Skip to content

Commit bac802a

Browse files
committed
Fix forEachChild to include withClause for ModuleDeclaration
The test harness validates that all child nodes are visited by forEachChild. We added withClause to ModuleDeclaration but forgot to update the forEachChild visitor in parser.ts to include it, causing the error: 'Missing child when forEach'ing over node: ModuleDeclaration-withClause' This commit adds the withClause to the forEachChild visitor for ModuleDeclaration.
1 parent edc1a1f commit bac802a

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,8 @@ const forEachChildTable: ForEachChildTable = {
923923
[SyntaxKind.ModuleDeclaration]: function forEachChildInModuleDeclaration<T>(node: ModuleDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
924924
return visitNodes(cbNode, cbNodes, node.modifiers) ||
925925
visitNode(cbNode, node.name) ||
926-
visitNode(cbNode, node.body);
926+
visitNode(cbNode, node.body) ||
927+
visitNode(cbNode, node.withClause);
927928
},
928929
[SyntaxKind.ImportEqualsDeclaration]: function forEachChildInImportEqualsDeclaration<T>(node: ImportEqualsDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
929930
return visitNodes(cbNode, cbNodes, node.modifiers) ||

tests/baselines/reference/ambientModuleWithImportAttributes.types

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ declare module "*.css" with { type: "css" } {
1313
export default stylesheet;
1414
>stylesheet : CSSStyleSheet
1515
> : ^^^^^^^^^^^^^
16+
17+
>type : any
18+
> : ^^^
19+
20+
const stylesheet: CSSStyleSheet;
21+
export default stylesheet;
1622
}
1723

1824
declare module "*.json" with { type: "json" } {
@@ -26,6 +32,12 @@ declare module "*.json" with { type: "json" } {
2632
export default data;
2733
>data : any
2834
> : ^^^
35+
36+
>type : any
37+
> : ^^^
38+
39+
const data: any;
40+
export default data;
2941
}
3042

3143
// Ambient module with specific name and import attributes
@@ -40,6 +52,12 @@ declare module "my-module" with { type: "custom" } {
4052
export const bar: string;
4153
>bar : string
4254
> : ^^^^^^
55+
56+
>type : any
57+
> : ^^^
58+
59+
export function foo(): void;
60+
export const bar: string;
4361
}
4462

4563
// Ambient module with multiple attributes
@@ -50,6 +68,13 @@ declare module "multi-attr" with { type: "json", integrity: "sha384-..." } {
5068
export const value: number;
5169
>value : number
5270
> : ^^^^^^
71+
72+
>type : any
73+
> : ^^^
74+
>integrity : any
75+
> : ^^^
76+
77+
export const value: number;
5378
}
5479

5580
// Ambient module without import attributes (should still work)

tests/baselines/reference/ambientModuleWithImportAttributesDiagnostics.types

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ declare module "*.css" with { type: "css" } {
1313
export default stylesheet;
1414
>stylesheet : CSSStyleSheet
1515
> : ^^^^^^^^^^^^^
16+
17+
>type : any
18+
> : ^^^
19+
20+
const stylesheet: CSSStyleSheet;
21+
export default stylesheet;
1622
}
1723

1824
declare module "*.json" with { type: "json" } {
@@ -26,6 +32,12 @@ declare module "*.json" with { type: "json" } {
2632
export default data;
2733
>data : any
2834
> : ^^^
35+
36+
>type : any
37+
> : ^^^
38+
39+
const data: any;
40+
export default data;
2941
}
3042

3143
declare module "*.txt" {

tests/baselines/reference/ambientModuleWithImportAttributesSemantics.types

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ declare module "*.css" with { type: "css" } {
1313
export default stylesheet;
1414
>stylesheet : CSSStyleSheet
1515
> : ^^^^^^^^^^^^^
16+
17+
>type : any
18+
> : ^^^
19+
20+
const stylesheet: CSSStyleSheet;
21+
export default stylesheet;
1622
}
1723

1824
// Test exact match with different attributes
@@ -27,6 +33,12 @@ declare module "*.json" with { type: "json" } {
2733
export default data;
2834
>data : any
2935
> : ^^^
36+
37+
>type : any
38+
> : ^^^
39+
40+
const data: any;
41+
export default data;
3042
}
3143

3244
// Test exact match without attributes
@@ -57,6 +69,14 @@ declare module "*.wasm" with { type: "module", version: "1" } {
5769
export default module;
5870
>module : WebAssembly.Module
5971
> : ^^^^^^^^^^^^^^^^^^
72+
73+
>type : any
74+
> : ^^^
75+
>version : any
76+
> : ^^^
77+
78+
const module: WebAssembly.Module;
79+
export default module;
6080
}
6181

6282
=== test.ts ===

0 commit comments

Comments
 (0)