diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6b357628f33..f11c88b2a0b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -536,7 +536,7 @@ namespace ts { export function parseSourceFile(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile { - const isJavaScriptFile = hasJavaScriptFileExtension(fileName) || _sourceText.lastIndexOf("// @language=javascript", 0) === 0 || scriptKind == ScriptKind.Js; + const isJavaScriptFile = hasJavaScriptFileExtension(fileName) || _sourceText.lastIndexOf("// @language=javascript", 0) === 0 || scriptKind == ScriptKind.JS; initializeState(fileName, _sourceText, languageVersion, isJavaScriptFile, _syntaxCursor); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d9613191c48..8c9d1d1d40a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2462,10 +2462,10 @@ namespace ts { export const enum ScriptKind { Unknown = 0, - Js = 1, - Jsx = 2, - Ts = 3, - Tsx = 4 + JS = 1, + JSX = 2, + TS = 3, + TSX = 4 } export const enum ScriptTarget { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 4bc5386252f..9761afc9034 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -183,7 +183,7 @@ namespace Harness.LanguageService { const script = this.getScriptInfo(fileName); return script ? new ScriptSnapshot(script) : undefined; } - getScriptKind(fileName: string): ScriptKind { return ScriptKind.Unknown; } + getScriptKind(fileName: string): ts.ScriptKind { return ts.ScriptKind.Unknown; } getScriptVersion(fileName: string): string { const script = this.getScriptInfo(fileName); return script ? script.version.toString() : undefined; @@ -254,7 +254,7 @@ namespace Harness.LanguageService { const nativeScriptSnapshot = this.nativeHost.getScriptSnapshot(fileName); return nativeScriptSnapshot && new ScriptSnapshotProxy(nativeScriptSnapshot); } - getScriptKind(fileName: string): ScriptKind { return this.nativeHost.getScriptKind(fileName); } + getScriptKind(fileName: string): ts.ScriptKind { return this.nativeHost.getScriptKind(fileName); } getScriptVersion(fileName: string): string { return this.nativeHost.getScriptVersion(fileName); } getLocalizedDiagnosticMessages(): string { return JSON.stringify({}); } diff --git a/src/services/services.ts b/src/services/services.ts index 2fa6031924c..5a5f4da607e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1019,7 +1019,7 @@ namespace ts { getNewLine?(): string; getProjectVersion?(): string; getScriptFileNames(): string[]; - getScriptKind(fileName: string): ScriptKind; + getScriptKind?(fileName: string): ScriptKind; getScriptVersion(fileName: string): string; getScriptSnapshot(fileName: string): IScriptSnapshot; getLocalizedDiagnosticMessages?(): any; @@ -1750,7 +1750,7 @@ namespace ts { private createEntry(fileName: string, path: Path) { let entry: HostFileInformation; - const scriptKind = this.host.getScriptKind(fileName); + const scriptKind = this.host.getScriptKind ? this.host.getScriptKind(fileName) : ScriptKind.Unknown; const scriptSnapshot = this.host.getScriptSnapshot(fileName); if (scriptSnapshot) { entry = { @@ -1823,7 +1823,7 @@ namespace ts { throw new Error("Could not find file: '" + fileName + "'."); } - const scriptKind = this.host.getScriptKind(fileName); + const scriptKind = this.host.getScriptKind ? this.host.getScriptKind(fileName) : ScriptKind.Unknown; const version = this.host.getScriptVersion(fileName); let sourceFile: SourceFile; diff --git a/src/services/shims.ts b/src/services/shims.ts index d7cf4da50fd..571c75482bb 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -55,7 +55,7 @@ namespace ts { /** Returns a JSON-encoded value of the type: string[] */ getScriptFileNames(): string; - getScriptKind(fileName: string): ScriptKind; + getScriptKind?(fileName: string): ScriptKind; getScriptVersion(fileName: string): string; getScriptSnapshot(fileName: string): ScriptSnapshotShim; getLocalizedDiagnosticMessages(): string; @@ -350,7 +350,8 @@ namespace ts { public getScriptKind(fileName: string): ScriptKind { try { return this.shimHost.getScriptKind(fileName); - } catch (e) { + } + catch (e) { return ScriptKind.Unknown; } }