diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 6338dedc58..a313d72df8 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -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 { diff --git a/internal/checker/utilities.go b/internal/checker/utilities.go index 6fdedd0a91..d151e6d0b2 100644 --- a/internal/checker/utilities.go +++ b/internal/checker/utilities.go @@ -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 {