Skip to content

Commit 2668cdf

Browse files
authored
Add callback tag, fix jsdoc type parameter resolution (#1187)
1 parent 76d6872 commit 2668cdf

File tree

105 files changed

+763
-1258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+763
-1258
lines changed

internal/api/encoder/encoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
686686
return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.TypeExpression != nil) << 1) | (boolToByte(n.Name() != nil) << 2) | (boolToByte(n.Comment != nil) << 3)
687687
case ast.KindJSDocSignature:
688688
n := node.AsJSDocSignature()
689-
return (boolToByte(n.TypeParameters() != nil) << 0) | (boolToByte(n.Parameters != nil) << 1) | (boolToByte(n.Type != nil) << 2)
689+
return (boolToByte(n.TypeParameters != nil) << 0) | (boolToByte(n.Parameters != nil) << 1) | (boolToByte(n.Type != nil) << 2)
690690
case ast.KindClassStaticBlockDeclaration:
691691
n := node.AsClassStaticBlockDeclaration()
692692
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.Body != nil) << 1)

internal/ast/ast.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9201,6 +9201,7 @@ type JSDocTemplateTag struct {
92019201
JSDocTagBase
92029202
Constraint *Node
92039203
TypeParameters *TypeParameterList
9204+
Host *Node
92049205
}
92059206

92069207
func (f *NodeFactory) NewJSDocTemplateTag(tagName *IdentifierNode, constraint *Node, typeParameters *TypeParameterList, comment *NodeList) *Node {
@@ -9876,40 +9877,36 @@ func (node *JSDocTypeLiteral) Clone(f NodeFactoryCoercible) *Node {
98769877
// JSDocSignature
98779878
type JSDocSignature struct {
98789879
TypeNodeBase
9879-
typeParameters *TypeParameterList
9880-
Parameters *NodeList
9881-
Type *JSDocTag
9880+
FunctionLikeBase
98829881
}
98839882

9884-
func (f *NodeFactory) NewJSDocSignature(typeParameters *TypeParameterList, parameters *NodeList, typeNode *JSDocTag) *Node {
9883+
func (f *NodeFactory) NewJSDocSignature(typeParameters *NodeList, parameters *NodeList, typeNode *JSDocTag) *Node {
98859884
data := &JSDocSignature{}
9886-
data.typeParameters = typeParameters
9885+
data.TypeParameters = typeParameters
98879886
data.Parameters = parameters
98889887
data.Type = typeNode
98899888
return f.newNode(KindJSDocSignature, data)
98909889
}
98919890

9892-
func (f *NodeFactory) UpdateJSDocSignature(node *JSDocSignature, typeParameters *TypeParameterList, parameters *NodeList, typeNode *JSDocTag) *Node {
9893-
if typeParameters != node.typeParameters || parameters != node.Parameters || typeNode != node.Type {
9891+
func (f *NodeFactory) UpdateJSDocSignature(node *JSDocSignature, typeParameters *NodeList, parameters *NodeList, typeNode *JSDocTag) *Node {
9892+
if typeParameters != node.TypeParameters || parameters != node.Parameters || typeNode != node.Type {
98949893
return updateNode(f.NewJSDocSignature(typeParameters, parameters, typeNode), node.AsNode(), f.hooks)
98959894
}
98969895
return node.AsNode()
98979896
}
98989897

98999898
func (node *JSDocSignature) ForEachChild(v Visitor) bool {
9900-
return visitNodeList(v, node.typeParameters) || visitNodeList(v, node.Parameters) || visit(v, node.Type)
9899+
return visitNodeList(v, node.TypeParameters) || visitNodeList(v, node.Parameters) || visit(v, node.Type)
99019900
}
99029901

99039902
func (node *JSDocSignature) VisitEachChild(v *NodeVisitor) *Node {
9904-
return v.Factory.UpdateJSDocSignature(node, v.visitNodes(node.typeParameters), v.visitNodes(node.Parameters), v.visitNode(node.Type))
9903+
return v.Factory.UpdateJSDocSignature(node, v.visitNodes(node.TypeParameters), v.visitNodes(node.Parameters), v.visitNode(node.Type))
99059904
}
99069905

99079906
func (node *JSDocSignature) Clone(f NodeFactoryCoercible) *Node {
9908-
return cloneNode(f.AsNodeFactory().NewJSDocSignature(node.TypeParameters(), node.Parameters, node.Type), node.AsNode(), f.AsNodeFactory().hooks)
9907+
return cloneNode(f.AsNodeFactory().NewJSDocSignature(node.TypeParameters, node.Parameters, node.Type), node.AsNode(), f.AsNodeFactory().hooks)
99099908
}
99109909

9911-
func (node *JSDocSignature) TypeParameters() *TypeParameterList { return node.typeParameters }
9912-
99139910
// JSDocNameReference
99149911
type JSDocNameReference struct {
99159912
TypeNodeBase

internal/ast/utilities.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,11 @@ func WalkUpParenthesizedTypes(node *TypeNode) *Node {
865865
}
866866

867867
func GetEffectiveTypeParent(parent *Node) *Node {
868-
if IsInJSFile(parent) && parent.Kind == KindJSDocTypeExpression {
869-
if host := parent.AsJSDocTypeExpression().Host; host != nil {
870-
parent = host
868+
if parent != nil && IsInJSFile(parent) {
869+
if parent.Kind == KindJSDocTypeExpression && parent.AsJSDocTypeExpression().Host != nil {
870+
parent = parent.AsJSDocTypeExpression().Host
871+
} else if parent.Kind == KindJSDocTemplateTag && parent.AsJSDocTemplateTag().Host != nil {
872+
parent = parent.AsJSDocTemplateTag().Host
871873
}
872874
}
873875
return parent

internal/binder/nameresolver.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,8 @@ loop:
288288
if isSelfReferenceLocation(location, lastLocation) {
289289
lastSelfReferenceLocation = location
290290
}
291-
if location.Kind == ast.KindJSDocTypeExpression && location.AsJSDocTypeExpression().Host != nil {
292-
lastLocation = location.AsJSDocTypeExpression().Host.Type()
293-
location = location.AsJSDocTypeExpression().Host
294-
} else {
295-
lastLocation = location
296-
location = location.Parent
297-
}
291+
lastLocation = location
292+
location = ast.GetEffectiveTypeParent(location.Parent)
298293
}
299294
// We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
300295
// If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
@@ -487,6 +482,9 @@ func isTypeParameterSymbolDeclaredInContainer(symbol *ast.Symbol, container *ast
487482
for _, decl := range symbol.Declarations {
488483
if decl.Kind == ast.KindTypeParameter {
489484
parent := decl.Parent
485+
if parent.Kind == ast.KindJSDocTemplateTag {
486+
parent = parent.AsJSDocTemplateTag().Host
487+
}
490488
if parent == container {
491489
return true
492490
}

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22602,7 +22602,7 @@ func (c *Checker) getOuterTypeParametersOfClassOrInterface(symbol *ast.Symbol) [
2260222602
// Return the outer type parameters of a node or undefined if the node has no outer type parameters.
2260322603
func (c *Checker) getOuterTypeParameters(node *ast.Node, includeThisTypes bool) []*Type {
2260422604
for {
22605-
node = node.Parent
22605+
node = ast.GetEffectiveTypeParent(node.Parent)
2260622606
if node == nil {
2260722607
return nil
2260822608
}

0 commit comments

Comments
 (0)