Skip to content

Commit 3825c9b

Browse files
Handled function boundaries.
1 parent 88f37e5 commit 3825c9b

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/services/services.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ module ts {
21692169
var result: ReferenceEntry[];
21702170

21712171
// Each of these helper functions bails out if the node is undefined,
2172-
// which is why you'll see much of this'node.parent && node.parent.parent' pattern.
2172+
// which is why you'll see much of this 'node.parent && node.parent.parent' pattern.
21732173
switch (node.kind) {
21742174
case SyntaxKind.TryKeyword:
21752175
case SyntaxKind.CatchKeyword:
@@ -2237,6 +2237,9 @@ module ts {
22372237
case SyntaxKind.DoStatement:
22382238
case SyntaxKind.WhileStatement:
22392239
case SyntaxKind.SwitchStatement:
2240+
case SyntaxKind.FunctionExpression:
2241+
case SyntaxKind.FunctionDeclaration:
2242+
case SyntaxKind.ArrowFunction:
22402243
return;
22412244
}
22422245

@@ -2256,7 +2259,7 @@ module ts {
22562259
if (breakStatement.label) {
22572260
return undefined;
22582261
}
2259-
2262+
22602263
for (var owner = node.parent; owner; owner = owner.parent) {
22612264
switch (owner.kind) {
22622265
case SyntaxKind.ForStatement:
@@ -2265,10 +2268,16 @@ module ts {
22652268
case SyntaxKind.WhileStatement:
22662269
// TODO (drosen): Handle loops!
22672270
return undefined;
2271+
case SyntaxKind.FunctionExpression:
2272+
case SyntaxKind.FunctionDeclaration:
2273+
case SyntaxKind.ArrowFunction:
2274+
return undefined;
22682275
case SyntaxKind.SwitchStatement:
22692276
return getSwitchCaseDefaultOccurrences(<SwitchStatement>owner);
22702277
}
22712278
}
2279+
2280+
return undefined;
22722281
}
22732282

22742283
function pushIfKeyword(keywordList: Node[], token: Node) {

tests/cases/fourslash/getOccurrencesSwitchCaseDefaultBroken.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
//// break;
1111
//// /*5*/cas 16:
1212
//// c/*3*/ase 12:
13+
//// function f() {
14+
//// br/*11*/eak;
15+
//// /*12*/break;
16+
//// }
1317
////}
14-
18+
////
1519
////sw/*6*/itch (10) {
1620
//// de/*7*/fault
1721
//// case 1:
1822
//// case 2
19-
23+
////
2024
//// c/*8*/ose 4:
2125
//// case 8:
2226
//// case 0xBEEF:
2327
//// bre/*9*/ak;
2428
//// case 16:
29+
//// () => bre/*10*/ak;
2530
////}
2631

2732
for (var i = 1; i <= test.markers().length; i++) {
@@ -43,5 +48,10 @@ for (var i = 1; i <= test.markers().length; i++) {
4348
case 9:
4449
verify.occurrencesAtPositionCount(8);
4550
break;
51+
case 10:
52+
case 11:
53+
case 12:
54+
verify.occurrencesAtPositionCount(0);
55+
break;
4656
}
4757
}

0 commit comments

Comments
 (0)