@@ -1040,6 +1040,25 @@ func IsStatic(node *Node) bool {
1040
1040
return IsClassElement (node ) && HasStaticModifier (node ) || IsClassStaticBlockDeclaration (node )
1041
1041
}
1042
1042
1043
+ func CanHaveSymbol (node * Node ) bool {
1044
+ switch node .Kind {
1045
+ case KindArrowFunction , KindBinaryExpression , KindBindingElement , KindCallExpression , KindCallSignature ,
1046
+ KindClassDeclaration , KindClassExpression , KindClassStaticBlockDeclaration , KindConstructor , KindConstructorType ,
1047
+ KindConstructSignature , KindElementAccessExpression , KindEnumDeclaration , KindEnumMember , KindExportAssignment ,
1048
+ KindExportDeclaration , KindExportSpecifier , KindFunctionDeclaration , KindFunctionExpression , KindFunctionType ,
1049
+ KindGetAccessor , KindImportClause , KindImportEqualsDeclaration , KindImportSpecifier , KindIndexSignature ,
1050
+ KindInterfaceDeclaration , KindJSExportAssignment , KindJSTypeAliasDeclaration , KindCommonJSExport ,
1051
+ KindJsxAttribute , KindJsxAttributes , KindJsxSpreadAttribute , KindMappedType , KindMethodDeclaration ,
1052
+ KindMethodSignature , KindModuleDeclaration , KindNamedTupleMember , KindNamespaceExport , KindNamespaceExportDeclaration ,
1053
+ KindNamespaceImport , KindNewExpression , KindNoSubstitutionTemplateLiteral , KindNumericLiteral , KindObjectLiteralExpression ,
1054
+ KindParameter , KindPropertyAccessExpression , KindPropertyAssignment , KindPropertyDeclaration , KindPropertySignature ,
1055
+ KindSetAccessor , KindShorthandPropertyAssignment , KindSourceFile , KindSpreadAssignment , KindStringLiteral ,
1056
+ KindTypeAliasDeclaration , KindTypeLiteral , KindTypeParameter , KindVariableDeclaration :
1057
+ return true
1058
+ }
1059
+ return false
1060
+ }
1061
+
1043
1062
func CanHaveIllegalDecorators (node * Node ) bool {
1044
1063
switch node .Kind {
1045
1064
case KindPropertyAssignment , KindShorthandPropertyAssignment ,
@@ -1260,6 +1279,10 @@ func IsExternalModuleImportEqualsDeclaration(node *Node) bool {
1260
1279
return node .Kind == KindImportEqualsDeclaration && node .AsImportEqualsDeclaration ().ModuleReference .Kind == KindExternalModuleReference
1261
1280
}
1262
1281
1282
+ func IsModuleOrEnumDeclaration (node * Node ) bool {
1283
+ return node .Kind == KindModuleDeclaration || node .Kind == KindEnumDeclaration
1284
+ }
1285
+
1263
1286
func IsLiteralImportTypeNode (node * Node ) bool {
1264
1287
return IsImportTypeNode (node ) && IsLiteralTypeNode (node .AsImportTypeNode ().Argument ) && IsStringLiteral (node .AsImportTypeNode ().Argument .AsLiteralTypeNode ().Literal )
1265
1288
}
@@ -1301,6 +1324,27 @@ func IsThisParameter(node *Node) bool {
1301
1324
return IsParameter (node ) && node .Name () != nil && IsThisIdentifier (node .Name ())
1302
1325
}
1303
1326
1327
+ func IsBindableStaticAccessExpression (node * Node , excludeThisKeyword bool ) bool {
1328
+ return IsPropertyAccessExpression (node ) &&
1329
+ (! excludeThisKeyword && node .Expression ().Kind == KindThisKeyword || IsIdentifier (node .Name ()) && IsBindableStaticNameExpression (node .Expression () /*excludeThisKeyword*/ , true )) ||
1330
+ IsBindableStaticElementAccessExpression (node , excludeThisKeyword )
1331
+ }
1332
+
1333
+ func IsBindableStaticElementAccessExpression (node * Node , excludeThisKeyword bool ) bool {
1334
+ return IsLiteralLikeElementAccess (node ) &&
1335
+ ((! excludeThisKeyword && node .Expression ().Kind == KindThisKeyword ) ||
1336
+ IsEntityNameExpression (node .Expression ()) ||
1337
+ IsBindableStaticAccessExpression (node .Expression () /*excludeThisKeyword*/ , true ))
1338
+ }
1339
+
1340
+ func IsLiteralLikeElementAccess (node * Node ) bool {
1341
+ return IsElementAccessExpression (node ) && IsStringOrNumericLiteralLike (node .AsElementAccessExpression ().ArgumentExpression )
1342
+ }
1343
+
1344
+ func IsBindableStaticNameExpression (node * Node , excludeThisKeyword bool ) bool {
1345
+ return IsEntityNameExpression (node ) || IsBindableStaticAccessExpression (node , excludeThisKeyword )
1346
+ }
1347
+
1304
1348
// Does not handle signed numeric names like `a[+0]` - handling those would require handling prefix unary expressions
1305
1349
// throughout late binding handling as well, which is awkward (but ultimately probably doable if there is demand)
1306
1350
func GetElementOrPropertyAccessName (node * Node ) * Node {
@@ -1319,6 +1363,13 @@ func GetElementOrPropertyAccessName(node *Node) *Node {
1319
1363
panic ("Unhandled case in GetElementOrPropertyAccessName" )
1320
1364
}
1321
1365
1366
+ func GetInitializerOfBinaryExpression (expr * BinaryExpression ) * Expression {
1367
+ for IsBinaryExpression (expr .Right ) {
1368
+ expr = expr .Right .AsBinaryExpression ()
1369
+ }
1370
+ return expr .Right .Expression ()
1371
+ }
1372
+
1322
1373
func IsExpressionWithTypeArgumentsInClassExtendsClause (node * Node ) bool {
1323
1374
return TryGetClassExtendingExpressionWithTypeArguments (node ) != nil
1324
1375
}
@@ -1662,6 +1713,40 @@ func GetThisContainer(node *Node, includeArrowFunctions bool, includeClassComput
1662
1713
}
1663
1714
}
1664
1715
1716
+ func GetSuperContainer (node * Node , stopOnFunctions bool ) * Node {
1717
+ for {
1718
+ node = node .Parent
1719
+ if node == nil {
1720
+ return nil
1721
+ }
1722
+ switch node .Kind {
1723
+ case KindComputedPropertyName :
1724
+ node = node .Parent
1725
+ break
1726
+ case KindFunctionDeclaration , KindFunctionExpression , KindArrowFunction :
1727
+ if ! stopOnFunctions {
1728
+ continue
1729
+ }
1730
+ // falls through
1731
+
1732
+ case KindPropertyDeclaration , KindPropertySignature , KindMethodDeclaration , KindMethodSignature , KindConstructor , KindGetAccessor , KindSetAccessor , KindClassStaticBlockDeclaration :
1733
+ return node
1734
+ case KindDecorator :
1735
+ // Decorators are always applied outside of the body of a class or method.
1736
+ if node .Parent .Kind == KindParameter && IsClassElement (node .Parent .Parent ) {
1737
+ // If the decorator's parent is a Parameter, we resolve the this container from
1738
+ // the grandparent class declaration.
1739
+ node = node .Parent .Parent
1740
+ } else if IsClassElement (node .Parent ) {
1741
+ // If the decorator's parent is a class element, we resolve the 'this' container
1742
+ // from the parent class declaration.
1743
+ node = node .Parent
1744
+ }
1745
+ break
1746
+ }
1747
+ }
1748
+ }
1749
+
1665
1750
func GetImmediatelyInvokedFunctionExpression (fn * Node ) * Node {
1666
1751
if IsFunctionExpressionOrArrowFunction (fn ) {
1667
1752
prev := fn
@@ -1770,13 +1855,13 @@ func IsExpressionNode(node *Node) bool {
1770
1855
for node .Parent .Kind == KindQualifiedName {
1771
1856
node = node .Parent
1772
1857
}
1773
- return IsTypeQueryNode (node .Parent ) || isJSDocLinkLike (node .Parent ) || isJSXTagName (node )
1858
+ return IsTypeQueryNode (node .Parent ) || IsJSDocLinkLike (node .Parent ) || isJSXTagName (node )
1774
1859
case KindJSDocMemberName :
1775
- return IsTypeQueryNode (node .Parent ) || isJSDocLinkLike (node .Parent ) || isJSXTagName (node )
1860
+ return IsTypeQueryNode (node .Parent ) || IsJSDocLinkLike (node .Parent ) || isJSXTagName (node )
1776
1861
case KindPrivateIdentifier :
1777
1862
return IsBinaryExpression (node .Parent ) && node .Parent .AsBinaryExpression ().Left == node && node .Parent .AsBinaryExpression ().OperatorToken .Kind == KindInKeyword
1778
1863
case KindIdentifier :
1779
- if IsTypeQueryNode (node .Parent ) || isJSDocLinkLike (node .Parent ) || isJSXTagName (node ) {
1864
+ if IsTypeQueryNode (node .Parent ) || IsJSDocLinkLike (node .Parent ) || isJSXTagName (node ) {
1780
1865
return true
1781
1866
}
1782
1867
fallthrough
@@ -1919,7 +2004,7 @@ func isPartOfTypeExpressionWithTypeArguments(node *Node) bool {
1919
2004
return IsHeritageClause (parent ) && (! IsClassLike (parent .Parent ) || parent .AsHeritageClause ().Token == KindImplementsKeyword )
1920
2005
}
1921
2006
1922
- func isJSDocLinkLike (node * Node ) bool {
2007
+ func IsJSDocLinkLike (node * Node ) bool {
1923
2008
return NodeKindIs (node , KindJSDocLink , KindJSDocLinkCode , KindJSDocLinkPlain )
1924
2009
}
1925
2010
@@ -1985,7 +2070,7 @@ func IsJSDocCommentContainingNode(node *Node) bool {
1985
2070
node .Kind == KindJSDocText ||
1986
2071
node .Kind == KindJSDocTypeLiteral ||
1987
2072
node .Kind == KindJSDocSignature ||
1988
- isJSDocLinkLike (node ) ||
2073
+ IsJSDocLinkLike (node ) ||
1989
2074
IsJSDocTag (node )
1990
2075
}
1991
2076
@@ -3455,25 +3540,6 @@ func IsCallOrNewExpression(node *Node) bool {
3455
3540
return IsCallExpression (node ) || IsNewExpression (node )
3456
3541
}
3457
3542
3458
- func CanHaveSymbol (node * Node ) bool {
3459
- switch node .Kind {
3460
- case KindArrowFunction , KindBinaryExpression , KindBindingElement , KindCallExpression , KindCallSignature ,
3461
- KindClassDeclaration , KindClassExpression , KindClassStaticBlockDeclaration , KindConstructor , KindConstructorType ,
3462
- KindConstructSignature , KindElementAccessExpression , KindEnumDeclaration , KindEnumMember , KindExportAssignment , KindJSExportAssignment ,
3463
- KindExportDeclaration , KindExportSpecifier , KindFunctionDeclaration , KindFunctionExpression , KindFunctionType ,
3464
- KindGetAccessor , KindIdentifier , KindImportClause , KindImportEqualsDeclaration , KindImportSpecifier ,
3465
- KindIndexSignature , KindInterfaceDeclaration , KindJSDocSignature , KindJSDocTypeLiteral ,
3466
- KindJsxAttribute , KindJsxAttributes , KindJsxSpreadAttribute , KindMappedType , KindMethodDeclaration ,
3467
- KindMethodSignature , KindModuleDeclaration , KindNamedTupleMember , KindNamespaceExport , KindNamespaceExportDeclaration ,
3468
- KindNamespaceImport , KindNewExpression , KindNoSubstitutionTemplateLiteral , KindNumericLiteral , KindObjectLiteralExpression ,
3469
- KindParameter , KindPropertyAccessExpression , KindPropertyAssignment , KindPropertyDeclaration , KindPropertySignature ,
3470
- KindSetAccessor , KindShorthandPropertyAssignment , KindSourceFile , KindSpreadAssignment , KindStringLiteral ,
3471
- KindTypeAliasDeclaration , KindJSTypeAliasDeclaration , KindTypeLiteral , KindTypeParameter , KindVariableDeclaration :
3472
- return true
3473
- }
3474
- return false
3475
- }
3476
-
3477
3543
func IndexOfNode (nodes []* Node , node * Node ) int {
3478
3544
index , ok := slices .BinarySearchFunc (nodes , node , compareNodePositions )
3479
3545
if ok {
0 commit comments