Cherry-pick PR #50673 into release-4.8 (#50742) · microsoft/TypeScript@39576e6 (original) (raw)

File tree

Original file line number Diff line number Diff line change
@@ -45658,7 +45658,7 @@ namespace ts {
45658 45658 }
45659 45659
45660 45660 const nodeArguments = node.arguments;
45661 - if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext) {
45661 + if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext && moduleKind !== ModuleKind.Node16) {
45662 45662 // We are allowed trailing comma after proposal-import-assertions.
45663 45663 checkGrammarForDisallowedTrailingComma(nodeArguments);
45664 45664
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
1 1 tests/cases/conformance/node/index.ts(1,35): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2 2 tests/cases/conformance/node/otherc.cts(1,35): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
3 -tests/cases/conformance/node/otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
4 3
5 4
6 5 ==== tests/cases/conformance/node/index.ts (1 errors) ====
7 6 import json from "./package.json" assert { type: "json" };
8 7 ~~~~~~~~~~~~~~~~~~~~~~~
9 8 !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
10 -==== tests/cases/conformance/node/otherc.cts (2 errors) ====
9 +==== tests/cases/conformance/node/otherc.cts (1 errors) ====
11 10 import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
12 11 ~~~~~~~~~~~~~~~~~~~~~~~
13 12 !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
14 13 const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
15 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 -!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
17 14 ==== tests/cases/conformance/node/package.json (0 errors) ====
18 15 {
19 16 "name": "pkg",