Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow JS with isolated modules (#31483)
* Allow JS with isolated modules Previously legacy JS code was not allowed; it was required to use ES6 module syntax. Unfortunately, the check happens after parsing but before binding, and the commonjs module indicator isn't set until binding because it's not syntactically simple like the ES6 module indicator, which is set during parsing. So I decided that JS should be allowed during isolatedModules unconditionally. We're not going to be transforming it anyway. * Update baselines * Switch test to outDir instead of noEmit
- Loading branch information
Showing
14 changed files
with
60 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//// [index.js] | ||
module.exports = {} | ||
var x = 1 | ||
|
||
|
||
//// [index.js] | ||
module.exports = {}; | ||
var x = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
=== tests/cases/compiler/index.js === | ||
module.exports = {} | ||
>module.exports : Symbol("tests/cases/compiler/index", Decl(index.js, 0, 0)) | ||
>module : Symbol(module, Decl(index.js, 0, 0)) | ||
>exports : Symbol("tests/cases/compiler/index", Decl(index.js, 0, 0)) | ||
|
||
var x = 1 | ||
>x : Symbol(x, Decl(index.js, 1, 3)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== tests/cases/compiler/index.js === | ||
module.exports = {} | ||
>module.exports = {} : typeof import("tests/cases/compiler/index") | ||
>module.exports : typeof import("tests/cases/compiler/index") | ||
>module : { "tests/cases/compiler/index": typeof import("tests/cases/compiler/index"); } | ||
>exports : typeof import("tests/cases/compiler/index") | ||
>{} : {} | ||
|
||
var x = 1 | ||
>x : number | ||
>1 : 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
tests/cases/compiler/file1.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
tests/cases/compiler/file1.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
|
||
|
||
==== tests/cases/compiler/file1.ts (1 errors) ==== | ||
var x; | ||
~~~ | ||
!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
|
||
|
||
==== tests/cases/compiler/isolatedModulesPlainFile-AMD.ts (1 errors) ==== | ||
declare function run(a: number): void; | ||
~~~~~~~ | ||
!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
run(1); | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
|
||
|
||
==== tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts (1 errors) ==== | ||
declare function run(a: number): void; | ||
~~~~~~~ | ||
!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
run(1); | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
|
||
|
||
==== tests/cases/compiler/isolatedModulesPlainFile-ES6.ts (1 errors) ==== | ||
declare function run(a: number): void; | ||
~~~~~~~ | ||
!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
run(1); | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/compiler/isolatedModulesPlainFile-System.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
tests/cases/compiler/isolatedModulesPlainFile-System.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
|
||
|
||
==== tests/cases/compiler/isolatedModulesPlainFile-System.ts (1 errors) ==== | ||
declare function run(a: number): void; | ||
~~~~~~~ | ||
!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
run(1); | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
|
||
|
||
==== tests/cases/compiler/isolatedModulesPlainFile-UMD.ts (1 errors) ==== | ||
declare function run(a: number): void; | ||
~~~~~~~ | ||
!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. | ||
!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. | ||
run(1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @Filename: tsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"outDir": "foo", | ||
"isolatedModules": true, | ||
} | ||
} | ||
|
||
// @Filename: index.js | ||
module.exports = {} | ||
var x = 1 |