Skip to content

Commit 08b7e8c

Browse files
committed
Verify diagnostic and options serializing
1 parent 19f5ecb commit 08b7e8c

File tree

5 files changed

+296
-19
lines changed

5 files changed

+296
-19
lines changed

internal/execute/testsys_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
type FileMap map[string]string
2020

21-
func newTestSys(fileOrFolderList FileMap, cwd string, args ...string) *testSys {
21+
func newTestSys(fileOrFolderList FileMap, cwd string) *testSys {
2222
if cwd == "" {
2323
cwd = "/home/src/workspaces/project"
2424
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package execute_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/bundled"
7+
)
8+
9+
func TestIncremental(t *testing.T) {
10+
t.Parallel()
11+
if !bundled.Embedded {
12+
// Without embedding, we'd need to read all of the lib files out from disk into the MapFS.
13+
// Just skip this for now.
14+
t.Skip("bundled files are not embedded")
15+
}
16+
17+
testCases := []*tscInput{
18+
{
19+
subScenario: "serializing error chain",
20+
sys: newTestSys(FileMap{
21+
"/home/src/workspaces/project/tsconfig.json": `{
22+
"compilerOptions": {
23+
"incremental": true,
24+
"strict": true,
25+
"jsx": "react",
26+
"module": "esnext",
27+
},
28+
}`,
29+
"/home/src/workspaces/project/index.tsx": `
30+
declare namespace JSX {
31+
interface ElementChildrenAttribute { children: {}; }
32+
interface IntrinsicElements { div: {} }
33+
}
34+
35+
declare var React: any;
36+
37+
declare function Component(props: never): any;
38+
declare function Component(props: { children?: number }): any;
39+
(<Component>
40+
<div />
41+
<div />
42+
</Component>)`,
43+
}, "/home/src/workspaces/project"),
44+
},
45+
}
46+
47+
for _, test := range testCases {
48+
test.verify(t, "incremental")
49+
}
50+
}

internal/incremental/buildInfo.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,27 @@ func (b *BuildInfoDiagnosticsOfFile) MarshalJSON() ([]byte, error) {
213213
}
214214

215215
func (b *BuildInfoDiagnosticsOfFile) UnmarshalJSON(data []byte) error {
216-
var fileIdAndDiagnostics []any
216+
var fileIdAndDiagnostics []json.RawMessage
217217
if err := json.Unmarshal(data, &fileIdAndDiagnostics); err != nil {
218218
return fmt.Errorf("invalid BuildInfoDiagnosticsOfFile: %s", data)
219219
}
220220
if len(fileIdAndDiagnostics) != 2 {
221221
return fmt.Errorf("invalid BuildInfoDiagnosticsOfFile: expected 2 elements, got %d", len(fileIdAndDiagnostics))
222222
}
223223
var fileId BuildInfoFileId
224-
if fileIdV, ok := fileIdAndDiagnostics[0].(float64); !ok {
225-
return fmt.Errorf("invalid fileId in BuildInfoDiagnosticsOfFile: expected float64, got %T", fileIdAndDiagnostics[0])
226-
} else {
227-
fileId = BuildInfoFileId(fileIdV)
224+
if err := json.Unmarshal(fileIdAndDiagnostics[0], &fileId); err != nil {
225+
return fmt.Errorf("invalid fileId in BuildInfoDiagnosticsOfFile: %s", err)
228226
}
229-
if diagnostics, ok := fileIdAndDiagnostics[1].([]*BuildInfoDiagnostic); ok {
230-
*b = BuildInfoDiagnosticsOfFile{
231-
FileId: fileId,
232-
Diagnostics: diagnostics,
233-
}
234-
return nil
227+
228+
var diagnostics []*BuildInfoDiagnostic
229+
if err := json.Unmarshal(fileIdAndDiagnostics[1], &diagnostics); err != nil {
230+
return fmt.Errorf("invalid diagnostics in BuildInfoDiagnosticsOfFile: %s", err)
231+
}
232+
*b = BuildInfoDiagnosticsOfFile{
233+
FileId: fileId,
234+
Diagnostics: diagnostics,
235235
}
236-
return fmt.Errorf("invalid diagnostics in BuildInfoDiagnosticsOfFile: expected []*BuildInfoDiagnostic, got %T", fileIdAndDiagnostics[1])
236+
return nil
237237
}
238238

239239
type BuildInfoSemanticDiagnostic struct {

internal/tsoptions/parsinghelpers.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
290290
case "mapRoot":
291291
allOptions.MapRoot = parseString(value)
292292
case "module":
293-
allOptions.Module = value.(core.ModuleKind)
293+
allOptions.Module = floatOrInt32ToFlag[core.ModuleKind](value)
294294
case "moduleDetectionKind":
295-
allOptions.ModuleDetection = value.(core.ModuleDetectionKind)
295+
allOptions.ModuleDetection = floatOrInt32ToFlag[core.ModuleDetectionKind](value)
296296
case "moduleResolution":
297-
allOptions.ModuleResolution = value.(core.ModuleResolutionKind)
297+
allOptions.ModuleResolution = floatOrInt32ToFlag[core.ModuleResolutionKind](value)
298298
case "moduleSuffixes":
299299
allOptions.ModuleSuffixes = parseStringArray(value)
300300
case "moduleDetection":
301-
allOptions.ModuleDetection = value.(core.ModuleDetectionKind)
301+
allOptions.ModuleDetection = floatOrInt32ToFlag[core.ModuleDetectionKind](value)
302302
case "noCheck":
303303
allOptions.NoCheck = parseTristate(value)
304304
case "noFallthroughCasesInSwitch":
@@ -388,7 +388,7 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
388388
case "suppressOutputPathCheck":
389389
allOptions.SuppressOutputPathCheck = parseTristate(value)
390390
case "target":
391-
allOptions.Target = value.(core.ScriptTarget)
391+
allOptions.Target = floatOrInt32ToFlag[core.ScriptTarget](value)
392392
case "traceResolution":
393393
allOptions.TraceResolution = parseTristate(value)
394394
case "tsBuildInfoFile":
@@ -428,7 +428,7 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
428428
case "outDir":
429429
allOptions.OutDir = parseString(value)
430430
case "newLine":
431-
allOptions.NewLine = value.(core.NewLineKind)
431+
allOptions.NewLine = floatOrInt32ToFlag[core.NewLineKind](value)
432432
case "watch":
433433
allOptions.Watch = parseTristate(value)
434434
case "pprofDir":
@@ -444,6 +444,13 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
444444
return true
445445
}
446446

447+
func floatOrInt32ToFlag[T ~int32](value any) T {
448+
if v, ok := value.(T); ok {
449+
return v
450+
}
451+
return T(value.(float64))
452+
}
453+
447454
func ParseWatchOptions(key string, value any, allOptions *core.WatchOptions) []*ast.Diagnostic {
448455
if allOptions == nil {
449456
return nil
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
2+
currentDirectory::/home/src/workspaces/project
3+
useCaseSensitiveFileNames::true
4+
Input::
5+
//// [/home/src/workspaces/project/index.tsx] new file
6+
7+
declare namespace JSX {
8+
interface ElementChildrenAttribute { children: {}; }
9+
interface IntrinsicElements { div: {} }
10+
}
11+
12+
declare var React: any;
13+
14+
declare function Component(props: never): any;
15+
declare function Component(props: { children?: number }): any;
16+
(<Component>
17+
<div />
18+
<div />
19+
</Component>)
20+
//// [/home/src/workspaces/project/tsconfig.json] new file
21+
{
22+
"compilerOptions": {
23+
"incremental": true,
24+
"strict": true,
25+
"jsx": "react",
26+
"module": "esnext",
27+
},
28+
}
29+
30+
ExitStatus:: 2
31+
32+
CompilerOptions::{}
33+
Output::
34+
index.tsx:11:23 - error TS2746: This JSX tag's 'children' prop expects a single child of type 'number | undefined', but multiple children were provided.
35+
36+
11 (<Component>
37+
   ~~~~~~~~~
38+
39+
index.tsx:11:23 - error TS2769: No overload matches this call.
40+
The last overload gave the following error.
41+
This JSX tag's 'children' prop expects a single child of type 'number | undefined', but multiple children were provided.
42+
43+
11 (<Component>
44+
   ~~~~~~~~~
45+
46+
index.tsx:10:38 - The last overload is declared here.
47+
10 declare function Component(props: { children?: number }): any;
48+
   ~~~~~~~~~
49+
50+
51+
Found 2 errors in the same file, starting at: index.tsx:11
52+
53+
//// [/home/src/workspaces/project/index.js] new file
54+
(React.createElement(Component, null, React.createElement("div", null), React.createElement("div", null)));
55+
56+
//// [/home/src/workspaces/project/index.tsx] no change
57+
//// [/home/src/workspaces/project/tsconfig.json] no change
58+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] new file
59+
{"Version":"FakeTSVersion","fileNames":["bundled:///libs/lib.d.ts","bundled:///libs/lib.es5.d.ts","bundled:///libs/lib.dom.d.ts","bundled:///libs/lib.webworker.importscripts.d.ts","bundled:///libs/lib.scripthost.d.ts","bundled:///libs/lib.decorators.d.ts","bundled:///libs/lib.decorators.legacy.d.ts","./index.tsx"],"fileInfos":["a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"c7980af975245f04431574a9c187c9abd1c0ba29d83a127ad2af4b952296f935","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"jsx":3,"module":99,"strict":true},"semanticDiagnosticsPerFile":[[8,[{"pos":426,"end":435,"code":2746,"category":1,"message":"This JSX tag's 'children' prop expects a single child of type 'number | undefined', but multiple children were provided."},{"pos":426,"end":435,"code":2769,"category":1,"message":"No overload matches this call.","messageChain":[{"pos":426,"end":435,"code":2770,"category":1,"message":"The last overload gave the following error.","messageChain":[{"pos":426,"end":435,"code":2746,"category":1,"message":"This JSX tag's 'children' prop expects a single child of type 'number | undefined', but multiple children were provided."}]}],"relatedInformation":[{"pos":358,"end":367,"code":2771,"category":1,"message":"The last overload is declared here."}]}]]]}
60+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] new file
61+
{
62+
"Version": "FakeTSVersion",
63+
"fileNames": [
64+
"bundled:///libs/lib.d.ts",
65+
"bundled:///libs/lib.es5.d.ts",
66+
"bundled:///libs/lib.dom.d.ts",
67+
"bundled:///libs/lib.webworker.importscripts.d.ts",
68+
"bundled:///libs/lib.scripthost.d.ts",
69+
"bundled:///libs/lib.decorators.d.ts",
70+
"bundled:///libs/lib.decorators.legacy.d.ts",
71+
"./index.tsx"
72+
],
73+
"fileInfos": [
74+
{
75+
"fileName": "bundled:///libs/lib.d.ts",
76+
"version": "a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",
77+
"signature": "a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",
78+
"impliedNodeFormat": "CommonJS"
79+
},
80+
{
81+
"fileName": "bundled:///libs/lib.es5.d.ts",
82+
"version": "69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546",
83+
"signature": "69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546",
84+
"affectsGlobalScope": true,
85+
"impliedNodeFormat": "CommonJS",
86+
"original": {
87+
"version": "69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546",
88+
"affectsGlobalScope": true,
89+
"impliedNodeFormat": 1
90+
}
91+
},
92+
{
93+
"fileName": "bundled:///libs/lib.dom.d.ts",
94+
"version": "092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763",
95+
"signature": "092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763",
96+
"affectsGlobalScope": true,
97+
"impliedNodeFormat": "CommonJS",
98+
"original": {
99+
"version": "092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763",
100+
"affectsGlobalScope": true,
101+
"impliedNodeFormat": 1
102+
}
103+
},
104+
{
105+
"fileName": "bundled:///libs/lib.webworker.importscripts.d.ts",
106+
"version": "80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89",
107+
"signature": "80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89",
108+
"affectsGlobalScope": true,
109+
"impliedNodeFormat": "CommonJS",
110+
"original": {
111+
"version": "80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89",
112+
"affectsGlobalScope": true,
113+
"impliedNodeFormat": 1
114+
}
115+
},
116+
{
117+
"fileName": "bundled:///libs/lib.scripthost.d.ts",
118+
"version": "cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573",
119+
"signature": "cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573",
120+
"affectsGlobalScope": true,
121+
"impliedNodeFormat": "CommonJS",
122+
"original": {
123+
"version": "cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573",
124+
"affectsGlobalScope": true,
125+
"impliedNodeFormat": 1
126+
}
127+
},
128+
{
129+
"fileName": "bundled:///libs/lib.decorators.d.ts",
130+
"version": "8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea",
131+
"signature": "8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea",
132+
"affectsGlobalScope": true,
133+
"impliedNodeFormat": "CommonJS",
134+
"original": {
135+
"version": "8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea",
136+
"affectsGlobalScope": true,
137+
"impliedNodeFormat": 1
138+
}
139+
},
140+
{
141+
"fileName": "bundled:///libs/lib.decorators.legacy.d.ts",
142+
"version": "782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538",
143+
"signature": "782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538",
144+
"affectsGlobalScope": true,
145+
"impliedNodeFormat": "CommonJS",
146+
"original": {
147+
"version": "782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538",
148+
"affectsGlobalScope": true,
149+
"impliedNodeFormat": 1
150+
}
151+
},
152+
{
153+
"fileName": "./index.tsx",
154+
"version": "c7980af975245f04431574a9c187c9abd1c0ba29d83a127ad2af4b952296f935",
155+
"signature": "c7980af975245f04431574a9c187c9abd1c0ba29d83a127ad2af4b952296f935",
156+
"affectsGlobalScope": true,
157+
"impliedNodeFormat": "CommonJS",
158+
"original": {
159+
"version": "c7980af975245f04431574a9c187c9abd1c0ba29d83a127ad2af4b952296f935",
160+
"affectsGlobalScope": true,
161+
"impliedNodeFormat": 1
162+
}
163+
}
164+
],
165+
"options": {
166+
"jsx": 3,
167+
"module": 99,
168+
"strict": true
169+
},
170+
"semanticDiagnosticsPerFile": [
171+
[
172+
"./index.tsx",
173+
[
174+
{
175+
"pos": 426,
176+
"end": 435,
177+
"code": 2746,
178+
"category": 1,
179+
"message": "This JSX tag's 'children' prop expects a single child of type 'number | undefined', but multiple children were provided."
180+
},
181+
{
182+
"pos": 426,
183+
"end": 435,
184+
"code": 2769,
185+
"category": 1,
186+
"message": "No overload matches this call.",
187+
"messageChain": [
188+
{
189+
"pos": 426,
190+
"end": 435,
191+
"code": 2770,
192+
"category": 1,
193+
"message": "The last overload gave the following error.",
194+
"messageChain": [
195+
{
196+
"pos": 426,
197+
"end": 435,
198+
"code": 2746,
199+
"category": 1,
200+
"message": "This JSX tag's 'children' prop expects a single child of type 'number | undefined', but multiple children were provided."
201+
}
202+
]
203+
}
204+
],
205+
"relatedInformation": [
206+
{
207+
"pos": 358,
208+
"end": 367,
209+
"code": 2771,
210+
"category": 1,
211+
"message": "The last overload is declared here."
212+
}
213+
]
214+
}
215+
]
216+
]
217+
],
218+
"size": 2074
219+
}
220+

0 commit comments

Comments
 (0)