@@ -1948,7 +1948,10 @@ func IsComputedNonLiteralName(name *Node) bool {
1948
1948
}
1949
1949
1950
1950
func IsQuestionToken (node * Node ) bool {
1951
- return node != nil && node .Kind == KindQuestionToken
1951
+ if node == nil {
1952
+ return false
1953
+ }
1954
+ return node .Kind == KindQuestionToken
1952
1955
}
1953
1956
1954
1957
func GetTextOfPropertyName (name * Node ) string {
@@ -2403,7 +2406,7 @@ func GetImpliedNodeFormatForFile(path string, packageJsonType string) core.Modul
2403
2406
impliedNodeFormat = core .ResolutionModeESM
2404
2407
} else if tspath .FileExtensionIsOneOf (path , []string {tspath .ExtensionDcts , tspath .ExtensionCts , tspath .ExtensionCjs }) {
2405
2408
impliedNodeFormat = core .ResolutionModeCommonJS
2406
- } else if packageJsonType != "" && tspath .FileExtensionIsOneOf (path , []string {tspath .ExtensionDts , tspath .ExtensionTs , tspath .ExtensionTsx , tspath .ExtensionJs , tspath .ExtensionJsx }) {
2409
+ } else if tspath .FileExtensionIsOneOf (path , []string {tspath .ExtensionDts , tspath .ExtensionTs , tspath .ExtensionTsx , tspath .ExtensionJs , tspath .ExtensionJsx }) {
2407
2410
impliedNodeFormat = core .IfElse (packageJsonType == "module" , core .ResolutionModeESM , core .ResolutionModeCommonJS )
2408
2411
}
2409
2412
@@ -2739,6 +2742,22 @@ func IsTypeOnlyImportOrExportDeclaration(node *Node) bool {
2739
2742
return IsTypeOnlyImportDeclaration (node ) || isTypeOnlyExportDeclaration (node )
2740
2743
}
2741
2744
2745
+ func IsExclusivelyTypeOnlyImportOrExport (node * Node ) bool {
2746
+ switch node .Kind {
2747
+ case KindExportDeclaration :
2748
+ return node .AsExportDeclaration ().IsTypeOnly
2749
+ case KindImportDeclaration , KindJSImportDeclaration :
2750
+ if importClause := node .AsImportDeclaration ().ImportClause ; importClause != nil {
2751
+ return importClause .AsImportClause ().IsTypeOnly
2752
+ }
2753
+ case KindJSDocImportTag :
2754
+ if importClause := node .AsJSDocImportTag ().ImportClause ; importClause != nil {
2755
+ return importClause .AsImportClause ().IsTypeOnly
2756
+ }
2757
+ }
2758
+ return false
2759
+ }
2760
+
2742
2761
func GetClassLikeDeclarationOfSymbol (symbol * Symbol ) * Node {
2743
2762
return core .Find (symbol .Declarations , IsClassLike )
2744
2763
}
@@ -2941,6 +2960,59 @@ func GetPropertyNameForPropertyNameNode(name *Node) string {
2941
2960
panic ("Unhandled case in getPropertyNameForPropertyNameNode" )
2942
2961
}
2943
2962
2963
+ func IsPartOfTypeOnlyImportOrExportDeclaration (node * Node ) bool {
2964
+ return FindAncestor (node , IsTypeOnlyImportOrExportDeclaration ) != nil
2965
+ }
2966
+
2967
+ func IsPartOfExclusivelyTypeOnlyImportOrExportDeclaration (node * Node ) bool {
2968
+ return FindAncestor (node , IsExclusivelyTypeOnlyImportOrExport ) != nil
2969
+ }
2970
+
2971
+ func IsEmittableImport (node * Node ) bool {
2972
+ switch node .Kind {
2973
+ case KindImportDeclaration :
2974
+ return node .AsImportDeclaration ().ImportClause == nil || ! node .AsImportDeclaration ().ImportClause .IsTypeOnly ()
2975
+ case KindExportDeclaration :
2976
+ return ! node .AsExportDeclaration ().IsTypeOnly
2977
+ case KindImportEqualsDeclaration :
2978
+ return ! node .AsImportEqualsDeclaration ().IsTypeOnly
2979
+ case KindCallExpression :
2980
+ return IsImportCall (node )
2981
+ }
2982
+ return false
2983
+ }
2984
+
2985
+ func IsResolutionModeOverrideHost (node * Node ) bool {
2986
+ if node == nil {
2987
+ return false
2988
+ }
2989
+ switch node .Kind {
2990
+ case KindImportType , KindExportDeclaration , KindImportDeclaration , KindJSImportDeclaration :
2991
+ return true
2992
+ }
2993
+ return false
2994
+ }
2995
+
2996
+ func HasResolutionModeOverride (node * Node ) bool {
2997
+ if node == nil {
2998
+ return false
2999
+ }
3000
+ var attributes * ImportAttributesNode
3001
+ switch node .Kind {
3002
+ case KindImportType :
3003
+ attributes = node .AsImportTypeNode ().Attributes
3004
+ case KindImportDeclaration , KindJSImportDeclaration :
3005
+ attributes = node .AsImportDeclaration ().Attributes
3006
+ case KindExportDeclaration :
3007
+ attributes = node .AsExportDeclaration ().Attributes
3008
+ }
3009
+ if attributes != nil {
3010
+ _ , ok := attributes .GetResolutionModeOverride ()
3011
+ return ok
3012
+ }
3013
+ return false
3014
+ }
3015
+
2944
3016
func IsStringTextContainingNode (node * Node ) bool {
2945
3017
return node .Kind == KindStringLiteral || IsTemplateLiteralKind (node .Kind )
2946
3018
}
@@ -3304,6 +3376,87 @@ func IsTypeDeclarationName(name *Node) bool {
3304
3376
GetNameOfDeclaration (name .Parent ) == name
3305
3377
}
3306
3378
3379
+ func IsRightSideOfQualifiedNameOrPropertyAccess (node * Node ) bool {
3380
+ parent := node .Parent
3381
+ switch parent .Kind {
3382
+ case KindQualifiedName :
3383
+ return parent .AsQualifiedName ().Right == node
3384
+ case KindPropertyAccessExpression :
3385
+ return parent .AsPropertyAccessExpression ().Name () == node
3386
+ case KindMetaProperty :
3387
+ return parent .AsMetaProperty ().Name () == node
3388
+ }
3389
+ return false
3390
+ }
3391
+
3392
+ func HasQuestionToken (node * Node ) bool {
3393
+ switch node .Kind {
3394
+ case KindParameter :
3395
+ return node .AsParameterDeclaration ().QuestionToken != nil
3396
+ case KindMethodDeclaration :
3397
+ return IsQuestionToken (node .AsMethodDeclaration ().PostfixToken )
3398
+ case KindShorthandPropertyAssignment :
3399
+ return IsQuestionToken (node .AsShorthandPropertyAssignment ().PostfixToken )
3400
+ case KindMethodSignature :
3401
+ return IsQuestionToken (node .AsMethodSignatureDeclaration ().PostfixToken )
3402
+ case KindPropertySignature :
3403
+ return IsQuestionToken (node .AsPropertySignatureDeclaration ().PostfixToken )
3404
+ case KindPropertyAssignment :
3405
+ return IsQuestionToken (node .AsPropertyAssignment ().PostfixToken )
3406
+ case KindPropertyDeclaration :
3407
+ return IsQuestionToken (node .AsPropertyDeclaration ().PostfixToken )
3408
+ }
3409
+ return false
3410
+ }
3411
+
3412
+ func GetInvokedExpression (node * Node ) * Node {
3413
+ switch node .Kind {
3414
+ case KindTaggedTemplateExpression :
3415
+ return node .AsTaggedTemplateExpression ().Tag
3416
+ case KindJsxOpeningElement , KindJsxSelfClosingElement :
3417
+ return node .TagName ()
3418
+ case KindBinaryExpression :
3419
+ return node .AsBinaryExpression ().Right
3420
+ default :
3421
+ return node .Expression ()
3422
+ }
3423
+ }
3424
+
3425
+ func IsCallOrNewExpression (node * Node ) bool {
3426
+ return IsCallExpression (node ) || IsNewExpression (node )
3427
+ }
3428
+
3429
+ func CanHaveSymbol (node * Node ) bool {
3430
+ switch node .Kind {
3431
+ case KindArrowFunction , KindBinaryExpression , KindBindingElement , KindCallExpression , KindCallSignature ,
3432
+ KindClassDeclaration , KindClassExpression , KindClassStaticBlockDeclaration , KindConstructor , KindConstructorType ,
3433
+ KindConstructSignature , KindElementAccessExpression , KindEnumDeclaration , KindEnumMember , KindExportAssignment , KindJSExportAssignment ,
3434
+ KindExportDeclaration , KindExportSpecifier , KindFunctionDeclaration , KindFunctionExpression , KindFunctionType ,
3435
+ KindGetAccessor , KindIdentifier , KindImportClause , KindImportEqualsDeclaration , KindImportSpecifier ,
3436
+ KindIndexSignature , KindInterfaceDeclaration , KindJSDocSignature , KindJSDocTypeLiteral ,
3437
+ KindJsxAttribute , KindJsxAttributes , KindJsxSpreadAttribute , KindMappedType , KindMethodDeclaration ,
3438
+ KindMethodSignature , KindModuleDeclaration , KindNamedTupleMember , KindNamespaceExport , KindNamespaceExportDeclaration ,
3439
+ KindNamespaceImport , KindNewExpression , KindNoSubstitutionTemplateLiteral , KindNumericLiteral , KindObjectLiteralExpression ,
3440
+ KindParameter , KindPropertyAccessExpression , KindPropertyAssignment , KindPropertyDeclaration , KindPropertySignature ,
3441
+ KindSetAccessor , KindShorthandPropertyAssignment , KindSourceFile , KindSpreadAssignment , KindStringLiteral ,
3442
+ KindTypeAliasDeclaration , KindJSTypeAliasDeclaration , KindTypeLiteral , KindTypeParameter , KindVariableDeclaration :
3443
+ return true
3444
+ }
3445
+ return false
3446
+ }
3447
+
3448
+ func IndexOfNode (nodes []* Node , node * Node ) int {
3449
+ index , ok := slices .BinarySearchFunc (nodes , node , compareNodePositions )
3450
+ if ok {
3451
+ return index
3452
+ }
3453
+ return - 1
3454
+ }
3455
+
3456
+ func compareNodePositions (n1 , n2 * Node ) int {
3457
+ return n1 .Pos () - n2 .Pos ()
3458
+ }
3459
+
3307
3460
func IsUnterminatedNode (node * Node ) bool {
3308
3461
return IsLiteralKind (node .Kind ) && IsUnterminatedLiteral (node )
3309
3462
}
@@ -3316,4 +3469,4 @@ func IsInitializedProperty(member *ClassElement) bool {
3316
3469
3317
3470
func IsJsxOpeningLikeElement (node * Node ) bool {
3318
3471
return IsJsxOpeningElement (node ) || IsJsxSelfClosingElement (node )
3319
- }
3472
+ }
0 commit comments