Treat the .jsx and .tsx files as jsx when parsing and .js files are parsed in standard mode

This commit is contained in:
Sheetal Nandi
2015-10-28 16:39:22 -07:00
parent 2d3a345fd3
commit 0c3c7f1a1b
4 changed files with 12 additions and 15 deletions

View File

@@ -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) {

View File

@@ -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.

View File

@@ -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 = <string>undefined;
!!! error TS17002: Expected corresponding JSX closing tag for 'string'.
~~~~~~
!!! error TS8016: 'type assertion expressions' can only be used in a .ts file.

View File

@@ -4,13 +4,13 @@
// @Filename: a.js
//// var v = <string>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(`[]`);
]`);