From 00184d4edee7eec6f9baace4c067919893118347 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 20 Nov 2025 13:38:50 -0800 Subject: [PATCH] Fix dyanmic import grammar check --- internal/checker/grammarchecks.go | 2 +- ...ImportAssertions(module=node18).errors.txt | 5 +---- ...tAssertions(module=node18).errors.txt.diff | 20 ------------------- ...ImportAssertions(module=node20).errors.txt | 5 +---- ...tAssertions(module=node20).errors.txt.diff | 15 +++----------- ...ImportAttributes(module=node18).errors.txt | 5 +---- ...tAttributes(module=node18).errors.txt.diff | 20 ------------------- ...ImportAttributes(module=node20).errors.txt | 5 +---- ...tAttributes(module=node20).errors.txt.diff | 20 ------------------- 9 files changed, 8 insertions(+), 89 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt.diff diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go index d8a12a9fcd..dafbd9f413 100644 --- a/internal/checker/grammarchecks.go +++ b/internal/checker/grammarchecks.go @@ -2191,7 +2191,7 @@ func (c *Checker) checkGrammarImportCallExpression(node *ast.Node) bool { nodeArguments := nodeAsCall.Arguments argumentNodes := nodeArguments.Nodes - if c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindNodeNext && c.moduleKind != core.ModuleKindNode16 && c.moduleKind != core.ModuleKindPreserve { + if !(core.ModuleKindNode16 <= c.moduleKind && c.moduleKind <= core.ModuleKindNodeNext) && c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindPreserve { // We are allowed trailing comma after proposal-import-assertions. c.checkGrammarForDisallowedTrailingComma(nodeArguments, diagnostics.Trailing_comma_not_allowed) diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt index 79444f5833..b1d54f8e21 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt @@ -1,16 +1,13 @@ otherc.cts(1,35): error TS2836: Import assertions are not allowed on statements that compile to CommonJS 'require' calls. -otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== index.ts (0 errors) ==== import json from "./package.json" assert { type: "json" }; -==== otherc.cts (2 errors) ==== +==== otherc.cts (1 errors) ==== import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2836: Import assertions are not allowed on statements that compile to CommonJS 'require' calls. const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== package.json (0 errors) ==== { "name": "pkg", diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt.diff deleted file mode 100644 index 0a80622d31..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node18).errors.txt.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.nodeModulesImportAssertions(module=node18).errors.txt -+++ new.nodeModulesImportAssertions(module=node18).errors.txt -@@= skipped -0, +0 lines =@@ - otherc.cts(1,35): error TS2836: Import assertions are not allowed on statements that compile to CommonJS 'require' calls. -+otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - - - ==== index.ts (0 errors) ==== - import json from "./package.json" assert { type: "json" }; --==== otherc.cts (1 errors) ==== -+==== otherc.cts (2 errors) ==== - import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions - ~~~~~~~~~~~~~~~~~~~~~~~ - !!! error TS2836: Import assertions are not allowed on statements that compile to CommonJS 'require' calls. - const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine -+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - ==== package.json (0 errors) ==== - { - "name": "pkg", \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt index f4002d5a5a..c1227dbbdf 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt @@ -1,19 +1,16 @@ index.ts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. otherc.cts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. -otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== index.ts (1 errors) ==== import json from "./package.json" assert { type: "json" }; ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. -==== otherc.cts (2 errors) ==== +==== otherc.cts (1 errors) ==== import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== package.json (0 errors) ==== { "name": "pkg", diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt.diff index 3feaff9e32..4074e9a16a 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAssertions(module=node20).errors.txt.diff @@ -1,25 +1,16 @@ --- old.nodeModulesImportAssertions(module=node20).errors.txt +++ new.nodeModulesImportAssertions(module=node20).errors.txt -@@= skipped -0, +0 lines =@@ - index.ts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. - otherc.cts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. -+otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - +@@= skipped -3, +3 lines =@@ ==== index.ts (1 errors) ==== import json from "./package.json" assert { type: "json" }; - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. --==== otherc.cts (1 errors) ==== -+==== otherc.cts (2 errors) ==== + ==== otherc.cts (1 errors) ==== import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine -+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - ==== package.json (0 errors) ==== - { - "name": "pkg", \ No newline at end of file + ==== package.json (0 errors) ==== \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt index 1e6ecc3460..8f85517984 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt @@ -1,16 +1,13 @@ otherc.cts(1,35): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. -otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== index.ts (0 errors) ==== import json from "./package.json" with { type: "json" }; -==== otherc.cts (2 errors) ==== +==== otherc.cts (1 errors) ==== import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. const json2 = import("./package.json", { with: { type: "json" } }); // should be fine - ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== package.json (0 errors) ==== { "name": "pkg", diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt.diff deleted file mode 100644 index 8340b9dc99..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node18).errors.txt.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.nodeModulesImportAttributes(module=node18).errors.txt -+++ new.nodeModulesImportAttributes(module=node18).errors.txt -@@= skipped -0, +0 lines =@@ - otherc.cts(1,35): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. -+otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - - - ==== index.ts (0 errors) ==== - import json from "./package.json" with { type: "json" }; --==== otherc.cts (1 errors) ==== -+==== otherc.cts (2 errors) ==== - import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes - ~~~~~~~~~~~~~~~~~~~~~ - !!! error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. - const json2 = import("./package.json", { with: { type: "json" } }); // should be fine -+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - ==== package.json (0 errors) ==== - { - "name": "pkg", \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt index 1e6ecc3460..8f85517984 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt @@ -1,16 +1,13 @@ otherc.cts(1,35): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. -otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== index.ts (0 errors) ==== import json from "./package.json" with { type: "json" }; -==== otherc.cts (2 errors) ==== +==== otherc.cts (1 errors) ==== import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. const json2 = import("./package.json", { with: { type: "json" } }); // should be fine - ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. ==== package.json (0 errors) ==== { "name": "pkg", diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt.diff deleted file mode 100644 index d564201563..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesImportAttributes(module=node20).errors.txt.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.nodeModulesImportAttributes(module=node20).errors.txt -+++ new.nodeModulesImportAttributes(module=node20).errors.txt -@@= skipped -0, +0 lines =@@ - otherc.cts(1,35): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. -+otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - - - ==== index.ts (0 errors) ==== - import json from "./package.json" with { type: "json" }; --==== otherc.cts (1 errors) ==== -+==== otherc.cts (2 errors) ==== - import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes - ~~~~~~~~~~~~~~~~~~~~~ - !!! error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. - const json2 = import("./package.json", { with: { type: "json" } }); // should be fine -+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'. - ==== package.json (0 errors) ==== - { - "name": "pkg", \ No newline at end of file