@@ -2134,7 +2134,6 @@ module ts {
2134
2134
return result ;
2135
2135
}
2136
2136
2137
- /// Find references
2138
2137
function getOccurrencesAtPosition ( filename : string , position : number ) : ReferenceEntry [ ] {
2139
2138
synchronizeHostData ( ) ;
2140
2139
@@ -2404,8 +2403,12 @@ module ts {
2404
2403
}
2405
2404
}
2406
2405
2407
- if ( node . kind === SyntaxKind . ThisKeyword || node . kind === SyntaxKind . SuperKeyword ) {
2408
- return getReferencesForThisOrSuperKeyword ( node , sourceFiles ) ;
2406
+ if ( node . kind === SyntaxKind . ThisKeyword ) {
2407
+ return getReferencesForThisKeyword ( node , sourceFiles ) ;
2408
+ }
2409
+
2410
+ if ( node . kind === SyntaxKind . SuperKeyword ) {
2411
+ return getReferencesForSuperKeyword ( node ) ;
2409
2412
}
2410
2413
2411
2414
var symbol = typeInfoResolver . getSymbolInfo ( node ) ;
@@ -2629,24 +2632,57 @@ module ts {
2629
2632
}
2630
2633
}
2631
2634
2632
- function getReferencesForThisOrSuperKeyword ( thisOrSuperKeyword : Node , sourceFiles : SourceFile [ ] ) : ReferenceEntry [ ] {
2633
- var keywordName : string ;
2634
- var searchSpaceNode : Node ;
2635
-
2636
- if ( thisOrSuperKeyword . kind === SyntaxKind . ThisKeyword ) {
2637
- keywordName = "this"
2638
- searchSpaceNode = getThisContainer ( thisOrSuperKeyword , /* includeArrowFunctions */ false ) ;
2635
+ function getReferencesForSuperKeyword ( superKeyword : Node ) : ReferenceEntry [ ] {
2636
+ var searchSpaceNode = getSuperContainer ( superKeyword ) ;
2637
+ if ( ! searchSpaceNode ) {
2638
+ return undefined ;
2639
2639
}
2640
- else {
2641
- keywordName = "super" ;
2642
- searchSpaceNode = getSuperContainer ( thisOrSuperKeyword ) ;
2640
+ // Whether 'super' occurs in a static context within a class.
2641
+ var staticFlag = NodeFlags . Static ;
2643
2642
2644
- if ( ! searchSpaceNode ) {
2643
+ switch ( searchSpaceNode . kind ) {
2644
+ case SyntaxKind . Property :
2645
+ case SyntaxKind . Method :
2646
+ case SyntaxKind . Constructor :
2647
+ case SyntaxKind . GetAccessor :
2648
+ case SyntaxKind . SetAccessor :
2649
+ staticFlag &= searchSpaceNode . flags ;
2650
+ searchSpaceNode = searchSpaceNode . parent ; // re-assign to be the owning class
2651
+ break ;
2652
+ default :
2645
2653
return undefined ;
2646
- }
2647
2654
}
2648
2655
2649
- // Whether 'this'/'super' occurs in a static context within a class.
2656
+ var result : ReferenceEntry [ ] = [ ] ;
2657
+
2658
+ var sourceFile = searchSpaceNode . getSourceFile ( ) ;
2659
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "super" , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
2660
+ forEach ( possiblePositions , position => {
2661
+ cancellationToken . throwIfCancellationRequested ( ) ;
2662
+
2663
+ var node = getNodeAtPosition ( sourceFile , position ) ;
2664
+
2665
+ if ( ! node || node . kind !== SyntaxKind . SuperKeyword ) {
2666
+ return ;
2667
+ }
2668
+
2669
+ var container = getSuperContainer ( node ) ;
2670
+
2671
+ // If we have a 'super' container, we must have an enclosing class.
2672
+ // Now make sure the owning class is the same as the search-space
2673
+ // and has the same static qualifier as the original 'super's owner.
2674
+ if ( container && ( NodeFlags . Static & container . flags ) === staticFlag && container . parent . symbol === searchSpaceNode . symbol ) {
2675
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2676
+ }
2677
+ } ) ;
2678
+
2679
+ return result ;
2680
+ }
2681
+
2682
+ function getReferencesForThisKeyword ( thisOrSuperKeyword : Node , sourceFiles : SourceFile [ ] ) : ReferenceEntry [ ] {
2683
+ var searchSpaceNode = getThisContainer ( thisOrSuperKeyword , /* includeArrowFunctions */ false ) ;
2684
+
2685
+ // Whether 'this' occurs in a static context within a class.
2650
2686
var staticFlag = NodeFlags . Static ;
2651
2687
2652
2688
switch ( searchSpaceNode . kind ) {
@@ -2662,13 +2698,9 @@ module ts {
2662
2698
if ( isExternalModule ( < SourceFile > searchSpaceNode ) ) {
2663
2699
return undefined ;
2664
2700
}
2665
- break ;
2701
+ // Fall through
2666
2702
case SyntaxKind . FunctionDeclaration :
2667
2703
case SyntaxKind . FunctionExpression :
2668
- // 'super' can only occur within a class.
2669
- if ( thisOrSuperKeyword . kind === SyntaxKind . SuperKeyword ) {
2670
- return undefined ;
2671
- }
2672
2704
break ;
2673
2705
default :
2674
2706
return undefined ;
@@ -2678,60 +2710,48 @@ module ts {
2678
2710
2679
2711
if ( searchSpaceNode . kind === SyntaxKind . SourceFile ) {
2680
2712
forEach ( sourceFiles , sourceFile => {
2681
- var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , keywordName , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
2682
- getThisOrSuperReferencesInFile ( sourceFile , sourceFile , possiblePositions , result ) ;
2713
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
2714
+ getThisReferencesInFile ( sourceFile , sourceFile , possiblePositions , result ) ;
2683
2715
} ) ;
2684
2716
}
2685
2717
else {
2686
2718
var sourceFile = searchSpaceNode . getSourceFile ( ) ;
2687
- var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , keywordName , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
2688
- getThisOrSuperReferencesInFile ( sourceFile , searchSpaceNode , possiblePositions , result ) ;
2719
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
2720
+ getThisReferencesInFile ( sourceFile , searchSpaceNode , possiblePositions , result ) ;
2689
2721
}
2690
2722
2691
2723
return result ;
2692
2724
2693
- function getThisOrSuperReferencesInFile ( sourceFile : SourceFile , searchSpaceNode : Node , possiblePositions : number [ ] , result : ReferenceEntry [ ] ) : void {
2725
+ function getThisReferencesInFile ( sourceFile : SourceFile , searchSpaceNode : Node , possiblePositions : number [ ] , result : ReferenceEntry [ ] ) : void {
2694
2726
forEach ( possiblePositions , position => {
2695
2727
cancellationToken . throwIfCancellationRequested ( ) ;
2696
2728
2697
2729
var node = getNodeAtPosition ( sourceFile , position ) ;
2698
- if ( ! node ) {
2730
+ if ( ! node || node . kind !== SyntaxKind . ThisKeyword ) {
2699
2731
return ;
2700
2732
}
2701
2733
2702
- var container = getNodeAtPosition ( sourceFile , position ) ;
2703
- if ( ! container ) {
2704
- return ;
2705
- }
2706
-
2707
- if ( node . kind === SyntaxKind . SuperKeyword ) {
2708
- container = getSuperContainer ( node ) ;
2709
- }
2710
- else if ( node . kind === SyntaxKind . ThisKeyword ) {
2711
- container = getThisContainer ( node , /* includeArrowFunctions */ false ) ;
2712
- }
2734
+ var container = getThisContainer ( node , /* includeArrowFunctions */ false ) ;
2713
2735
2714
- if ( container ) {
2715
- switch ( searchSpaceNode . kind ) {
2716
- case SyntaxKind . FunctionExpression :
2717
- case SyntaxKind . FunctionDeclaration :
2718
- if ( searchSpaceNode . symbol === container . symbol ) {
2719
- result . push ( getReferenceEntryFromNode ( node ) ) ;
2720
- }
2721
- break ;
2722
- case SyntaxKind . ClassDeclaration :
2723
- // Make sure the container belongs to the same class
2724
- // and has the appropriate static modifier from the original container.
2725
- if ( container . parent && searchSpaceNode . symbol === container . parent . symbol && ( container . flags & NodeFlags . Static ) === staticFlag ) {
2726
- result . push ( getReferenceEntryFromNode ( node ) ) ;
2727
- }
2728
- break ;
2729
- case SyntaxKind . SourceFile :
2730
- if ( container . kind === SyntaxKind . SourceFile && ! isExternalModule ( < SourceFile > container ) ) {
2731
- result . push ( getReferenceEntryFromNode ( node ) ) ;
2732
- }
2733
- break ;
2734
- }
2736
+ switch ( searchSpaceNode . kind ) {
2737
+ case SyntaxKind . FunctionExpression :
2738
+ case SyntaxKind . FunctionDeclaration :
2739
+ if ( searchSpaceNode . symbol === container . symbol ) {
2740
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2741
+ }
2742
+ break ;
2743
+ case SyntaxKind . ClassDeclaration :
2744
+ // Make sure the container belongs to the same class
2745
+ // and has the appropriate static modifier from the original container.
2746
+ if ( container . parent && searchSpaceNode . symbol === container . parent . symbol && ( container . flags & NodeFlags . Static ) === staticFlag ) {
2747
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2748
+ }
2749
+ break ;
2750
+ case SyntaxKind . SourceFile :
2751
+ if ( container . kind === SyntaxKind . SourceFile && ! isExternalModule ( < SourceFile > container ) ) {
2752
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2753
+ }
2754
+ break ;
2735
2755
}
2736
2756
} ) ;
2737
2757
}
0 commit comments