Skip to content

Commit d2376b2

Browse files
committed
Fix incorrect BuildInfoEmitSignature unmarshalling
1 parent 263d4f8 commit d2376b2

File tree

3 files changed

+130
-8
lines changed

3 files changed

+130
-8
lines changed

internal/incremental/buildInfo.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,16 @@ func (b *BuildInfoEmitSignature) UnmarshalJSON(data []byte) error {
393393
var signature string
394394
var differsOnlyInDtsMap, differsInOptions bool
395395
if signatureV, ok := fileIdAndSignature[1].(string); !ok {
396-
if signatureList, ok := fileIdAndSignature[1].([]string); ok {
396+
if signatureList, ok := fileIdAndSignature[1].([]any); ok {
397397
if len(signatureList) == 0 {
398398
differsOnlyInDtsMap = true
399399
} else if len(signatureList) == 1 {
400-
signature = signatureList[0]
401-
differsInOptions = true
400+
if sig, ok := signatureList[0].(string); ok {
401+
signature = sig
402+
differsInOptions = true
403+
} else {
404+
return fmt.Errorf("invalid signature in BuildInfoEmitSignature: expected string, got %T", signatureList[0])
405+
}
402406
} else {
403407
return fmt.Errorf("invalid signature in BuildInfoEmitSignature: expected string or []string with 0 or 1 element, got %d elements", len(signatureList))
404408
}

internal/testutil/incrementaltestutil/fs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func (f *FsHandlingBuildInfo) WriteFile(path string, data string, writeByteOrder
5252
if err := f.FS.WriteFile(path+".readable.baseline.txt", toReadableBuildInfo(&buildInfo, data), false); err != nil {
5353
return fmt.Errorf("testFs.WriteFile: failed to write readable build info: %w", err)
5454
}
55+
} else {
56+
panic("testFs.WriteFile: failed to unmarshal build info: - use underlying FS's write method if this is intended use for testcase" + err.Error())
5557
}
5658
}
5759
return f.FS.WriteFile(path, data, writeByteOrderMark)

testdata/baselines/reference/tsc/noEmitOnError/when-declarationMap-changes.js

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,126 @@ Output::
149149
Found 1 error in a.ts:1
150150

151151
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
152-
{"version":"7.0.0-dev","root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6792320cbdee0286d2b3e83ff1d9fcc1-const x: 20 = 10;","signature":"c4dd771ef0ee0838482d28bc7dea6269-declare const x: 20;\n","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4448aee3ffd6eaf52054c6f2413c128a-const y = 10;","signature":"b0061f8cf6b7f4ef02673fae62fc90dd-declare const y = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true,"declaration":true,"declarationMap":true,"noEmitOnError":true},"semanticDiagnosticsPerFile":[[2,[{"pos":6,"end":7,"code":2322,"category":1,"message":"Type '10' is not assignable to type '20'."}]]],"affectedFilesPendingEmit":[2,[3,48]],"latestChangedDtsFile":"./b.d.ts","emitSignatures":[[2,["4be7af7f970696121f4f582a5d074177-declare const x = 10;\n"]],[3,[]]]}
152+
{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"6792320cbdee0286d2b3e83ff1d9fcc1-const x: 20 = 10;","signature":"c4dd771ef0ee0838482d28bc7dea6269-declare const x: 20;\n","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4448aee3ffd6eaf52054c6f2413c128a-const y = 10;","signature":"b0061f8cf6b7f4ef02673fae62fc90dd-declare const y = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true,"declaration":true,"declarationMap":true,"noEmitOnError":true},"semanticDiagnosticsPerFile":[[2,[{"pos":6,"end":7,"code":2322,"category":1,"message":"Type '10' is not assignable to type '20'."}]]],"affectedFilesPendingEmit":[2,[3,48]],"latestChangedDtsFile":"./b.d.ts","emitSignatures":[[2,["4be7af7f970696121f4f582a5d074177-declare const x = 10;\n"]],[3,[]]]}
153+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
154+
{
155+
"version": "FakeTSVersion",
156+
"root": [
157+
{
158+
"files": [
159+
"./a.ts",
160+
"./b.ts"
161+
],
162+
"original": [
163+
2,
164+
3
165+
]
166+
}
167+
],
168+
"fileNames": [
169+
"lib.d.ts",
170+
"./a.ts",
171+
"./b.ts"
172+
],
173+
"fileInfos": [
174+
{
175+
"fileName": "lib.d.ts",
176+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
177+
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
178+
"affectsGlobalScope": true,
179+
"impliedNodeFormat": "CommonJS",
180+
"original": {
181+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
182+
"affectsGlobalScope": true,
183+
"impliedNodeFormat": 1
184+
}
185+
},
186+
{
187+
"fileName": "./a.ts",
188+
"version": "6792320cbdee0286d2b3e83ff1d9fcc1-const x: 20 = 10;",
189+
"signature": "c4dd771ef0ee0838482d28bc7dea6269-declare const x: 20;\n",
190+
"affectsGlobalScope": true,
191+
"impliedNodeFormat": "CommonJS",
192+
"original": {
193+
"version": "6792320cbdee0286d2b3e83ff1d9fcc1-const x: 20 = 10;",
194+
"signature": "c4dd771ef0ee0838482d28bc7dea6269-declare const x: 20;\n",
195+
"affectsGlobalScope": true,
196+
"impliedNodeFormat": 1
197+
}
198+
},
199+
{
200+
"fileName": "./b.ts",
201+
"version": "4448aee3ffd6eaf52054c6f2413c128a-const y = 10;",
202+
"signature": "b0061f8cf6b7f4ef02673fae62fc90dd-declare const y = 10;\n",
203+
"affectsGlobalScope": true,
204+
"impliedNodeFormat": "CommonJS",
205+
"original": {
206+
"version": "4448aee3ffd6eaf52054c6f2413c128a-const y = 10;",
207+
"signature": "b0061f8cf6b7f4ef02673fae62fc90dd-declare const y = 10;\n",
208+
"affectsGlobalScope": true,
209+
"impliedNodeFormat": 1
210+
}
211+
}
212+
],
213+
"options": {
214+
"composite": true,
215+
"declaration": true,
216+
"declarationMap": true,
217+
"noEmitOnError": true
218+
},
219+
"semanticDiagnosticsPerFile": [
220+
[
221+
"./a.ts",
222+
[
223+
{
224+
"pos": 6,
225+
"end": 7,
226+
"code": 2322,
227+
"category": 1,
228+
"message": "Type '10' is not assignable to type '20'."
229+
}
230+
]
231+
]
232+
],
233+
"affectedFilesPendingEmit": [
234+
[
235+
"./a.ts",
236+
"Js|Dts|DtsMap",
237+
2
238+
],
239+
[
240+
"./b.ts",
241+
"DtsEmit|DtsMap",
242+
[
243+
3,
244+
48
245+
]
246+
]
247+
],
248+
"latestChangedDtsFile": "./b.d.ts",
249+
"emitSignatures": [
250+
{
251+
"file": "./a.ts",
252+
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
253+
"differsInOptions": true,
254+
"original": [
255+
2,
256+
[
257+
"4be7af7f970696121f4f582a5d074177-declare const x = 10;\n"
258+
]
259+
]
260+
},
261+
{
262+
"file": "./b.ts",
263+
"differsOnlyInDtsMap": true,
264+
"original": [
265+
3,
266+
[]
267+
]
268+
}
269+
],
270+
"size": 1620
271+
}
153272

154273
tsconfig.json::
155274
SemanticDiagnostics::
@@ -177,7 +296,6 @@ declare const y = 10;
177296
//# sourceMappingURL=b.d.ts.map
178297
//// [/home/src/workspaces/project/b.d.ts.map] *new*
179298
{"version":3,"file":"b.d.ts","sourceRoot":"","sources":["b.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,CAAC,KAAK,CAAC"}
180-
//// [/home/src/workspaces/project/b.js] *rewrite with same content*
181299
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
182300
{"version":"FakeTSVersion","root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4447ab8c90027f28bdaff9f2056779ce-const x = 10;","signature":"4be7af7f970696121f4f582a5d074177-declare const x = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4448aee3ffd6eaf52054c6f2413c128a-const y = 10;","signature":"b0061f8cf6b7f4ef02673fae62fc90dd-declare const y = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true,"declaration":true,"declarationMap":true,"noEmitOnError":true},"latestChangedDtsFile":"./b.d.ts"}
183301
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
@@ -254,7 +372,5 @@ tsconfig.json::
254372
SemanticDiagnostics::
255373
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
256374
*refresh* /home/src/workspaces/project/a.ts
257-
*refresh* /home/src/workspaces/project/b.ts
258375
Signatures::
259-
(stored at emit) /home/src/workspaces/project/a.ts
260-
(stored at emit) /home/src/workspaces/project/b.ts
376+
(computed .d.ts) /home/src/workspaces/project/a.ts

0 commit comments

Comments
 (0)