@@ -2168,8 +2168,7 @@ module ts {
2168
2168
2169
2169
var result : ReferenceEntry [ ] ;
2170
2170
2171
- // 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.
2171
+ // 'parent' and 'hasKind' are falsey-propagating convenience functions.
2173
2172
switch ( node . kind ) {
2174
2173
case SyntaxKind . TryKeyword :
2175
2174
case SyntaxKind . CatchKeyword :
@@ -2201,14 +2200,14 @@ module ts {
2201
2200
function getTryCatchFinallyOccurrences ( tryStatement : TryStatement ) : ReferenceEntry [ ] {
2202
2201
var keywords : Node [ ] = [ ] ;
2203
2202
2204
- pushIfKeyword ( keywords , tryStatement . getFirstToken ( ) , SyntaxKind . TryKeyword ) ;
2203
+ pushKeyword ( keywords , tryStatement . getFirstToken ( ) , SyntaxKind . TryKeyword ) ;
2205
2204
2206
2205
if ( tryStatement . catchBlock ) {
2207
- pushIfKeyword ( keywords , tryStatement . catchBlock . getFirstToken ( ) , SyntaxKind . CatchKeyword ) ;
2206
+ pushKeyword ( keywords , tryStatement . catchBlock . getFirstToken ( ) , SyntaxKind . CatchKeyword ) ;
2208
2207
}
2209
2208
2210
2209
if ( tryStatement . finallyBlock ) {
2211
- pushIfKeyword ( keywords , tryStatement . finallyBlock . getFirstToken ( ) , SyntaxKind . FinallyKeyword ) ;
2210
+ pushKeyword ( keywords , tryStatement . finallyBlock . getFirstToken ( ) , SyntaxKind . FinallyKeyword ) ;
2212
2211
}
2213
2212
2214
2213
return keywordsToReferenceEntries ( keywords ) ;
@@ -2217,33 +2216,33 @@ module ts {
2217
2216
function getSwitchCaseDefaultOccurrences ( switchStatement : SwitchStatement ) {
2218
2217
var keywords : Node [ ] = [ ] ;
2219
2218
2220
- pushIfKeyword ( keywords , switchStatement . getFirstToken ( ) , SyntaxKind . SwitchKeyword ) ;
2219
+ pushKeyword ( keywords , switchStatement . getFirstToken ( ) , SyntaxKind . SwitchKeyword ) ;
2221
2220
2222
2221
// Go through each clause in the switch statement, collecting the clause keywords.
2223
2222
switchStatement . clauses . forEach ( clause => {
2224
- pushIfKeyword ( keywords , clause . getFirstToken ( ) , [ SyntaxKind . CaseKeyword , SyntaxKind . DefaultKeyword ] ) ;
2223
+ pushKeyword ( keywords , clause . getFirstToken ( ) , [ SyntaxKind . CaseKeyword , SyntaxKind . DefaultKeyword ] ) ;
2225
2224
2226
2225
// For each clause, also recursively traverse the statements where we can find analogous breaks.
2227
2226
forEachChild ( clause , function aggregateBreakKeywords ( node : Node ) : void {
2228
2227
switch ( node . kind ) {
2229
2228
case SyntaxKind . BreakStatement :
2230
2229
// If the break statement has a label, it cannot be part of a switch block.
2231
2230
if ( ! ( < BreakOrContinueStatement > node ) . label ) {
2232
- pushIfKeyword ( keywords , node . getFirstToken ( ) , SyntaxKind . BreakKeyword ) ;
2231
+ pushKeyword ( keywords , node . getFirstToken ( ) , SyntaxKind . BreakKeyword ) ;
2233
2232
}
2234
2233
// Fall through
2235
2234
case SyntaxKind . ForStatement :
2236
2235
case SyntaxKind . ForInStatement :
2237
2236
case SyntaxKind . DoStatement :
2238
2237
case SyntaxKind . WhileStatement :
2239
2238
case SyntaxKind . SwitchStatement :
2240
- case SyntaxKind . FunctionExpression :
2241
- case SyntaxKind . FunctionDeclaration :
2242
- case SyntaxKind . ArrowFunction :
2243
2239
return ;
2244
2240
}
2245
2241
2246
- forEachChild ( node , aggregateBreakKeywords ) ;
2242
+ // Do not cross function boundaries.
2243
+ if ( ! isAnyFunction ( node ) ) {
2244
+ forEachChild ( node , aggregateBreakKeywords ) ;
2245
+ }
2247
2246
} ) ;
2248
2247
} ) ;
2249
2248
@@ -2264,12 +2263,14 @@ module ts {
2264
2263
case SyntaxKind . WhileStatement :
2265
2264
// TODO (drosen): Handle loops!
2266
2265
return undefined ;
2267
- case SyntaxKind . FunctionExpression :
2268
- case SyntaxKind . FunctionDeclaration :
2269
- case SyntaxKind . ArrowFunction :
2270
- return undefined ;
2266
+
2271
2267
case SyntaxKind . SwitchStatement :
2272
2268
return getSwitchCaseDefaultOccurrences ( < SwitchStatement > owner ) ;
2269
+
2270
+ default :
2271
+ if ( isAnyFunction ( owner ) ) {
2272
+ return undefined ;
2273
+ }
2273
2274
}
2274
2275
}
2275
2276
@@ -2286,9 +2287,9 @@ module ts {
2286
2287
return node && node . parent ;
2287
2288
}
2288
2289
2289
- function pushIfKeyword ( keywordList : Node [ ] , token : Node , expected : SyntaxKind ) : void ;
2290
- function pushIfKeyword ( keywordList : Node [ ] , token : Node , expected : SyntaxKind [ ] ) : void ;
2291
- function pushIfKeyword ( keywordList : Node [ ] , token : Node , expected : any ) : void {
2290
+ function pushKeyword ( keywordList : Node [ ] , token : Node , expected : SyntaxKind ) : void ;
2291
+ function pushKeyword ( keywordList : Node [ ] , token : Node , expected : SyntaxKind [ ] ) : void ;
2292
+ function pushKeyword ( keywordList : Node [ ] , token : Node , expected : any ) : void {
2292
2293
if ( ! token ) {
2293
2294
return ;
2294
2295
}
0 commit comments