Skip to content

Commit 8370e5f

Browse files
authored
Fix enum strings used in error messages (microsoft#1283)
1 parent ed795b2 commit 8370e5f

10 files changed

+124
-220
lines changed

internal/core/compileroptions.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"github.com/microsoft/typescript-go/internal/tspath"
1010
)
1111

12-
//go:generate go tool golang.org/x/tools/cmd/stringer -type=ModuleKind,ScriptTarget -output=compileroptions_stringer_generated.go
13-
//go:generate go tool mvdan.cc/gofumpt -lang=go1.24 -w compileroptions_stringer_generated.go
12+
//go:generate go tool golang.org/x/tools/cmd/stringer -type=ModuleKind -trimprefix=ModuleKind -output=modulekind_stringer_generated.go
13+
//go:generate go tool golang.org/x/tools/cmd/stringer -type=ScriptTarget -trimprefix=ScriptTarget -output=scripttarget_stringer_generated.go
14+
//go:generate go tool mvdan.cc/gofumpt -lang=go1.24 -w modulekind_stringer_generated.go scripttarget_stringer_generated.go
1415

1516
type CompilerOptions struct {
1617
_ noCopy

internal/core/compileroptions_stringer_generated.go

Lines changed: 0 additions & 95 deletions
This file was deleted.

internal/core/modulekind_stringer_generated.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/core/scripttarget_stringer_generated.go

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/main.mts(5,36): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
44
/main.mts(6,52): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
55
/main.mts(9,47): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
6-
/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'.
6+
/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'.
77
/main.mts(10,41): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
88
/main.mts(11,42): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
99
/main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'.
@@ -61,7 +61,7 @@
6161
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
6262
import { version } from "./config.json" with { type: "json" }; // Error, named import
6363
~~~~~~~
64-
!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode16'.
64+
!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node16'.
6565
~~~~~~~~~~~~~~~~~~~~~
6666
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'.
6767
import * as config3 from "./config.json" with { type: "json" };

testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node16).errors.txt.diff

Lines changed: 0 additions & 20 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
/loosey.cts(1,36): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls.
33
/loosey.cts(2,8): error TS1259: Module '"/config"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
44
/loosey.cts(6,9): error TS2339: Property 'default' does not exist on type '{ version: number; }'.
5-
/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'.
6-
/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'.
7-
/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'.
5+
/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'.
6+
/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'.
7+
/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'.
88
/main.mts(9,47): error TS2857: Import attributes cannot be used with type-only imports or exports.
9-
/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'.
9+
/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'.
1010
/main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'.
1111

1212

@@ -48,23 +48,23 @@
4848
import { oops } from "not.json"; // Ok
4949
import moreOops from "actually-json"; // Error in nodenext
5050
~~~~~~~~~~~~~~~
51-
!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'.
51+
!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'.
5252
import typed from "actually-json/typed"; // Error in nodenext
5353
~~~~~~~~~~~~~~~~~~~~~
54-
!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'.
54+
!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'.
5555

5656
import config from "./config.json" with { type: "json" }; // Ok
5757
import { default as config1 } from "./config.json" with { type: "json" }; // Ok
5858
import config2 from "./config.json"; // Error in nodenext, no attribute
5959
~~~~~~~~~~~~~~~
60-
!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'.
60+
!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'.
6161
import type config2Type from "./config.json"; // Ok, type-only
6262
import type config2Type2 from "./config.json" with { type: "json" }; // Error, import attributes not allowed on type-only imports
6363
~~~~~~~~~~~~~~~~~~~~~
6464
!!! error TS2857: Import attributes cannot be used with type-only imports or exports.
6565
import { version } from "./config.json" with { type: "json" }; // Error, named import
6666
~~~~~~~
67-
!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode18'.
67+
!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node18'.
6868
import * as config3 from "./config.json" with { type: "json" };
6969
config3.version; // Error
7070
~~~~~~~

testdata/baselines/reference/submodule/conformance/nodeModulesJson(module=node18).errors.txt.diff

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,9 @@
55
/loosey.cts(1,36): error TS2856: Import attributes are not allowed on statements that compile to CommonJS 'require' calls.
66
+/loosey.cts(2,8): error TS1259: Module '"/config"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
77
/loosey.cts(6,9): error TS2339: Property 'default' does not exist on type '{ version: number; }'.
8-
-/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'.
9-
-/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'.
10-
-/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'.
11-
+/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'.
12-
+/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'.
13-
+/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'.
14-
/main.mts(9,47): error TS2857: Import attributes cannot be used with type-only imports or exports.
15-
-/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'.
16-
+/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'.
17-
/main.mts(12,9): error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'.
18-
19-
20-
@@= skipped -45, +47 lines =@@
21-
import { oops } from "not.json"; // Ok
22-
import moreOops from "actually-json"; // Error in nodenext
23-
~~~~~~~~~~~~~~~
24-
-!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'.
25-
+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'.
26-
import typed from "actually-json/typed"; // Error in nodenext
27-
~~~~~~~~~~~~~~~~~~~~~
28-
-!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'.
29-
+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'.
30-
31-
import config from "./config.json" with { type: "json" }; // Ok
32-
import { default as config1 } from "./config.json" with { type: "json" }; // Ok
33-
import config2 from "./config.json"; // Error in nodenext, no attribute
34-
~~~~~~~~~~~~~~~
35-
-!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node18'.
36-
+!!! error TS1543: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'ModuleKindNode18'.
37-
import type config2Type from "./config.json"; // Ok, type-only
38-
import type config2Type2 from "./config.json" with { type: "json" }; // Error, import attributes not allowed on type-only imports
39-
~~~~~~~~~~~~~~~~~~~~~
40-
!!! error TS2857: Import attributes cannot be used with type-only imports or exports.
41-
import { version } from "./config.json" with { type: "json" }; // Error, named import
42-
~~~~~~~
43-
-!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'Node18'.
44-
+!!! error TS1544: Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to 'ModuleKindNode18'.
45-
import * as config3 from "./config.json" with { type: "json" };
46-
config3.version; // Error
47-
~~~~~~~
8+
/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'.
9+
/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'.
10+
@@= skipped -68, +70 lines =@@
4811
!!! error TS2339: Property 'version' does not exist on type '{ default: { version: number; }; }'.
4912
config3.default; // Ok
5013

0 commit comments

Comments
 (0)