Skip to content

Fix enum strings used in error messages #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 0 additions & 95 deletions internal/core/compileroptions_stringer_generated.go

This file was deleted.

51 changes: 51 additions & 0 deletions internal/core/modulekind_stringer_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions internal/core/scripttarget_stringer_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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; }; }'.
Expand Down Expand Up @@ -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" };
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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; }; }'.


Expand Down Expand Up @@ -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
~~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading