Skip to content

Commit 9f532d3

Browse files
committed
fix: fix outline crash for upcoming ts 5.5
1 parent 01dfb8a commit 9f532d3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

typescript/src/getPatchedNavTree.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ensureArray } from '@zardoy/utils'
2-
import { getCancellationToken, isTs5, nodeModules } from './utils'
2+
import { getCancellationToken, isTs5, isTs5And5, nodeModules } from './utils'
33
import { createLanguageService } from './dummyLanguageService'
44
import { getCannotFindCodes } from './utils/cannotFindCodes'
55

@@ -11,8 +11,9 @@ type AdditionalFeatures = Record<'arraysTuplesNumberedItems', boolean>
1111
const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavigationTree(...args) } => {
1212
// what is happening here: grabbing & patching NavigationBar module contents from actual running JS
1313
const tsServerPath = typeof __TS_SEVER_PATH__ === 'undefined' ? require.main!.filename : __TS_SEVER_PATH__
14+
const typescriptFilePath = `${nodeModules!.path.dirname(tsServerPath)}/typescript.js`
1415
// current lib/tsserver.js
15-
const mainScript = nodeModules!.fs.readFileSync(tsServerPath, 'utf8')
16+
const mainScript = nodeModules!.fs.readFileSync(isTs5And5() ? typescriptFilePath : tsServerPath, 'utf8')
1617
type PatchData = {
1718
markerModuleStart: string
1819
skipStartMarker?: boolean
@@ -173,7 +174,7 @@ export const getNavTreeItems = (
173174
fileName: string,
174175
additionalFeatures: AdditionalFeatures,
175176
) => {
176-
if (!navModule) navModule = getPatchedNavModule(additionalFeatures)
177+
navModule = getPatchedNavModule(additionalFeatures)
177178
const sourceFile =
178179
(languageService as unknown as import('typescript-full').LanguageService).getNonBoundSourceFile?.(fileName) ??
179180
languageService.getProgram()!.getSourceFile(fileName)

typescript/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export const buildStringCompletion = (node: ts.StringLiteralLike, completion: Ex
131131

132132
// semver: can't use compare as it incorrectly works with build postfix
133133
export const isTs5 = () => semver.major(ts.version) >= 5
134+
export const isTs5And5 = () => (semver.major(ts.version) === 5 && semver.minor(ts.version) >= 5) || semver.major(ts.version) > 5
134135

135136
export const isTsPatched = () => {
136137
try {

0 commit comments

Comments
 (0)