Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
45 changes: 44 additions & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,49 @@ func isDeclarationStatementKind(kind Kind) bool {
return false
}

func isDeclarationKind(kind Kind) bool {
switch kind {
case KindArrowFunction,
KindBindingElement,
KindClassDeclaration,
KindClassExpression,
KindClassStaticBlockDeclaration,
KindConstructor,
KindEnumDeclaration,
KindEnumMember,
KindExportSpecifier,
KindFunctionDeclaration,
KindFunctionExpression,
KindGetAccessor,
KindImportClause,
KindImportEqualsDeclaration,
KindImportSpecifier,
KindInterfaceDeclaration,
KindJsxAttribute,
KindMethodDeclaration,
KindMethodSignature,
KindModuleDeclaration,
KindNamespaceExportDeclaration,
KindNamespaceExport,
KindNamespaceImport,
KindParameter,
KindPropertyAssignment,
KindPropertyDeclaration,
KindPropertySignature,
KindSetAccessor,
KindShorthandPropertyAssignment,
KindTypeAliasDeclaration,
KindTypeParameter,
KindVariableDeclaration,
KindJSDocTypedefTag,
KindJSDocCallbackTag,
KindJSDocPropertyTag,
KindNamedTupleMember:
return true
}
return false
}

// Determines whether a node is a DeclarationStatement. Ideally this does not use Parent pointers, but it may use them
// to rule out a Block node that is part of `try` or `catch` or is the Block-like body of a function.
//
Expand Down Expand Up @@ -1265,7 +1308,7 @@ func IsDeclaration(node *Node) bool {
if node.Kind == KindTypeParameter {
return node.Parent != nil
}
return IsDeclarationNode(node)
return isDeclarationKind(node.Kind)
}

// True if `name` is the name of a declaration node
Expand Down
Loading
Loading