Skip to content

Commit 3a3ff23

Browse files
authored
Consider module in GetEmitScriptTarget (microsoft#733)
1 parent 9585d1b commit 3a3ff23

File tree

81 files changed

+1540
-4744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1540
-4744
lines changed

internal/core/compileroptions.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ func (options *CompilerOptions) GetEmitScriptTarget() ScriptTarget {
142142
if options.Target != ScriptTargetNone {
143143
return options.Target
144144
}
145-
return ScriptTargetES5
145+
switch options.GetEmitModuleKind() {
146+
case ModuleKindNode16:
147+
return ScriptTargetES2022
148+
case ModuleKindNodeNext:
149+
return ScriptTargetESNext
150+
default:
151+
return ScriptTargetES5
152+
}
146153
}
147154

148155
func (options *CompilerOptions) GetEmitModuleKind() ModuleKind {

testdata/baselines/reference/submodule/compiler/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function drainStream(stream: NodeJS.ReadableStream): Promise<void>
77
>stream : Symbol(stream, Decl(app.mts, 1, 34))
88
>NodeJS : Symbol(NodeJS, Decl(globals.d.ts, 0, 0))
99
>ReadableStream : Symbol(ReadableStream, Decl(globals.d.ts, 0, 26))
10-
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
10+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
1111
}
1212

1313
=== /node_modules/@types/node/globals.d.ts ===

testdata/baselines/reference/submodule/compiler/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.symbols.diff

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
>stream : Symbol(stream, Decl(app.mts, 1, 34))
66
>NodeJS : Symbol(NodeJS, Decl(globals.d.ts, 0, 0))
77
->ReadableStream : Symbol(NodeJS.ReadableStream, Decl(globals.d.ts, 0, 26))
8-
->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
98
+>ReadableStream : Symbol(ReadableStream, Decl(globals.d.ts, 0, 26))
10-
+>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
9+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
1110
}
1211

13-
=== /node_modules/@types/node/globals.d.ts ===

testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.errors.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
error TS2468: Cannot find global value 'Promise'.
21
/index.ts(2,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
32
/index.ts(2,32): error TS1478: Identifier or string literal expected.
43
/index.ts(2,32): error TS2695: Left side of comma operator is unused and has no side effects.
@@ -8,7 +7,6 @@ error TS2468: Cannot find global value 'Promise'.
87
/index.ts(2,69): error TS1128: Declaration or statement expected.
98
/index.ts(2,70): error TS1128: Declaration or statement expected.
109
/index.ts(2,71): error TS2304: Cannot find name 'RequireInterface'.
11-
/index.ts(3,7): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
1210
/index.ts(3,36): error TS1005: ':' expected.
1311
/index.ts(3,70): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/require"); }>'.
1412
/index.ts(5,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
@@ -35,8 +33,7 @@ error TS2468: Cannot find global value 'Promise'.
3533
/index.ts(6,112): error TS1128: Declaration or statement expected.
3634

3735

38-
!!! error TS2468: Cannot find global value 'Promise'.
39-
==== /index.ts (34 errors) ====
36+
==== /index.ts (33 errors) ====
4037
export type LocalInterface =
4138
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
4239
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -58,8 +55,6 @@ error TS2468: Cannot find global value 'Promise'.
5855
~~~~~~~~~~~~~~~~
5956
!!! error TS2304: Cannot find name 'RequireInterface'.
6057
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
61-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62-
!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
6358
~
6459
!!! error TS1005: ':' expected.
6560
~~~~~~~~~~~~~~~

testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.errors.txt.diff

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
11
--- old.parseAssertEntriesError.errors.txt
22
+++ new.parseAssertEntriesError.errors.txt
3-
@@= skipped -0, +0 lines =@@
4-
+error TS2468: Cannot find global value 'Promise'.
5-
/index.ts(2,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
6-
/index.ts(2,32): error TS1478: Identifier or string literal expected.
7-
/index.ts(2,32): error TS2695: Left side of comma operator is unused and has no side effects.
8-
@@= skipped -6, +7 lines =@@
9-
/index.ts(2,69): error TS1128: Declaration or statement expected.
3+
@@= skipped -7, +7 lines =@@
104
/index.ts(2,70): error TS1128: Declaration or statement expected.
115
/index.ts(2,71): error TS2304: Cannot find name 'RequireInterface'.
12-
+/index.ts(3,7): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
136
/index.ts(3,36): error TS1005: ':' expected.
147
-/index.ts(3,70): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'.
158
+/index.ts(3,70): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/require"); }>'.
169
/index.ts(5,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
1710
/index.ts(5,59): error TS1478: Identifier or string literal expected.
1811
/index.ts(5,59): error TS2695: Left side of comma operator is unused and has no side effects.
19-
@@= skipped -26, +27 lines =@@
20-
/index.ts(6,112): error TS1128: Declaration or statement expected.
21-
22-
23-
-==== /index.ts (33 errors) ====
24-
+!!! error TS2468: Cannot find global value 'Promise'.
25-
+==== /index.ts (34 errors) ====
26-
export type LocalInterface =
27-
& import("pkg", { assert: {1234, "resolution-mode": "require"} }).RequireInterface
28-
~~~~~~~~~~~~~~~~~~~~~~~~~
29-
@@= skipped -22, +23 lines =@@
30-
~~~~~~~~~~~~~~~~
31-
!!! error TS2304: Cannot find name 'RequireInterface'.
32-
& import("pkg", { assert: {1234, "resolution-mode": "import"} }).ImportInterface;
33-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34-
+!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
12+
@@= skipped -50, +50 lines =@@
3513
~
3614
!!! error TS1005: ':' expected.
3715
~~~~~~~~~~~~~~~

testdata/baselines/reference/submodule/compiler/parseImportAttributesError.errors.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
error TS2468: Cannot find global value 'Promise'.
21
/index.ts(2,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
32
/index.ts(2,30): error TS1478: Identifier or string literal expected.
43
/index.ts(2,30): error TS2695: Left side of comma operator is unused and has no side effects.
@@ -8,7 +7,6 @@ error TS2468: Cannot find global value 'Promise'.
87
/index.ts(2,67): error TS1128: Declaration or statement expected.
98
/index.ts(2,68): error TS1128: Declaration or statement expected.
109
/index.ts(2,69): error TS2304: Cannot find name 'RequireInterface'.
11-
/index.ts(3,7): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
1210
/index.ts(3,34): error TS1005: ':' expected.
1311
/index.ts(3,68): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/require"); }>'.
1412
/index.ts(5,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
@@ -35,8 +33,7 @@ error TS2468: Cannot find global value 'Promise'.
3533
/index.ts(6,110): error TS1128: Declaration or statement expected.
3634

3735

38-
!!! error TS2468: Cannot find global value 'Promise'.
39-
==== /index.ts (34 errors) ====
36+
==== /index.ts (33 errors) ====
4037
export type LocalInterface =
4138
& import("pkg", { with: {1234, "resolution-mode": "require"} }).RequireInterface
4239
~~~~~~~~~~~~~~~~~~~~~~~
@@ -58,8 +55,6 @@ error TS2468: Cannot find global value 'Promise'.
5855
~~~~~~~~~~~~~~~~
5956
!!! error TS2304: Cannot find name 'RequireInterface'.
6057
& import("pkg", { with: {1234, "resolution-mode": "import"} }).ImportInterface;
61-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62-
!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
6358
~
6459
!!! error TS1005: ':' expected.
6560
~~~~~~~~~~~~~~~

testdata/baselines/reference/submodule/compiler/parseImportAttributesError.errors.txt.diff

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
11
--- old.parseImportAttributesError.errors.txt
22
+++ new.parseImportAttributesError.errors.txt
3-
@@= skipped -0, +0 lines =@@
4-
+error TS2468: Cannot find global value 'Promise'.
5-
/index.ts(2,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
6-
/index.ts(2,30): error TS1478: Identifier or string literal expected.
7-
/index.ts(2,30): error TS2695: Left side of comma operator is unused and has no side effects.
8-
@@= skipped -6, +7 lines =@@
9-
/index.ts(2,67): error TS1128: Declaration or statement expected.
3+
@@= skipped -7, +7 lines =@@
104
/index.ts(2,68): error TS1128: Declaration or statement expected.
115
/index.ts(2,69): error TS2304: Cannot find name 'RequireInterface'.
12-
+/index.ts(3,7): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
136
/index.ts(3,34): error TS1005: ':' expected.
147
-/index.ts(3,68): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/import"); }>'.
158
+/index.ts(3,68): error TS2339: Property 'ImportInterface' does not exist on type 'Promise<{ default: typeof import("/node_modules/pkg/require"); }>'.
169
/index.ts(5,34): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'?
1710
/index.ts(5,57): error TS1478: Identifier or string literal expected.
1811
/index.ts(5,57): error TS2695: Left side of comma operator is unused and has no side effects.
19-
@@= skipped -26, +27 lines =@@
20-
/index.ts(6,110): error TS1128: Declaration or statement expected.
21-
22-
23-
-==== /index.ts (33 errors) ====
24-
+!!! error TS2468: Cannot find global value 'Promise'.
25-
+==== /index.ts (34 errors) ====
26-
export type LocalInterface =
27-
& import("pkg", { with: {1234, "resolution-mode": "require"} }).RequireInterface
28-
~~~~~~~~~~~~~~~~~~~~~~~
29-
@@= skipped -22, +23 lines =@@
30-
~~~~~~~~~~~~~~~~
31-
!!! error TS2304: Cannot find name 'RequireInterface'.
32-
& import("pkg", { with: {1234, "resolution-mode": "import"} }).ImportInterface;
33-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34-
+!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
12+
@@= skipped -50, +50 lines =@@
3513
~
3614
!!! error TS1005: ':' expected.
3715
~~~~~~~~~~~~~~~
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
error TS2468: Cannot find global value 'Promise'.
2-
/src/buzz.mts(2,1): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
31
/src/buzz.mts(2,8): error TS2307: Cannot find module './foo' or its corresponding type declarations.
42

53

6-
!!! error TS2468: Cannot find global value 'Promise'.
7-
==== /src/buzz.mts (2 errors) ====
4+
==== /src/buzz.mts (1 errors) ====
85
// Extensionless relative path dynamic import in an ES module
96
import("./foo").then(x => x); // should error, ask for extension
10-
~~~~~~~~~~~~~~~
11-
!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
127
~~~~~~~
138
!!! error TS2307: Cannot find module './foo' or its corresponding type declarations.

testdata/baselines/reference/submodule/conformance/moduleResolutionWithoutExtension5.errors.txt.diff

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
+++ new.moduleResolutionWithoutExtension5.errors.txt
33
@@= skipped -0, +0 lines =@@
44
-/src/buzz.mts(2,8): error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
5-
+error TS2468: Cannot find global value 'Promise'.
6-
+/src/buzz.mts(2,1): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
75
+/src/buzz.mts(2,8): error TS2307: Cannot find module './foo' or its corresponding type declarations.
86

97

10-
-==== /src/buzz.mts (1 errors) ====
11-
+!!! error TS2468: Cannot find global value 'Promise'.
12-
+==== /src/buzz.mts (2 errors) ====
8+
==== /src/buzz.mts (1 errors) ====
139
// Extensionless relative path dynamic import in an ES module
1410
import("./foo").then(x => x); // should error, ask for extension
15-
+ ~~~~~~~~~~~~~~~
16-
+!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
1711
~~~~~~~
1812
-!!! error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
1913
+!!! error TS2307: Cannot find module './foo' or its corresponding type declarations.
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
error TS2468: Cannot find global value 'Promise'.
2-
/src/bar.cts(2,1): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
31
/src/bar.cts(2,8): error TS2307: Cannot find module './foo' or its corresponding type declarations.
42

53

6-
!!! error TS2468: Cannot find global value 'Promise'.
7-
==== /src/bar.cts (2 errors) ====
4+
==== /src/bar.cts (1 errors) ====
85
// Extensionless relative path dynamic import in a cjs module
96
import("./foo").then(x => x); // should error, ask for extension
10-
~~~~~~~~~~~~~~~
11-
!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
127
~~~~~~~
138
!!! error TS2307: Cannot find module './foo' or its corresponding type declarations.

testdata/baselines/reference/submodule/conformance/moduleResolutionWithoutExtension8.errors.txt.diff

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
+++ new.moduleResolutionWithoutExtension8.errors.txt
33
@@= skipped -0, +0 lines =@@
44
-/src/bar.cts(2,8): error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
5-
+error TS2468: Cannot find global value 'Promise'.
6-
+/src/bar.cts(2,1): error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
75
+/src/bar.cts(2,8): error TS2307: Cannot find module './foo' or its corresponding type declarations.
86

97

10-
-==== /src/bar.cts (1 errors) ====
11-
+!!! error TS2468: Cannot find global value 'Promise'.
12-
+==== /src/bar.cts (2 errors) ====
8+
==== /src/bar.cts (1 errors) ====
139
// Extensionless relative path dynamic import in a cjs module
1410
import("./foo").then(x => x); // should error, ask for extension
15-
+ ~~~~~~~~~~~~~~~
16-
+!!! error TS2712: A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
1711
~~~~~~~
1812
-!!! error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
1913
+!!! error TS2307: Cannot find module './foo' or its corresponding type declarations.

0 commit comments

Comments
 (0)