@@ -3468,29 +3468,6 @@ module ts {
3468
3468
return getTypeOfSymbol ( getExportSymbolOfValueSymbolIfExported ( symbol ) ) ;
3469
3469
}
3470
3470
3471
- function getThisContainer ( node : Node ) : Node {
3472
- while ( true ) {
3473
- node = node . parent ;
3474
- if ( ! node ) {
3475
- return node ;
3476
- }
3477
- switch ( node . kind ) {
3478
- case SyntaxKind . FunctionDeclaration :
3479
- case SyntaxKind . FunctionExpression :
3480
- case SyntaxKind . ModuleDeclaration :
3481
- case SyntaxKind . Property :
3482
- case SyntaxKind . Method :
3483
- case SyntaxKind . Constructor :
3484
- case SyntaxKind . GetAccessor :
3485
- case SyntaxKind . SetAccessor :
3486
- case SyntaxKind . EnumDeclaration :
3487
- case SyntaxKind . SourceFile :
3488
- case SyntaxKind . ArrowFunction :
3489
- return node ;
3490
- }
3491
- }
3492
- }
3493
-
3494
3471
function captureLexicalThis ( node : Node , container : Node ) : void {
3495
3472
var classNode = container . parent && container . parent . kind === SyntaxKind . ClassDeclaration ? container . parent : undefined ;
3496
3473
getNodeLinks ( node ) . flags |= NodeCheckFlags . LexicalThis ;
@@ -3503,11 +3480,14 @@ module ts {
3503
3480
}
3504
3481
3505
3482
function checkThisExpression ( node : Node ) : Type {
3506
- var container = getThisContainer ( node ) ;
3483
+ // Stop at the first arrow function so that we can
3484
+ // tell whether 'this' needs to be captured.
3485
+ var container = getThisContainer ( node , /* includeArrowFunctions */ true ) ;
3507
3486
var needToCaptureLexicalThis = false ;
3508
- // skip arrow functions
3509
- while ( container . kind === SyntaxKind . ArrowFunction ) {
3510
- container = getThisContainer ( container ) ;
3487
+
3488
+ // Now skip arrow functions to get the "real" owner of 'this'.
3489
+ if ( container . kind === SyntaxKind . ArrowFunction ) {
3490
+ container = getThisContainer ( container , /* includeArrowFunctions */ false ) ;
3511
3491
needToCaptureLexicalThis = true ;
3512
3492
}
3513
3493
@@ -4407,37 +4387,6 @@ module ts {
4407
4387
return voidType ;
4408
4388
}
4409
4389
4410
- // WARNING: This has the same semantics as the forEach family of functions,
4411
- // in that traversal terminates in the event that 'visitor' supplies a truthy value.
4412
- function forEachReturnStatement < T > ( body : Block , visitor : ( stmt : ReturnStatement ) => T ) : T {
4413
-
4414
- return traverse ( body ) ;
4415
-
4416
- function traverse ( node : Node ) : T {
4417
- switch ( node . kind ) {
4418
- case SyntaxKind . ReturnStatement :
4419
- return visitor ( node ) ;
4420
- case SyntaxKind . Block :
4421
- case SyntaxKind . FunctionBlock :
4422
- case SyntaxKind . IfStatement :
4423
- case SyntaxKind . DoStatement :
4424
- case SyntaxKind . WhileStatement :
4425
- case SyntaxKind . ForStatement :
4426
- case SyntaxKind . ForInStatement :
4427
- case SyntaxKind . WithStatement :
4428
- case SyntaxKind . SwitchStatement :
4429
- case SyntaxKind . CaseClause :
4430
- case SyntaxKind . DefaultClause :
4431
- case SyntaxKind . LabelledStatement :
4432
- case SyntaxKind . TryStatement :
4433
- case SyntaxKind . TryBlock :
4434
- case SyntaxKind . CatchBlock :
4435
- case SyntaxKind . FinallyBlock :
4436
- return forEachChild ( node , traverse ) ;
4437
- }
4438
- }
4439
- }
4440
-
4441
4390
/// Returns a set of types relating to every return expression relating to a function block.
4442
4391
function checkAndAggregateReturnExpressionTypes ( body : Block , contextualMapper ?: TypeMapper ) : Type [ ] {
4443
4392
var aggregatedTypes : Type [ ] = [ ] ;
@@ -5856,17 +5805,6 @@ module ts {
5856
5805
// TODO: Check that target label is valid
5857
5806
}
5858
5807
5859
- function getContainingFunction ( node : Node ) : SignatureDeclaration {
5860
- while ( true ) {
5861
- node = node . parent ;
5862
- if ( ! node || node . kind === SyntaxKind . FunctionDeclaration || node . kind === SyntaxKind . FunctionExpression ||
5863
- node . kind === SyntaxKind . ArrowFunction || node . kind === SyntaxKind . Method || node . kind === SyntaxKind . Constructor ||
5864
- node . kind === SyntaxKind . GetAccessor || node . kind === SyntaxKind . SetAccessor ) {
5865
- return < SignatureDeclaration > node ;
5866
- }
5867
- }
5868
- }
5869
-
5870
5808
function checkReturnStatement ( node : ReturnStatement ) {
5871
5809
if ( node . expression && ! ( getNodeLinks ( node . expression ) . flags & NodeCheckFlags . TypeChecked ) ) {
5872
5810
var func = getContainingFunction ( node ) ;
0 commit comments