Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ func (b *nodeBuilderImpl) createElidedInformationPlaceholder() *ast.TypeNode {
if b.ctx.flags&nodebuilder.FlagsNoTruncation == 0 {
return b.f.NewTypeReferenceNode(b.f.NewIdentifier("..."), nil /*typeArguments*/)
}
// addSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "elided") // !!!
return b.f.NewKeywordTypeNode(ast.KindAnyKeyword)
return b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)
}

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

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

cleanup()
return node
Expand Down Expand Up @@ -2247,7 +2236,7 @@ func (b *nodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
name: propertyName,
questionToken: optionalToken,
})
b.setCommentRange(methodDeclaration, core.Coalesce(signature.declaration, propertySymbol.ValueDeclaration)) // !!! missing JSDoc support formerly provided by preserveCommentsOn
b.setCommentRange(methodDeclaration, core.Coalesce(signature.declaration, propertySymbol.ValueDeclaration))
typeElements = append(typeElements, methodDeclaration)
}
if len(signatures) != 0 || optionalToken == nil {
Expand Down Expand Up @@ -2278,7 +2267,7 @@ func (b *nodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
}
propertySignature := b.f.NewPropertySignatureDeclaration(modifiers, propertyName, optionalToken, propertyTypeNode, nil)

b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration) // !!! missing JSDoc support formerly provided by preserveCommentsOn
b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration)
typeElements = append(typeElements, propertySignature)

return typeElements
Expand All @@ -2288,9 +2277,7 @@ func (b *nodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
if b.checkTruncationLength() {
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
elem := b.f.NewNotEmittedTypeElement()
// TODO: attach synthetic comment
// b.e.addSyntheticTrailingComment(elem, ast.KindMultiLineCommentTrivia, "elided")
return b.f.NewNodeList([]*ast.TypeElement{elem})
return b.f.NewNodeList([]*ast.TypeElement{b.e.AddSyntheticLeadingComment(elem, ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)})
}
return b.f.NewNodeList([]*ast.Node{b.f.NewPropertySignatureDeclaration(nil, b.f.NewIdentifier("..."), nil, nil, nil)})
}
Expand Down Expand Up @@ -2326,11 +2313,7 @@ func (b *nodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur
}
if b.checkTruncationLength() && (i+2 < len(properties)-1) {
if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
// !!! synthetic comment support - missing middle silently elided without
// typeElement := typeElements[len(typeElements) - 1].Clone()
// typeElements = typeElements[0:len(typeElements)-1]
// b.e.addSyntheticTrailingComment(typeElement, ast.KindMultiLineCommentTrivia, __TEMPLATE__("... ", properties.length-i, " more elided ..."))
// typeElements = append(typeElements, typeElement)
typeElements[len(typeElements)-1] = b.e.AddSyntheticLeadingComment(typeElements[len(typeElements)-1], ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(properties)-i), false /*hasTrailingNewLine*/)
} else {
text := fmt.Sprintf("... %d more ...", len(properties)-i)
typeElements = append(typeElements, b.f.NewPropertySignatureDeclaration(nil, b.f.NewIdentifier(text), nil, nil, nil))
Expand Down Expand Up @@ -2820,10 +2803,9 @@ func (b *nodeBuilderImpl) typeToTypeNode(t *Type) *ast.TypeNode {
if t.alias != nil {
return t.alias.ToTypeReferenceNode(b)
}
// !!! TODO: add comment once synthetic comment additions to nodes are supported
// if t == b.ch.unresolvedType {
// return e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "unresolved")
// }
if t == b.ch.unresolvedType {
return b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "unresolved", false /*hasTrailingNewLine*/)
}
b.ctx.approximateLength += 3
return b.f.NewKeywordTypeNode(core.IfElse(t == b.ch.intrinsicMarkerType, ast.KindIntrinsicKeyword, ast.KindAnyKeyword))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class C {
declare class C {
static D: {
new (): {};
D: any;
D: /*elided*/ any;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,4 @@
+}


//// [classExpressionInClassStaticDeclarations.d.ts]
declare class C {
static D: {
new (): {};
- D: /*elided*/ any;
+ D: any;
};
}
//// [classExpressionInClassStaticDeclarations.d.ts]
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ declare function b1(): typeof b1;
declare function foo(): typeof foo;
declare var foo1: typeof foo;
declare var foo2: typeof foo;
declare var foo3: () => any;
declare var x: () => any;
declare var foo3: () => /*elided*/ any;
declare var x: () => /*elided*/ any;
declare function foo5(x: number): (x: number) => number;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
declare var foo2: typeof foo;
-declare var foo3: () => () => /*elided*/ any;
-declare var x: () => () => /*elided*/ any;
+declare var foo3: () => any;
+declare var x: () => any;
+declare var foo3: () => /*elided*/ any;
+declare var x: () => /*elided*/ any;
declare function foo5(x: number): (x: number) => number;
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ function f() {

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

This file was deleted.

Loading
Loading