diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a1076464bbd..b0a9e02ed7c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -537,7 +537,8 @@ namespace ts { } function getLanguageVariant(fileName: string) { - return isTsx(fileName) || isJavaScript(fileName) ? LanguageVariant.JSX : LanguageVariant.Standard; + // .tsx and .jsx files are treated as jsx language variant. + return fileExtensionIs(fileName, ".tsx") || fileExtensionIs(fileName, ".jsx") ? LanguageVariant.JSX : LanguageVariant.Standard; } function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 885d529f69e..838ff097933 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2142,10 +2142,6 @@ namespace ts { return hasExtension(fileName) && forEach(supportedJavascriptExtensions, extension => fileExtensionIs(fileName, extension)); } - export function isTsx(fileName: string) { - return fileExtensionIs(fileName, ".tsx"); - } - /** * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. diff --git a/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt b/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt index 669e83688cc..50d6416a62b 100644 --- a/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt @@ -1,9 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files. -tests/cases/compiler/a.js(1,27): error TS17002: Expected corresponding JSX closing tag for 'string'. +tests/cases/compiler/a.js(1,10): error TS8016: 'type assertion expressions' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' which is one of the input files. ==== tests/cases/compiler/a.js (1 errors) ==== var v = undefined; - -!!! error TS17002: Expected corresponding JSX closing tag for 'string'. \ No newline at end of file + ~~~~~~ +!!! error TS8016: 'type assertion expressions' can only be used in a .ts file. \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts index 5172ee7701c..c0c519cb24c 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts @@ -4,13 +4,13 @@ // @Filename: a.js //// var v = undefined; -verify.getSyntacticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[]`); +verify.getSemanticDiagnostics(`[ { - "message": "Expected corresponding JSX closing tag for 'string'.", - "start": 26, - "length": 0, + "message": "'type assertion expressions' can only be used in a .ts file.", + "start": 9, + "length": 6, "category": "error", - "code": 17002 + "code": 8016 } -]`); -verify.getSemanticDiagnostics(`[]`); \ No newline at end of file +]`); \ No newline at end of file