From 50f488b8f06c72d29772e5dc95487f78bdf8e23c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 24 Jun 2025 10:50:29 -0700 Subject: [PATCH] Fix enum strings used in error messages --- internal/core/compileroptions.go | 5 +- .../compileroptions_stringer_generated.go | 95 ------------------- .../core/modulekind_stringer_generated.go | 51 ++++++++++ .../core/scripttarget_stringer_generated.go | 49 ++++++++++ .../nodeModulesJson(module=node16).errors.txt | 4 +- ...ModulesJson(module=node16).errors.txt.diff | 20 ---- .../nodeModulesJson(module=node18).errors.txt | 16 ++-- ...ModulesJson(module=node18).errors.txt.diff | 43 +-------- ...odeModulesJson(module=nodenext).errors.txt | 16 ++-- ...dulesJson(module=nodenext).errors.txt.diff | 45 --------- 10 files changed, 124 insertions(+), 220 deletions(-) delete mode 100644 internal/core/compileroptions_stringer_generated.go create mode 100644 internal/core/modulekind_stringer_generated.go create mode 100644 internal/core/scripttarget_stringer_generated.go delete mode 100644 testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt.diff diff --git a/internal/core/compileroptions.go b/internal/core/compileroptions.go index c63d00eab1..bdfd520a60 100644 --- a/internal/core/compileroptions.go +++ b/internal/core/compileroptions.go @@ -9,8 +9,9 @@ import ( "github.com/microsoft/typescript-go/internal/tspath" ) -//go:generate go tool golang.org/x/tools/cmd/stringer -type=ModuleKind,ScriptTarget -output=compileroptions_stringer_generated.go -//go:generate go tool mvdan.cc/gofumpt -lang=go1.24 -w compileroptions_stringer_generated.go +//go:generate go tool golang.org/x/tools/cmd/stringer -type=ModuleKind -trimprefix=ModuleKind -output=modulekind_stringer_generated.go +//go:generate go tool golang.org/x/tools/cmd/stringer -type=ScriptTarget -trimprefix=ScriptTarget -output=scripttarget_stringer_generated.go +//go:generate go tool mvdan.cc/gofumpt -lang=go1.24 -w modulekind_stringer_generated.go scripttarget_stringer_generated.go type CompilerOptions struct { _ noCopy diff --git a/internal/core/compileroptions_stringer_generated.go b/internal/core/compileroptions_stringer_generated.go deleted file mode 100644 index 256018aeb0..0000000000 --- a/internal/core/compileroptions_stringer_generated.go +++ /dev/null @@ -1,95 +0,0 @@ -// Code generated by "stringer -type=ModuleKind,ScriptTarget -output=compileroptions_stringer_generated.go"; DO NOT EDIT. - -package core - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[ModuleKindNone-0] - _ = x[ModuleKindCommonJS-1] - _ = x[ModuleKindAMD-2] - _ = x[ModuleKindUMD-3] - _ = x[ModuleKindSystem-4] - _ = x[ModuleKindES2015-5] - _ = x[ModuleKindES2020-6] - _ = x[ModuleKindES2022-7] - _ = x[ModuleKindESNext-99] - _ = x[ModuleKindNode16-100] - _ = x[ModuleKindNode18-101] - _ = x[ModuleKindNodeNext-199] - _ = x[ModuleKindPreserve-200] -} - -const ( - _ModuleKind_name_0 = "ModuleKindNoneModuleKindCommonJSModuleKindAMDModuleKindUMDModuleKindSystemModuleKindES2015ModuleKindES2020ModuleKindES2022" - _ModuleKind_name_1 = "ModuleKindESNextModuleKindNode16ModuleKindNode18" - _ModuleKind_name_2 = "ModuleKindNodeNextModuleKindPreserve" -) - -var ( - _ModuleKind_index_0 = [...]uint8{0, 14, 32, 45, 58, 74, 90, 106, 122} - _ModuleKind_index_1 = [...]uint8{0, 16, 32, 48} - _ModuleKind_index_2 = [...]uint8{0, 18, 36} -) - -func (i ModuleKind) String() string { - switch { - case 0 <= i && i <= 7: - return _ModuleKind_name_0[_ModuleKind_index_0[i]:_ModuleKind_index_0[i+1]] - case 99 <= i && i <= 101: - i -= 99 - return _ModuleKind_name_1[_ModuleKind_index_1[i]:_ModuleKind_index_1[i+1]] - case 199 <= i && i <= 200: - i -= 199 - return _ModuleKind_name_2[_ModuleKind_index_2[i]:_ModuleKind_index_2[i+1]] - default: - return "ModuleKind(" + strconv.FormatInt(int64(i), 10) + ")" - } -} - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[ScriptTargetNone-0] - _ = x[ScriptTargetES3-0] - _ = x[ScriptTargetES5-1] - _ = x[ScriptTargetES2015-2] - _ = x[ScriptTargetES2016-3] - _ = x[ScriptTargetES2017-4] - _ = x[ScriptTargetES2018-5] - _ = x[ScriptTargetES2019-6] - _ = x[ScriptTargetES2020-7] - _ = x[ScriptTargetES2021-8] - _ = x[ScriptTargetES2022-9] - _ = x[ScriptTargetES2023-10] - _ = x[ScriptTargetES2024-11] - _ = x[ScriptTargetESNext-99] - _ = x[ScriptTargetJSON-100] - _ = x[ScriptTargetLatest-99] -} - -const ( - _ScriptTarget_name_0 = "ScriptTargetNoneScriptTargetES5ScriptTargetES2015ScriptTargetES2016ScriptTargetES2017ScriptTargetES2018ScriptTargetES2019ScriptTargetES2020ScriptTargetES2021ScriptTargetES2022ScriptTargetES2023ScriptTargetES2024" - _ScriptTarget_name_1 = "ScriptTargetESNextScriptTargetJSON" -) - -var ( - _ScriptTarget_index_0 = [...]uint8{0, 16, 31, 49, 67, 85, 103, 121, 139, 157, 175, 193, 211} - _ScriptTarget_index_1 = [...]uint8{0, 18, 34} -) - -func (i ScriptTarget) String() string { - switch { - case 0 <= i && i <= 11: - return _ScriptTarget_name_0[_ScriptTarget_index_0[i]:_ScriptTarget_index_0[i+1]] - case 99 <= i && i <= 100: - i -= 99 - return _ScriptTarget_name_1[_ScriptTarget_index_1[i]:_ScriptTarget_index_1[i+1]] - default: - return "ScriptTarget(" + strconv.FormatInt(int64(i), 10) + ")" - } -} diff --git a/internal/core/modulekind_stringer_generated.go b/internal/core/modulekind_stringer_generated.go new file mode 100644 index 0000000000..2bc8f4d727 --- /dev/null +++ b/internal/core/modulekind_stringer_generated.go @@ -0,0 +1,51 @@ +// Code generated by "stringer -type=ModuleKind -trimprefix=ModuleKind -output=modulekind_stringer_generated.go"; DO NOT EDIT. + +package core + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ModuleKindNone-0] + _ = x[ModuleKindCommonJS-1] + _ = x[ModuleKindAMD-2] + _ = x[ModuleKindUMD-3] + _ = x[ModuleKindSystem-4] + _ = x[ModuleKindES2015-5] + _ = x[ModuleKindES2020-6] + _ = x[ModuleKindES2022-7] + _ = x[ModuleKindESNext-99] + _ = x[ModuleKindNode16-100] + _ = x[ModuleKindNode18-101] + _ = x[ModuleKindNodeNext-199] + _ = x[ModuleKindPreserve-200] +} + +const ( + _ModuleKind_name_0 = "NoneCommonJSAMDUMDSystemES2015ES2020ES2022" + _ModuleKind_name_1 = "ESNextNode16Node18" + _ModuleKind_name_2 = "NodeNextPreserve" +) + +var ( + _ModuleKind_index_0 = [...]uint8{0, 4, 12, 15, 18, 24, 30, 36, 42} + _ModuleKind_index_1 = [...]uint8{0, 6, 12, 18} + _ModuleKind_index_2 = [...]uint8{0, 8, 16} +) + +func (i ModuleKind) String() string { + switch { + case 0 <= i && i <= 7: + return _ModuleKind_name_0[_ModuleKind_index_0[i]:_ModuleKind_index_0[i+1]] + case 99 <= i && i <= 101: + i -= 99 + return _ModuleKind_name_1[_ModuleKind_index_1[i]:_ModuleKind_index_1[i+1]] + case 199 <= i && i <= 200: + i -= 199 + return _ModuleKind_name_2[_ModuleKind_index_2[i]:_ModuleKind_index_2[i+1]] + default: + return "ModuleKind(" + strconv.FormatInt(int64(i), 10) + ")" + } +} diff --git a/internal/core/scripttarget_stringer_generated.go b/internal/core/scripttarget_stringer_generated.go new file mode 100644 index 0000000000..ad25dc22ca --- /dev/null +++ b/internal/core/scripttarget_stringer_generated.go @@ -0,0 +1,49 @@ +// Code generated by "stringer -type=ScriptTarget -trimprefix=ScriptTarget -output=scripttarget_stringer_generated.go"; DO NOT EDIT. + +package core + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[ScriptTargetNone-0] + _ = x[ScriptTargetES3-0] + _ = x[ScriptTargetES5-1] + _ = x[ScriptTargetES2015-2] + _ = x[ScriptTargetES2016-3] + _ = x[ScriptTargetES2017-4] + _ = x[ScriptTargetES2018-5] + _ = x[ScriptTargetES2019-6] + _ = x[ScriptTargetES2020-7] + _ = x[ScriptTargetES2021-8] + _ = x[ScriptTargetES2022-9] + _ = x[ScriptTargetES2023-10] + _ = x[ScriptTargetES2024-11] + _ = x[ScriptTargetESNext-99] + _ = x[ScriptTargetJSON-100] + _ = x[ScriptTargetLatest-99] +} + +const ( + _ScriptTarget_name_0 = "NoneES5ES2015ES2016ES2017ES2018ES2019ES2020ES2021ES2022ES2023ES2024" + _ScriptTarget_name_1 = "ESNextJSON" +) + +var ( + _ScriptTarget_index_0 = [...]uint8{0, 4, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67} + _ScriptTarget_index_1 = [...]uint8{0, 6, 10} +) + +func (i ScriptTarget) String() string { + switch { + case 0 <= i && i <= 11: + return _ScriptTarget_name_0[_ScriptTarget_index_0[i]:_ScriptTarget_index_0[i+1]] + case 99 <= i && i <= 100: + i -= 99 + return _ScriptTarget_name_1[_ScriptTarget_index_1[i]:_ScriptTarget_index_1[i+1]] + default: + return "ScriptTarget(" + strconv.FormatInt(int64(i), 10) + ")" + } +} diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt index ac054ff166..8977f188ce 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt @@ -3,7 +3,7 @@ /main.mts(5,36): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. /main.mts(6,52): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. /main.mts(9,47): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. -/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode16'. +/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node16'. /main.mts(10,41): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. /main.mts(11,42): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. /main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. @@ -61,7 +61,7 @@ !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. import { version } from "./config.json" with { type: "json" }; // Error, named import ~~~~~~~ -!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode16'. +!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node16'. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. import * as config3 from "./config.json" with { type: "json" }; diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt.diff deleted file mode 100644 index 0716da415c..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.nodeModulesJson(module=node16).errors.txt -+++ new.nodeModulesJson(module=node16).errors.txt -@@= skipped -2, +2 lines =@@ - /main.mts(5,36): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - /main.mts(6,52): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - /main.mts(9,47): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. --/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node16'. -+/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode16'. - /main.mts(10,41): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - /main.mts(11,42): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - /main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. -@@= skipped -58, +58 lines =@@ - !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - import { version } from "./config.json" with { type: "json" }; // Error, named import - ~~~~~~~ --!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node16'. -+!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode16'. - ~~~~~~~~~~~~~~~~~~~~~ - !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - import * as config3 from "./config.json" with { type: "json" }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt index b1a2ced62d..856fcee888 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt @@ -2,11 +2,11 @@ /loosey.cts(1,36): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. /loosey.cts(2,8): error TS1259: Module '"/config"' can only be default-imported using the 'allowSyntheticDefaultImports' flag /loosey.cts(6,9): error TS2339: Property 'default' does not exist on type '{ version: number; }'. -/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. -/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. -/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. +/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. +/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. +/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. /main.mts(9,47): error TS2857: Import attributes cannot be used with type-only imports or exports. -/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode18'. +/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node18'. /main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. @@ -48,23 +48,23 @@ import { oops } from "not.json"; // Ok import moreOops from "actually-json"; // Error in nodenext ~~~~~~~~~~~~~~~ -!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. +!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. import typed from "actually-json/typed"; // Error in nodenext ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. +!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. import config from "./config.json" with { type: "json" }; // Ok import { default as config1 } from "./config.json" with { type: "json" }; // Ok import config2 from "./config.json"; // Error in nodenext, no attribute ~~~~~~~~~~~~~~~ -!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. +!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. import type config2Type from "./config.json"; // Ok, type-only import type config2Type2 from "./config.json" with { type: "json" }; // Error, import attributes not allowed on type-only imports ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2857: Import attributes cannot be used with type-only imports or exports. import { version } from "./config.json" with { type: "json" }; // Error, named import ~~~~~~~ -!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode18'. +!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node18'. import * as config3 from "./config.json" with { type: "json" }; config3.version; // Error ~~~~~~~ diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt.diff index 2643d8b700..48e0c69f86 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt.diff @@ -5,46 +5,9 @@ /loosey.cts(1,36): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. +/loosey.cts(2,8): error TS1259: Module '"/config"' can only be default-imported using the 'allowSyntheticDefaultImports' flag /loosey.cts(6,9): error TS2339: Property 'default' does not exist on type '{ version: number; }'. --/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. --/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. --/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. -+/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. -+/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. -+/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. - /main.mts(9,47): error TS2857: Import attributes cannot be used with type-only imports or exports. --/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node18'. -+/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode18'. - /main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. - - -@@= skipped -45, +47 lines =@@ - import { oops } from "not.json"; // Ok - import moreOops from "actually-json"; // Error in nodenext - ~~~~~~~~~~~~~~~ --!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. -+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. - import typed from "actually-json/typed"; // Error in nodenext - ~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. -+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. - - import config from "./config.json" with { type: "json" }; // Ok - import { default as config1 } from "./config.json" with { type: "json" }; // Ok - import config2 from "./config.json"; // Error in nodenext, no attribute - ~~~~~~~~~~~~~~~ --!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. -+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'. - import type config2Type from "./config.json"; // Ok, type-only - import type config2Type2 from "./config.json" with { type: "json" }; // Error, import attributes not allowed on type-only imports - ~~~~~~~~~~~~~~~~~~~~~ - !!! error TS2857: Import attributes cannot be used with type-only imports or exports. - import { version } from "./config.json" with { type: "json" }; // Error, named import - ~~~~~~~ --!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node18'. -+!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode18'. - import * as config3 from "./config.json" with { type: "json" }; - config3.version; // Error - ~~~~~~~ + /main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. + /main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'. +@@= skipped -68, +70 lines =@@ !!! error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. config3.default; // Ok diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt index f732c7ebb9..04e6a649d3 100644 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt +++ b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt @@ -1,10 +1,10 @@ /loosey.cts(1,36): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. /loosey.cts(6,9): error TS2339: Property 'default' does not exist on type '{ version: number; }'. -/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. -/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. -/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. +/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. +/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. +/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. /main.mts(9,47): error TS2857: Import attributes cannot be used with type-only imports or exports. -/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNodeNext'. +/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. /main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. @@ -46,23 +46,23 @@ import { oops } from "not.json"; // Ok import moreOops from "actually-json"; // Error in nodenext ~~~~~~~~~~~~~~~ -!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. +!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. import typed from "actually-json/typed"; // Error in nodenext ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. +!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. import config from "./config.json" with { type: "json" }; // Ok import { default as config1 } from "./config.json" with { type: "json" }; // Ok import config2 from "./config.json"; // Error in nodenext, no attribute ~~~~~~~~~~~~~~~ -!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. +!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. import type config2Type from "./config.json"; // Ok, type-only import type config2Type2 from "./config.json" with { type: "json" }; // Error, import attributes not allowed on type-only imports ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2857: Import attributes cannot be used with type-only imports or exports. import { version } from "./config.json" with { type: "json" }; // Error, named import ~~~~~~~ -!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNodeNext'. +!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. import * as config3 from "./config.json" with { type: "json" }; config3.version; // Error ~~~~~~~ diff --git a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt.diff b/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt.diff deleted file mode 100644 index 2a8c2e6d9b..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=nodenext).errors.txt.diff +++ /dev/null @@ -1,45 +0,0 @@ ---- old.nodeModulesJson(module=nodenext).errors.txt -+++ new.nodeModulesJson(module=nodenext).errors.txt -@@= skipped -0, +0 lines =@@ - /loosey.cts(1,36): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls. - /loosey.cts(6,9): error TS2339: Property 'default' does not exist on type '{ version: number; }'. --/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. --/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. --/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. -+/main.mts(2,22): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. -+/main.mts(3,19): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. -+/main.mts(7,21): error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. - /main.mts(9,47): error TS2857: Import attributes cannot be used with type-only imports or exports. --/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. -+/main.mts(10,10): error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNodeNext'. - /main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'. - - -@@= skipped -45, +45 lines =@@ - import { oops } from "not.json"; // Ok - import moreOops from "actually-json"; // Error in nodenext - ~~~~~~~~~~~~~~~ --!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. -+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. - import typed from "actually-json/typed"; // Error in nodenext - ~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. -+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. - - import config from "./config.json" with { type: "json" }; // Ok - import { default as config1 } from "./config.json" with { type: "json" }; // Ok - import config2 from "./config.json"; // Error in nodenext, no attribute - ~~~~~~~~~~~~~~~ --!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'NodeNext'. -+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNodeNext'. - import type config2Type from "./config.json"; // Ok, type-only - import type config2Type2 from "./config.json" with { type: "json" }; // Error, import attributes not allowed on type-only imports - ~~~~~~~~~~~~~~~~~~~~~ - !!! error TS2857: Import attributes cannot be used with type-only imports or exports. - import { version } from "./config.json" with { type: "json" }; // Error, named import - ~~~~~~~ --!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'NodeNext'. -+!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNodeNext'. - import * as config3 from "./config.json" with { type: "json" }; - config3.version; // Error - ~~~~~~~ \ No newline at end of file