@@ -510,7 +510,7 @@ func IsFunctionLikeDeclaration(node *Node) bool {
510
510
return node != nil && isFunctionLikeDeclarationKind (node .Kind )
511
511
}
512
512
513
- func isFunctionLikeKind (kind Kind ) bool {
513
+ func IsFunctionLikeKind (kind Kind ) bool {
514
514
switch kind {
515
515
case KindMethodSignature ,
516
516
KindCallSignature ,
@@ -527,7 +527,7 @@ func isFunctionLikeKind(kind Kind) bool {
527
527
// Determines if a node is function- or signature-like.
528
528
func IsFunctionLike (node * Node ) bool {
529
529
// TODO(rbuckton): Move `node != nil` test to call sites
530
- return node != nil && isFunctionLikeKind (node .Kind )
530
+ return node != nil && IsFunctionLikeKind (node .Kind )
531
531
}
532
532
533
533
func IsFunctionLikeOrClassStaticBlockDeclaration (node * Node ) bool {
@@ -927,6 +927,13 @@ const (
927
927
FindAncestorQuit
928
928
)
929
929
930
+ func ToFindAncestorResult (b bool ) FindAncestorResult {
931
+ if b {
932
+ return FindAncestorTrue
933
+ }
934
+ return FindAncestorFalse
935
+ }
936
+
930
937
// Walks up the parents of a node to find the ancestor that matches the callback
931
938
func FindAncestorOrQuit (node * Node , callback func (* Node ) FindAncestorResult ) * Node {
932
939
for node != nil {
@@ -1966,6 +1973,7 @@ func TryGetTextOfPropertyName(name *Node) (string, bool) {
1966
1973
return "" , false
1967
1974
}
1968
1975
1976
+ // True if node is of a JSDoc kind that may contain comment text.
1969
1977
func IsJSDocCommentContainingNode (node * Node ) bool {
1970
1978
return node .Kind == KindJSDoc ||
1971
1979
node .Kind == KindJSDocText ||
@@ -2651,3 +2659,127 @@ func GetPragmaArgument(pragma *Pragma, name string) string {
2651
2659
}
2652
2660
return ""
2653
2661
}
2662
+
2663
+ func IsCheckJSEnabledForFile (sourceFile * SourceFile , compilerOptions * core.CompilerOptions ) bool {
2664
+ if sourceFile .CheckJsDirective != nil {
2665
+ return sourceFile .CheckJsDirective .Enabled
2666
+ }
2667
+ return compilerOptions .CheckJs == core .TSTrue
2668
+ }
2669
+
2670
+ func GetLeftmostAccessExpression (expr * Node ) * Node {
2671
+ for IsAccessExpression (expr ) {
2672
+ expr = expr .Expression ()
2673
+ }
2674
+ return expr
2675
+ }
2676
+
2677
+ func IsTypeOnlyImportDeclaration (node * Node ) bool {
2678
+ switch node .Kind {
2679
+ case KindImportSpecifier :
2680
+ return node .AsImportSpecifier ().IsTypeOnly || node .Parent .Parent .AsImportClause ().IsTypeOnly
2681
+ case KindNamespaceImport :
2682
+ return node .Parent .AsImportClause ().IsTypeOnly
2683
+ case KindImportClause :
2684
+ return node .AsImportClause ().IsTypeOnly
2685
+ case KindImportEqualsDeclaration :
2686
+ return node .AsImportEqualsDeclaration ().IsTypeOnly
2687
+ }
2688
+ return false
2689
+ }
2690
+
2691
+ func isTypeOnlyExportDeclaration (node * Node ) bool {
2692
+ switch node .Kind {
2693
+ case KindExportSpecifier :
2694
+ return node .AsExportSpecifier ().IsTypeOnly || node .Parent .Parent .AsExportDeclaration ().IsTypeOnly
2695
+ case KindExportDeclaration :
2696
+ d := node .AsExportDeclaration ()
2697
+ return d .IsTypeOnly && d .ModuleSpecifier != nil && d .ExportClause == nil
2698
+ case KindNamespaceExport :
2699
+ return node .Parent .AsExportDeclaration ().IsTypeOnly
2700
+ }
2701
+ return false
2702
+ }
2703
+
2704
+ func IsTypeOnlyImportOrExportDeclaration (node * Node ) bool {
2705
+ return IsTypeOnlyImportDeclaration (node ) || isTypeOnlyExportDeclaration (node )
2706
+ }
2707
+
2708
+ func GetSourceFileOfModule (module * Symbol ) * SourceFile {
2709
+ declaration := module .ValueDeclaration
2710
+ if declaration == nil {
2711
+ declaration = getNonAugmentationDeclaration (module )
2712
+ }
2713
+ return GetSourceFileOfNode (declaration )
2714
+ }
2715
+
2716
+ func getNonAugmentationDeclaration (symbol * Symbol ) * Node {
2717
+ return core .Find (symbol .Declarations , func (d * Node ) bool {
2718
+ return ! IsExternalModuleAugmentation (d ) && ! IsGlobalScopeAugmentation (d )
2719
+ })
2720
+ }
2721
+
2722
+ func IsExternalModuleAugmentation (node * Node ) bool {
2723
+ return IsAmbientModule (node ) && IsModuleAugmentationExternal (node )
2724
+ }
2725
+
2726
+ func GetClassLikeDeclarationOfSymbol (symbol * Symbol ) * Node {
2727
+ return core .Find (symbol .Declarations , IsClassLike )
2728
+ }
2729
+
2730
+ func GetLanguageVariant (scriptKind core.ScriptKind ) core.LanguageVariant {
2731
+ switch scriptKind {
2732
+ case core .ScriptKindTSX , core .ScriptKindJSX , core .ScriptKindJS , core .ScriptKindJSON :
2733
+ // .tsx and .jsx files are treated as jsx language variant.
2734
+ return core .LanguageVariantJSX
2735
+ }
2736
+ return core .LanguageVariantStandard
2737
+ }
2738
+
2739
+ func IsCallLikeExpression (node * Node ) bool {
2740
+ switch node .Kind {
2741
+ case KindJsxOpeningElement , KindJsxSelfClosingElement , KindCallExpression , KindNewExpression ,
2742
+ KindTaggedTemplateExpression , KindDecorator :
2743
+ return true
2744
+ }
2745
+ return false
2746
+ }
2747
+
2748
+ func IsCallLikeOrFunctionLikeExpression (node * Node ) bool {
2749
+ return IsCallLikeExpression (node ) || IsFunctionExpressionOrArrowFunction (node )
2750
+ }
2751
+
2752
+ func NodeHasKind (node * Node , kind Kind ) bool {
2753
+ if node == nil {
2754
+ return false
2755
+ }
2756
+ return node .Kind == kind
2757
+ }
2758
+
2759
+ func IsContextualKeyword (token Kind ) bool {
2760
+ return KindFirstContextualKeyword <= token && token <= KindLastContextualKeyword
2761
+ }
2762
+
2763
+ func IsThisInTypeQuery (node * Node ) bool {
2764
+ if ! IsThisIdentifier (node ) {
2765
+ return false
2766
+ }
2767
+ for IsQualifiedName (node .Parent ) && node .Parent .AsQualifiedName ().Left == node {
2768
+ node = node .Parent
2769
+ }
2770
+ return node .Parent .Kind == KindTypeQuery
2771
+ }
2772
+
2773
+ // Gets whether a bound `VariableDeclaration` or `VariableDeclarationList` is part of a `let` declaration.
2774
+ func IsLet (node * Node ) bool {
2775
+ return GetCombinedNodeFlags (node )& NodeFlagsBlockScoped == NodeFlagsLet
2776
+ }
2777
+
2778
+ func IsClassMemberModifier (token Kind ) bool {
2779
+ return IsParameterPropertyModifier (token ) || token == KindStaticKeyword ||
2780
+ token == KindOverrideKeyword || token == KindAccessorKeyword
2781
+ }
2782
+
2783
+ func IsParameterPropertyModifier (kind Kind ) bool {
2784
+ return ModifierToFlag (kind )& ModifierFlagsParameterPropertyModifier != 0
2785
+ }
0 commit comments