Skip to content

Commit d604acb

Browse files
authored
Add missing calls to AddSyntheticLeadingComment in node builder (#1607)
1 parent 2c91932 commit d604acb

21 files changed

+12344
-12413
lines changed

internal/checker/nodebuilderimpl.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ func (b *nodeBuilderImpl) createElidedInformationPlaceholder() *ast.TypeNode {
210210
if b.ctx.flags&nodebuilder.FlagsNoTruncation == 0 {
211211
return b.f.NewTypeReferenceNode(b.f.NewIdentifier("..."), nil /*typeArguments*/)
212212
}
213-
// addSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "elided") // !!!
214-
return b.f.NewKeywordTypeNode(ast.KindAnyKeyword)
213+
return b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)
215214
}
216215

217216
func (b *nodeBuilderImpl) mapToTypeNodes(list []*Type, isBareList bool) *ast.NodeList {
@@ -223,8 +222,7 @@ func (b *nodeBuilderImpl) mapToTypeNodes(list []*Type, isBareList bool) *ast.Nod
223222
if !isBareList {
224223
var node *ast.Node
225224
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
226-
// addSyntheticLeadingComment(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword), SyntaxKind.MultiLineCommentTrivia, `... ${types.length} elided ...`)
227-
node = b.f.NewKeywordTypeNode(ast.KindAnyKeyword)
225+
node = b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)
228226
} else {
229227
node = b.f.NewTypeReferenceNode(b.f.NewIdentifier("..."), nil /*typeArguments*/)
230228
}
@@ -237,8 +235,7 @@ func (b *nodeBuilderImpl) mapToTypeNodes(list []*Type, isBareList bool) *ast.Nod
237235
}
238236

239237
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
240-
// addSyntheticLeadingComment(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword), SyntaxKind.MultiLineCommentTrivia, `... ${types.length - 2} more elided ...`)
241-
nodes[1] = b.f.NewKeywordTypeNode(ast.KindAnyKeyword)
238+
nodes[1] = b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(list)-2), false /*hasTrailingNewLine*/)
242239
} else {
243240
text := fmt.Sprintf("... %d more ...", len(list)-2)
244241
nodes[1] = b.f.NewTypeReferenceNode(b.f.NewIdentifier(text), nil /*typeArguments*/)
@@ -262,8 +259,7 @@ func (b *nodeBuilderImpl) mapToTypeNodes(list []*Type, isBareList bool) *ast.Nod
262259
for i, t := range list {
263260
if b.checkTruncationLength() && (i+2 < len(list)-1) {
264261
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
265-
// addSyntheticLeadingComment(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword), SyntaxKind.MultiLineCommentTrivia, `... ${types.length} elided ...`)
266-
result = append(result, b.f.NewKeywordTypeNode(ast.KindAnyKeyword))
262+
result = append(result, b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(list)-i), false /*hasTrailingNewLine*/))
267263
} else {
268264
text := fmt.Sprintf("... %d more ...", len(list)-i)
269265
result = append(result, b.f.NewTypeReferenceNode(b.f.NewIdentifier(text), nil /*typeArguments*/))
@@ -1805,13 +1801,6 @@ func (b *nodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa
18051801
// if typeArguments != nil {
18061802
// node.TypeArguments = b.f.NewNodeList(typeArguments)
18071803
// }
1808-
// !!! TODO: synthetic comment support
1809-
// if signature.declaration. /* ? */ kind == ast.KindJSDocSignature && signature.declaration.Parent.Kind == ast.KindJSDocOverloadTag {
1810-
// comment := getTextOfNode(signature.declaration.Parent.Parent, true /*includeTrivia*/).slice(2, -2).split(regexp.MustParse(`\r\n|\n|\r`)).map_(func(line string) string {
1811-
// return line.replace(regexp.MustParse(`^\s+`), " ")
1812-
// }).join("\n")
1813-
// addSyntheticLeadingComment(node, ast.KindMultiLineCommentTrivia, comment, true /*hasTrailingNewLine*/)
1814-
// }
18151804

18161805
cleanup()
18171806
return node
@@ -2248,7 +2237,7 @@ func (b *nodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
22482237
name: propertyName,
22492238
questionToken: optionalToken,
22502239
})
2251-
b.setCommentRange(methodDeclaration, core.Coalesce(signature.declaration, propertySymbol.ValueDeclaration)) // !!! missing JSDoc support formerly provided by preserveCommentsOn
2240+
b.setCommentRange(methodDeclaration, core.Coalesce(signature.declaration, propertySymbol.ValueDeclaration))
22522241
typeElements = append(typeElements, methodDeclaration)
22532242
}
22542243
if len(signatures) != 0 || optionalToken == nil {
@@ -2279,7 +2268,7 @@ func (b *nodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
22792268
}
22802269
propertySignature := b.f.NewPropertySignatureDeclaration(modifiers, propertyName, optionalToken, propertyTypeNode, nil)
22812270

2282-
b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration) // !!! missing JSDoc support formerly provided by preserveCommentsOn
2271+
b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration)
22832272
typeElements = append(typeElements, propertySignature)
22842273

22852274
return typeElements
@@ -2289,9 +2278,7 @@ func (b *nodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
22892278
if b.checkTruncationLength() {
22902279
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
22912280
elem := b.f.NewNotEmittedTypeElement()
2292-
// TODO: attach synthetic comment
2293-
// b.e.addSyntheticTrailingComment(elem, ast.KindMultiLineCommentTrivia, "elided")
2294-
return b.f.NewNodeList([]*ast.TypeElement{elem})
2281+
return b.f.NewNodeList([]*ast.TypeElement{b.e.AddSyntheticLeadingComment(elem, ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)})
22952282
}
22962283
return b.f.NewNodeList([]*ast.Node{b.f.NewPropertySignatureDeclaration(nil, b.f.NewIdentifier("..."), nil, nil, nil)})
22972284
}
@@ -2327,11 +2314,7 @@ func (b *nodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
23272314
}
23282315
if b.checkTruncationLength() && (i+2 < len(properties)-1) {
23292316
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
2330-
// !!! synthetic comment support - missing middle silently elided without
2331-
// typeElement := typeElements[len(typeElements) - 1].Clone()
2332-
// typeElements = typeElements[0:len(typeElements)-1]
2333-
// b.e.addSyntheticTrailingComment(typeElement, ast.KindMultiLineCommentTrivia, __TEMPLATE__("... ", properties.length-i, " more elided ..."))
2334-
// typeElements = append(typeElements, typeElement)
2317+
typeElements[len(typeElements)-1] = b.e.AddSyntheticLeadingComment(typeElements[len(typeElements)-1], ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(properties)-i), false /*hasTrailingNewLine*/)
23352318
} else {
23362319
text := fmt.Sprintf("... %d more ...", len(properties)-i)
23372320
typeElements = append(typeElements, b.f.NewPropertySignatureDeclaration(nil, b.f.NewIdentifier(text), nil, nil, nil))
@@ -2821,10 +2804,9 @@ func (b *nodeBuilderImpl) typeToTypeNode(t *Type) *ast.TypeNode {
28212804
if t.alias != nil {
28222805
return t.alias.ToTypeReferenceNode(b)
28232806
}
2824-
// !!! TODO: add comment once synthetic comment additions to nodes are supported
2825-
// if t == b.ch.unresolvedType {
2826-
// return e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "unresolved")
2827-
// }
2807+
if t == b.ch.unresolvedType {
2808+
return b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "unresolved", false /*hasTrailingNewLine*/)
2809+
}
28282810
b.ctx.approximateLength += 3
28292811
return b.f.NewKeywordTypeNode(core.IfElse(t == b.ch.intrinsicMarkerType, ast.KindIntrinsicKeyword, ast.KindAnyKeyword))
28302812
}

testdata/baselines/reference/submodule/compiler/classExpressionInClassStaticDeclarations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class C {
1616
declare class C {
1717
static D: {
1818
new (): {};
19-
D: any;
19+
D: /*elided*/ any;
2020
};
2121
}

testdata/baselines/reference/submodule/compiler/classExpressionInClassStaticDeclarations.js.diff

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,4 @@
1616
+}
1717

1818

19-
//// [classExpressionInClassStaticDeclarations.d.ts]
20-
declare class C {
21-
static D: {
22-
new (): {};
23-
- D: /*elided*/ any;
24-
+ D: any;
25-
};
26-
}
19+
//// [classExpressionInClassStaticDeclarations.d.ts]

testdata/baselines/reference/submodule/compiler/declFileTypeofFunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ declare function b1(): typeof b1;
7070
declare function foo(): typeof foo;
7171
declare var foo1: typeof foo;
7272
declare var foo2: typeof foo;
73-
declare var foo3: () => any;
74-
declare var x: () => any;
73+
declare var foo3: () => /*elided*/ any;
74+
declare var x: () => /*elided*/ any;
7575
declare function foo5(x: number): (x: number) => number;

testdata/baselines/reference/submodule/compiler/declFileTypeofFunction.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
declare var foo2: typeof foo;
77
-declare var foo3: () => () => /*elided*/ any;
88
-declare var x: () => () => /*elided*/ any;
9-
+declare var foo3: () => any;
10-
+declare var x: () => any;
9+
+declare var foo3: () => /*elided*/ any;
10+
+declare var x: () => /*elided*/ any;
1111
declare function foo5(x: number): (x: number) => number;

testdata/baselines/reference/submodule/compiler/declarationEmitInferredTypeAlias4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ function f() {
1616

1717
//// [declarationEmitInferredTypeAlias4.d.ts]
1818
declare function f<A>(): A[] | {
19-
x: A[] | any;
19+
x: A[] | /*elided*/ any;
2020
};

testdata/baselines/reference/submodule/compiler/declarationEmitInferredTypeAlias4.js.diff

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

0 commit comments

Comments
 (0)