@@ -2146,7 +2146,7 @@ module ts {
2146
2146
return undefined ;
2147
2147
}
2148
2148
2149
- if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . ThisKeyword ||
2149
+ if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . ThisKeyword || node . kind === SyntaxKind . SuperKeyword ||
2150
2150
isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) || isNameOfExternalModuleImportOrDeclaration ( node ) ) {
2151
2151
return getReferencesForNode ( node , [ sourceFile ] ) ;
2152
2152
}
@@ -2379,6 +2379,7 @@ module ts {
2379
2379
2380
2380
if ( node . kind !== SyntaxKind . Identifier &&
2381
2381
node . kind !== SyntaxKind . ThisKeyword &&
2382
+ node . kind !== SyntaxKind . SuperKeyword &&
2382
2383
! isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) &&
2383
2384
! isNameOfExternalModuleImportOrDeclaration ( node ) ) {
2384
2385
return undefined ;
@@ -2402,8 +2403,8 @@ module ts {
2402
2403
}
2403
2404
}
2404
2405
2405
- if ( node . kind === SyntaxKind . ThisKeyword ) {
2406
- return getReferencesForThisKeyword ( node , sourceFiles ) ;
2406
+ if ( node . kind === SyntaxKind . ThisKeyword || node . kind === SyntaxKind . SuperKeyword ) {
2407
+ return getReferencesForThisOrSuperKeyword ( node , sourceFiles ) ;
2407
2408
}
2408
2409
2409
2410
var symbol = typeInfoResolver . getSymbolInfo ( node ) ;
@@ -2627,32 +2628,46 @@ module ts {
2627
2628
}
2628
2629
}
2629
2630
2630
- function getReferencesForThisKeyword ( thisKeyword : Node , sourceFiles : SourceFile [ ] ) {
2631
- // Get the owner" of the 'this' keyword.
2632
- var thisContainer = getThisContainer ( thisKeyword , /* includeArrowFunctions */ false ) ;
2633
-
2631
+ function getReferencesForThisOrSuperKeyword ( thisOrSuperKeyword : Node , sourceFiles : SourceFile [ ] ) : ReferenceEntry [ ] {
2632
+ var keywordName : string ;
2634
2633
var searchSpaceNode : Node ;
2635
2634
2636
- // Whether 'this' occurs in a static context within a class;
2635
+ if ( thisOrSuperKeyword . kind === SyntaxKind . ThisKeyword ) {
2636
+ keywordName = "this"
2637
+ searchSpaceNode = getThisContainer ( thisOrSuperKeyword , /* includeArrowFunctions */ false ) ;
2638
+ }
2639
+ else {
2640
+ keywordName = "super" ;
2641
+ searchSpaceNode = getSuperContainer ( thisOrSuperKeyword ) ;
2642
+
2643
+ if ( ! searchSpaceNode ) {
2644
+ return undefined ;
2645
+ }
2646
+ }
2647
+
2648
+ // Whether 'this'/'super' occurs in a static context within a class.
2637
2649
var staticFlag = NodeFlags . Static ;
2638
2650
2639
- switch ( thisContainer . kind ) {
2651
+ switch ( searchSpaceNode . kind ) {
2640
2652
case SyntaxKind . Property :
2641
2653
case SyntaxKind . Method :
2642
2654
case SyntaxKind . Constructor :
2643
2655
case SyntaxKind . GetAccessor :
2644
2656
case SyntaxKind . SetAccessor :
2645
- searchSpaceNode = thisContainer . parent ; // should be the owning class
2646
- staticFlag &= thisContainer . flags
2657
+ staticFlag &= searchSpaceNode . flags
2658
+ searchSpaceNode = searchSpaceNode . parent ; // re-assign to be the owning class
2647
2659
break ;
2648
2660
case SyntaxKind . SourceFile :
2649
- if ( isExternalModule ( < SourceFile > thisContainer ) ) {
2661
+ if ( isExternalModule ( < SourceFile > searchSpaceNode ) ) {
2650
2662
return undefined ;
2651
2663
}
2652
- // Fall through
2664
+ break ;
2653
2665
case SyntaxKind . FunctionDeclaration :
2654
2666
case SyntaxKind . FunctionExpression :
2655
- searchSpaceNode = thisContainer ;
2667
+ // 'super' can only occur within a class.
2668
+ if ( thisOrSuperKeyword . kind === SyntaxKind . SuperKeyword ) {
2669
+ return undefined ;
2670
+ }
2656
2671
break ;
2657
2672
default :
2658
2673
return undefined ;
@@ -2662,55 +2677,60 @@ module ts {
2662
2677
2663
2678
if ( searchSpaceNode . kind === SyntaxKind . SourceFile ) {
2664
2679
forEach ( sourceFiles , sourceFile => {
2665
- var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
2666
- getThisReferencesInFile ( sourceFile , sourceFile , possiblePositions , result ) ;
2680
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , keywordName , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
2681
+ getThisOrSuperReferencesInFile ( sourceFile , sourceFile , possiblePositions , result ) ;
2667
2682
} ) ;
2668
2683
}
2669
2684
else {
2670
2685
var sourceFile = searchSpaceNode . getSourceFile ( ) ;
2671
- var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
2672
- getThisReferencesInFile ( sourceFile , searchSpaceNode , possiblePositions , result ) ;
2686
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , keywordName , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
2687
+ getThisOrSuperReferencesInFile ( sourceFile , searchSpaceNode , possiblePositions , result ) ;
2673
2688
}
2674
2689
2675
2690
return result ;
2676
2691
2677
- function getThisReferencesInFile ( sourceFile : SourceFile , searchSpaceNode : Node , possiblePositions : number [ ] , result : ReferenceEntry [ ] ) : void {
2692
+ function getThisOrSuperReferencesInFile ( sourceFile : SourceFile , searchSpaceNode : Node , possiblePositions : number [ ] , result : ReferenceEntry [ ] ) : void {
2678
2693
forEach ( possiblePositions , position => {
2679
2694
cancellationToken . throwIfCancellationRequested ( ) ;
2680
2695
2681
2696
var node = getNodeAtPosition ( sourceFile , position ) ;
2682
- if ( ! node || node . kind !== SyntaxKind . ThisKeyword ) {
2697
+ if ( ! node ) {
2683
2698
return ;
2684
2699
}
2685
2700
2686
- // Get the owner of the 'this' keyword.
2687
- // This *should* be a node that occurs somewhere within searchSpaceNode.
2688
- var container = getThisContainer ( node , /* includeArrowFunctions */ false ) ;
2689
-
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 ) {
2699
- result . push ( getReferenceEntryFromNode ( node ) ) ;
2700
- }
2701
- break ;
2702
- case SyntaxKind . FunctionDeclaration :
2703
- case SyntaxKind . FunctionExpression :
2704
- if ( searchSpaceNode . symbol === container . symbol ) {
2705
- result . push ( getReferenceEntryFromNode ( node ) ) ;
2706
- }
2707
- break ;
2708
- case SyntaxKind . SourceFile :
2709
- // Add all 'this' keywords that belong to the top-level scope.
2710
- if ( searchSpaceNode . kind === SyntaxKind . SourceFile && ! isExternalModule ( < SourceFile > searchSpaceNode ) ) {
2711
- result . push ( getReferenceEntryFromNode ( node ) ) ;
2712
- }
2713
- break ;
2701
+ var container = getNodeAtPosition ( sourceFile , position ) ;
2702
+ if ( ! container ) {
2703
+ return ;
2704
+ }
2705
+
2706
+ if ( node . kind === SyntaxKind . SuperKeyword ) {
2707
+ container = getSuperContainer ( node ) ;
2708
+ }
2709
+ else if ( node . kind === SyntaxKind . ThisKeyword ) {
2710
+ container = getThisContainer ( node , /* includeArrowFunctions */ false ) ;
2711
+ }
2712
+
2713
+ if ( container ) {
2714
+ switch ( searchSpaceNode . kind ) {
2715
+ case SyntaxKind . FunctionExpression :
2716
+ case SyntaxKind . FunctionDeclaration :
2717
+ if ( searchSpaceNode . symbol === container . symbol ) {
2718
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2719
+ }
2720
+ break ;
2721
+ case SyntaxKind . ClassDeclaration :
2722
+ // Make sure the container belongs to the same class
2723
+ // and has the appropriate static modifier from the original container.
2724
+ if ( container . parent && searchSpaceNode . symbol === container . parent . symbol && ( container . flags & NodeFlags . Static ) === staticFlag ) {
2725
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2726
+ }
2727
+ break ;
2728
+ case SyntaxKind . SourceFile :
2729
+ if ( container . kind === SyntaxKind . SourceFile && ! isExternalModule ( < SourceFile > container ) ) {
2730
+ result . push ( getReferenceEntryFromNode ( node ) ) ;
2731
+ }
2732
+ break ;
2733
+ }
2714
2734
}
2715
2735
} ) ;
2716
2736
}
0 commit comments