Skip to content

Commit af38ab9

Browse files
authored
feat(41249): allow import.meta with module: es2020 (microsoft#41274)
1 parent 4055953 commit af38ab9

13 files changed

+908
-56
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28654,8 +28654,8 @@ namespace ts {
2865428654
}
2865528655

2865628656
function checkImportMetaProperty(node: MetaProperty) {
28657-
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) {
28658-
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_esnext_or_system);
28657+
if (moduleKind !== ModuleKind.ES2020 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) {
28658+
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_or_system);
2865928659
}
2866028660
const file = getSourceFileOfNode(node);
2866128661
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@
10041004
"category": "Error",
10051005
"code": 1342
10061006
},
1007-
"The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.": {
1007+
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.": {
10081008
"category": "Error",
10091009
"code": 1343
10101010
},
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
error TS2468: Cannot find global value 'Promise'.
2-
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,32): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
2+
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,32): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
33
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,44): error TS2339: Property 'blah' does not exist on type 'ImportMeta'.
4-
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,51): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
4+
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,51): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
55
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,63): error TS2339: Property 'blue' does not exist on type 'ImportMeta'.
6-
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,70): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
7-
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(2,1): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
6+
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(1,70): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
7+
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(2,1): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
88
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(2,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
9-
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(11,21): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
9+
tests/cases/conformance/es2019/importMeta/assignmentTargets.ts(11,21): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
1010
tests/cases/conformance/es2019/importMeta/example.ts(2,2): error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.
11-
tests/cases/conformance/es2019/importMeta/example.ts(3,59): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
11+
tests/cases/conformance/es2019/importMeta/example.ts(3,59): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
1212
tests/cases/conformance/es2019/importMeta/example.ts(3,71): error TS2339: Property 'url' does not exist on type 'ImportMeta'.
13-
tests/cases/conformance/es2019/importMeta/example.ts(6,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
13+
tests/cases/conformance/es2019/importMeta/example.ts(6,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
1414
tests/cases/conformance/es2019/importMeta/example.ts(6,28): error TS2339: Property 'scriptElement' does not exist on type 'ImportMeta'.
15-
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(1,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
16-
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(2,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
15+
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(1,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
16+
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(2,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
1717
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(2,23): error TS17012: 'metal' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
18-
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(3,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
18+
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(3,16): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
1919
tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts(3,23): error TS17012: 'import' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
20-
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(1,15): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
21-
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(2,15): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
20+
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(1,15): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
21+
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(2,15): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
2222
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(2,22): error TS17012: 'metal' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
23-
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(3,15): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
23+
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(3,15): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
2424
tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(3,22): error TS17012: 'import' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
2525

2626

@@ -32,14 +32,14 @@ tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(3,22): error TS
3232
!!! error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.
3333
const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString());
3434
~~~~~~~~~~~
35-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
35+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
3636
~~~
3737
!!! error TS2339: Property 'url' does not exist on type 'ImportMeta'.
3838
const blob = await response.blob();
3939

4040
const size = import.meta.scriptElement.dataset.size || 300;
4141
~~~~~~~~~~~
42-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
42+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
4343
~~~~~~~~~~~~~
4444
!!! error TS2339: Property 'scriptElement' does not exist on type 'ImportMeta'.
4545

@@ -53,48 +53,48 @@ tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(3,22): error TS
5353
==== tests/cases/conformance/es2019/importMeta/moduleLookingFile01.ts (5 errors) ====
5454
export let x = import.meta;
5555
~~~~~~~~~~~
56-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
56+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
5757
export let y = import.metal;
5858
~~~~~~~~~~~~
59-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
59+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
6060
~~~~~
6161
!!! error TS17012: 'metal' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
6262
export let z = import.import.import.malkovich;
6363
~~~~~~~~~~~~~
64-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
64+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
6565
~~~~~~
6666
!!! error TS17012: 'import' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
6767

6868
==== tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts (5 errors) ====
6969
let globalA = import.meta;
7070
~~~~~~~~~~~
71-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
71+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
7272
let globalB = import.metal;
7373
~~~~~~~~~~~~
74-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
74+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
7575
~~~~~
7676
!!! error TS17012: 'metal' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
7777
let globalC = import.import.import.malkovich;
7878
~~~~~~~~~~~~~
79-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
79+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
8080
~~~~~~
8181
!!! error TS17012: 'import' is not a valid meta-property for keyword 'import'. Did you mean 'meta'?
8282

8383
==== tests/cases/conformance/es2019/importMeta/assignmentTargets.ts (8 errors) ====
8484
export const foo: ImportMeta = import.meta.blah = import.meta.blue = import.meta;
8585
~~~~~~~~~~~
86-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
86+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
8787
~~~~
8888
!!! error TS2339: Property 'blah' does not exist on type 'ImportMeta'.
8989
~~~~~~~~~~~
90-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
90+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
9191
~~~~
9292
!!! error TS2339: Property 'blue' does not exist on type 'ImportMeta'.
9393
~~~~~~~~~~~
94-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
94+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
9595
import.meta = foo;
9696
~~~~~~~~~~~
97-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
97+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
9898
~~~~~~~~~~~
9999
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
100100

@@ -107,4 +107,4 @@ tests/cases/conformance/es2019/importMeta/scriptLookingFile01.ts(3,22): error TS
107107

108108
const { a, b, c } = import.meta.wellKnownProperty;
109109
~~~~~~~~~~~
110-
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
110+
!!! error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.

0 commit comments

Comments
 (0)