@@ -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
@@ -2146,7 +2145,7 @@ module ts {
2146
2145
return undefined ;
2147
2146
}
2148
2147
2149
- if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . ThisKeyword ||
2148
+ if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . ThisKeyword || node . kind === SyntaxKind . SuperKeyword ||
2150
2149
isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) || isNameOfExternalModuleImportOrDeclaration ( node ) ) {
2151
2150
return getReferencesForNode ( node , [ sourceFile ] ) ;
2152
2151
}
@@ -2378,7 +2377,9 @@ module ts {
2378
2377
}
2379
2378
2380
2379
if ( node . kind !== SyntaxKind . Identifier &&
2381
- node . kind !== SyntaxKind . ThisKeyword &&
2380
+ // TODO (drosen): This should be enabled in a later release - currently breaks rename.
2381
+ //node.kind !== SyntaxKind.ThisKeyword &&
2382
+ //node.kind !== SyntaxKind.SuperKeyword &&
2382
2383
! isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) &&
2383
2384
! isNameOfExternalModuleImportOrDeclaration ( node ) ) {
2384
2385
return undefined ;
@@ -2406,6 +2407,10 @@ module ts {
2406
2407
return getReferencesForThisKeyword ( node , sourceFiles ) ;
2407
2408
}
2408
2409
2410
+ if ( node . kind === SyntaxKind . SuperKeyword ) {
2411
+ return getReferencesForSuperKeyword ( node ) ;
2412
+ }
2413
+
2409
2414
var symbol = typeInfoResolver . getSymbolInfo ( node ) ;
2410
2415
2411
2416
// Could not find a symbol e.g. unknown identifier
@@ -2627,32 +2632,75 @@ module ts {
2627
2632
}
2628
2633
}
2629
2634
2630
- function getReferencesForThisKeyword ( thisKeyword : Node , sourceFiles : SourceFile [ ] ) {
2631
- // Get the owner" of the 'this' keyword.
2632
- var thisContainer = getThisContainer ( thisKeyword , /* includeArrowFunctions */ false ) ;
2635
+ function getReferencesForSuperKeyword ( superKeyword : Node ) : ReferenceEntry [ ] {
2636
+ var searchSpaceNode = getSuperContainer ( superKeyword ) ;
2637
+ if ( ! searchSpaceNode ) {
2638
+ return undefined ;
2639
+ }
2640
+ // Whether 'super' occurs in a static context within a class.
2641
+ var staticFlag = NodeFlags . Static ;
2642
+
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 :
2653
+ return undefined ;
2654
+ }
2655
+
2656
+ var result : ReferenceEntry [ ] = [ ] ;
2633
2657
2634
- var searchSpaceNode : Node ;
2658
+ var sourceFile = searchSpaceNode . getSourceFile ( ) ;
2659
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "super" , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
2660
+ forEach ( possiblePositions , position => {
2661
+ cancellationToken . throwIfCancellationRequested ( ) ;
2635
2662
2636
- // Whether 'this' occurs in a static context within a class;
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.
2637
2686
var staticFlag = NodeFlags . Static ;
2638
2687
2639
- switch ( thisContainer . kind ) {
2688
+ switch ( searchSpaceNode . kind ) {
2640
2689
case SyntaxKind . Property :
2641
2690
case SyntaxKind . Method :
2642
2691
case SyntaxKind . Constructor :
2643
2692
case SyntaxKind . GetAccessor :
2644
2693
case SyntaxKind . SetAccessor :
2645
- searchSpaceNode = thisContainer . parent ; // should be the owning class
2646
- staticFlag &= thisContainer . flags
2694
+ staticFlag &= searchSpaceNode . flags
2695
+ searchSpaceNode = searchSpaceNode . parent ; // re-assign to be the owning class
2647
2696
break ;
2648
2697
case SyntaxKind . SourceFile :
2649
- if ( isExternalModule ( < SourceFile > thisContainer ) ) {
2698
+ if ( isExternalModule ( < SourceFile > searchSpaceNode ) ) {
2650
2699
return undefined ;
2651
2700
}
2652
2701
// Fall through
2653
2702
case SyntaxKind . FunctionDeclaration :
2654
2703
case SyntaxKind . FunctionExpression :
2655
- searchSpaceNode = thisContainer ;
2656
2704
break ;
2657
2705
default :
2658
2706
return undefined ;
@@ -2683,31 +2731,24 @@ module ts {
2683
2731
return ;
2684
2732
}
2685
2733
2686
- // Get the owner of the 'this' keyword.
2687
- // This *should* be a node that occurs somewhere within searchSpaceNode.
2688
2734
var container = getThisContainer ( node , /* includeArrowFunctions */ false ) ;
2689
2735
2690
- switch ( container . kind ) {
2691
- case SyntaxKind . Property :
2692
- case SyntaxKind . Method :
2693
- case SyntaxKind . Constructor :
2694
- case SyntaxKind . GetAccessor :
2695
- case SyntaxKind . SetAccessor :
2696
- // Make sure the container belongs to the same class
2697
- // and has the appropriate static modifier from the original container.
2698
- if ( searchSpaceNode . symbol === container . parent . symbol && ( container . flags & NodeFlags . Static ) === staticFlag ) {
2736
+ switch ( searchSpaceNode . kind ) {
2737
+ case SyntaxKind . FunctionExpression :
2738
+ case SyntaxKind . FunctionDeclaration :
2739
+ if ( searchSpaceNode . symbol === container . symbol ) {
2699
2740
result . push ( getReferenceEntryFromNode ( node ) ) ;
2700
2741
}
2701
2742
break ;
2702
- case SyntaxKind . FunctionDeclaration :
2703
- case SyntaxKind . FunctionExpression :
2704
- if ( searchSpaceNode . symbol === container . symbol ) {
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 ) {
2705
2747
result . push ( getReferenceEntryFromNode ( node ) ) ;
2706
2748
}
2707
2749
break ;
2708
2750
case SyntaxKind . SourceFile :
2709
- // Add all 'this' keywords that belong to the top-level scope.
2710
- if ( searchSpaceNode . kind === SyntaxKind . SourceFile && ! isExternalModule ( < SourceFile > searchSpaceNode ) ) {
2751
+ if ( container . kind === SyntaxKind . SourceFile && ! isExternalModule ( < SourceFile > container ) ) {
2711
2752
result . push ( getReferenceEntryFromNode ( node ) ) ;
2712
2753
}
2713
2754
break ;
0 commit comments