Skip to content

Commit 6febe3b

Browse files
committed
Merge pull request #6562 from RyanCavanaugh/jsIsJsx
Treat .js as JSX
2 parents 85d09e4 + c38021f commit 6febe3b

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ namespace ts {
546546

547547
function getLanguageVariant(fileName: string) {
548548
// .tsx and .jsx files are treated as jsx language variant.
549-
return fileExtensionIs(fileName, ".tsx") || fileExtensionIs(fileName, ".jsx") ? LanguageVariant.JSX : LanguageVariant.Standard;
549+
return fileExtensionIs(fileName, ".tsx") || fileExtensionIs(fileName, ".jsx") || fileExtensionIs(fileName, ".js") ? LanguageVariant.JSX : LanguageVariant.Standard;
550550
}
551551

552552
function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, isJavaScriptFile: boolean, _syntaxCursor: IncrementalParser.SyntaxCursor) {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
2-
tests/cases/compiler/a.js(1,10): error TS8016: 'type assertion expressions' can only be used in a .ts file.
2+
tests/cases/compiler/a.js(1,10): error TS17008: JSX element 'string' has no corresponding closing tag.
3+
tests/cases/compiler/a.js(1,27): error TS1005: '</' expected.
34

45

56
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
6-
==== tests/cases/compiler/a.js (1 errors) ====
7+
==== tests/cases/compiler/a.js (2 errors) ====
78
var v = <string>undefined;
89
~~~~~~
9-
!!! error TS8016: 'type assertion expressions' can only be used in a .ts file.
10+
!!! error TS17008: JSX element 'string' has no corresponding closing tag.
11+
12+
!!! error TS1005: '</' expected.

tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)