Skip to content
Draft
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
16 changes: 15 additions & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3885,7 +3885,21 @@ func IsExpandoInitializer(initializer *Node) bool {
}

func GetContainingFunction(node *Node) *Node {
return FindAncestor(node.Parent, IsFunctionLike)
node = node.Parent
for node != nil {
if node.Kind == KindComputedPropertyName {
if node.Parent != nil && node.Parent.Parent != nil {
node = node.Parent.Parent
continue
}
return nil
}
if IsFunctionLike(node) {
return node
}
node = node.Parent
}
return nil
}

func IsImplicitlyExportedJSTypeAlias(node *Node) bool {
Expand Down
37 changes: 36 additions & 1 deletion internal/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,42 @@ func (s *orderedSet[T]) add(value T) {
}

func getContainingFunctionOrClassStaticBlock(node *ast.Node) *ast.Node {
return ast.FindAncestor(node.Parent, ast.IsFunctionLikeOrClassStaticBlockDeclaration)
node = node.Parent
for node != nil {
if node.Kind == ast.KindComputedPropertyName {
if node.Parent != nil && node.Parent.Parent != nil {
node = node.Parent.Parent
continue
}
return nil
}
if ast.IsFunctionLikeOrClassStaticBlockDeclaration(node) {
return node
}
node = node.Parent
}
return nil
}

func getContainingClassStaticBlock(node *ast.Node) *ast.Node {
node = node.Parent
for node != nil {
if node.Kind == ast.KindComputedPropertyName {
if node.Parent != nil && node.Parent.Parent != nil {
node = node.Parent.Parent
continue
}
return nil
}
if ast.IsClassLike(node) || ast.IsFunctionLike(node) {
return nil
}
if ast.IsClassStaticBlockDeclaration(node) {
return node
}
node = node.Parent
}
return nil
}

func isNodeDescendantOf(node *ast.Node, ancestor *ast.Node) bool {
Expand Down