@@ -2432,7 +2432,7 @@ module ts {
2432
2432
case SyntaxKind . Identifier :
2433
2433
case SyntaxKind . QualifiedName :
2434
2434
var symbol = getSymbolInfo ( node ) ;
2435
- return getDeclaredTypeOfSymbol ( symbol ) ;
2435
+ return symbol && getDeclaredTypeOfSymbol ( symbol ) ;
2436
2436
default :
2437
2437
return unknownType ;
2438
2438
}
@@ -3472,41 +3472,6 @@ module ts {
3472
3472
return getAncestor ( node , kind ) !== undefined ;
3473
3473
}
3474
3474
3475
- function getAncestor ( node : Node , kind : SyntaxKind ) : Node {
3476
- switch ( kind ) {
3477
- // special-cases that can be come first
3478
- case SyntaxKind . ClassDeclaration :
3479
- while ( node ) {
3480
- switch ( node . kind ) {
3481
- case SyntaxKind . ClassDeclaration :
3482
- return < ClassDeclaration > node ;
3483
- case SyntaxKind . EnumDeclaration :
3484
- case SyntaxKind . InterfaceDeclaration :
3485
- case SyntaxKind . ModuleDeclaration :
3486
- case SyntaxKind . ImportDeclaration :
3487
- // early exit cases - declarations cannot be nested in classes
3488
- return undefined ;
3489
- default :
3490
- node = node . parent ;
3491
- continue ;
3492
- }
3493
- }
3494
- break ;
3495
- default :
3496
- while ( node ) {
3497
- if ( node . kind === kind ) {
3498
- return node ;
3499
- }
3500
- else {
3501
- node = node . parent ;
3502
- }
3503
- }
3504
- break ;
3505
- }
3506
-
3507
- return undefined ;
3508
- }
3509
-
3510
3475
// EXPRESSION TYPE CHECKING
3511
3476
3512
3477
function checkIdentifier ( node : Identifier ) : Type {
@@ -3853,6 +3818,11 @@ module ts {
3853
3818
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
3854
3819
// be "pushed" onto a node using the contextualType property.
3855
3820
function getContextualType ( node : Expression ) : Type {
3821
+ if ( isInsideWithStatementBody ( node ) ) {
3822
+ // We cannot answer semantic questions within a with block, do not proceed any further
3823
+ return undefined ;
3824
+ }
3825
+
3856
3826
if ( node . contextualType ) {
3857
3827
return node . contextualType ;
3858
3828
}
@@ -6718,7 +6688,20 @@ module ts {
6718
6688
return findChildAtPosition ( sourceFile ) ;
6719
6689
}
6720
6690
6721
- function getSymbolsInScope ( location : Node , meaning : SymbolFlags ) : Symbol [ ] {
6691
+ function isInsideWithStatementBody ( node : Node ) : boolean {
6692
+ if ( node ) {
6693
+ while ( node . parent ) {
6694
+ if ( node . parent . kind === SyntaxKind . WithStatement && ( < WithStatement > node . parent ) . statement === node ) {
6695
+ return true ;
6696
+ }
6697
+ node = node . parent ;
6698
+ }
6699
+ }
6700
+
6701
+ return false ;
6702
+ }
6703
+
6704
+ function getSymbolsInScope ( location : Node , meaning : SymbolFlags ) : Symbol [ ] {
6722
6705
var symbols : SymbolTable = { } ;
6723
6706
var memberFlags : NodeFlags = 0 ;
6724
6707
function copySymbol ( symbol : Symbol , meaning : SymbolFlags ) {
@@ -6738,6 +6721,12 @@ module ts {
6738
6721
}
6739
6722
}
6740
6723
}
6724
+
6725
+ if ( isInsideWithStatementBody ( location ) ) {
6726
+ // We cannot answer semantic questions within a with block, do not proceed any further
6727
+ return [ ] ;
6728
+ }
6729
+
6741
6730
while ( location ) {
6742
6731
if ( location . locals && ! isGlobalSourceFile ( location ) ) {
6743
6732
copySymbols ( location . locals , meaning ) ;
@@ -7010,6 +6999,11 @@ module ts {
7010
6999
}
7011
7000
7012
7001
function getSymbolInfo ( node : Node ) {
7002
+ if ( isInsideWithStatementBody ( node ) ) {
7003
+ // We cannot answer semantic questions within a with block, do not proceed any further
7004
+ return undefined ;
7005
+ }
7006
+
7013
7007
if ( isDeclarationOrFunctionExpressionOrCatchVariableName ( node ) ) {
7014
7008
// This is a declaration, call getSymbolOfNode
7015
7009
return getSymbolOfNode ( node . parent ) ;
@@ -7064,9 +7058,15 @@ module ts {
7064
7058
}
7065
7059
7066
7060
function getTypeOfNode ( node : Node ) : Type {
7061
+ if ( isInsideWithStatementBody ( node ) ) {
7062
+ // We cannot answer semantic questions within a with block, do not proceed any further
7063
+ return unknownType ;
7064
+ }
7065
+
7067
7066
if ( isExpression ( node ) ) {
7068
7067
return getTypeOfExpression ( < Expression > node ) ;
7069
7068
}
7069
+
7070
7070
if ( isTypeNode ( node ) ) {
7071
7071
return getTypeFromTypeNode ( < TypeNode > node ) ;
7072
7072
}
@@ -7079,7 +7079,7 @@ module ts {
7079
7079
7080
7080
if ( isTypeDeclarationName ( node ) ) {
7081
7081
var symbol = getSymbolInfo ( node ) ;
7082
- return getDeclaredTypeOfSymbol ( symbol ) ;
7082
+ return symbol && getDeclaredTypeOfSymbol ( symbol ) ;
7083
7083
}
7084
7084
7085
7085
if ( isDeclaration ( node ) ) {
@@ -7090,12 +7090,12 @@ module ts {
7090
7090
7091
7091
if ( isDeclarationOrFunctionExpressionOrCatchVariableName ( node ) ) {
7092
7092
var symbol = getSymbolInfo ( node ) ;
7093
- return getTypeOfSymbol ( symbol ) ;
7093
+ return symbol && getTypeOfSymbol ( symbol ) ;
7094
7094
}
7095
7095
7096
7096
if ( isInRightSideOfImportOrExportAssignment ( node ) ) {
7097
7097
var symbol = getSymbolInfo ( node ) ;
7098
- var declaredType = getDeclaredTypeOfSymbol ( symbol ) ;
7098
+ var declaredType = symbol && getDeclaredTypeOfSymbol ( symbol ) ;
7099
7099
return declaredType !== unknownType ? declaredType : getTypeOfSymbol ( symbol ) ;
7100
7100
}
7101
7101
@@ -7147,7 +7147,7 @@ module ts {
7147
7147
}
7148
7148
7149
7149
function getRootSymbol ( symbol : Symbol ) {
7150
- return ( symbol . flags & SymbolFlags . Transient ) ? getSymbolLinks ( symbol ) . target : symbol ;
7150
+ return ( ( symbol . flags & SymbolFlags . Transient ) && getSymbolLinks ( symbol ) . target ) || symbol ;
7151
7151
}
7152
7152
7153
7153
// Emitter support
0 commit comments