1
1
/// <reference path="parser.ts"/>
2
2
3
3
module ts {
4
- /* @internal */ export var bindTime = 0 ;
4
+ /* @internal */ export let bindTime = 0 ;
5
5
6
6
export const enum ModuleInstanceState {
7
7
NonInstantiated = 0 ,
@@ -25,7 +25,7 @@ module ts {
25
25
}
26
26
// 4. other uninstantiated module declarations.
27
27
else if ( node . kind === SyntaxKind . ModuleBlock ) {
28
- var state = ModuleInstanceState . NonInstantiated ;
28
+ let state = ModuleInstanceState . NonInstantiated ;
29
29
forEachChild ( node , n => {
30
30
switch ( getModuleInstanceState ( n ) ) {
31
31
case ModuleInstanceState . NonInstantiated :
@@ -52,18 +52,18 @@ module ts {
52
52
}
53
53
54
54
export function bindSourceFile ( file : SourceFile ) : void {
55
- var start = new Date ( ) . getTime ( ) ;
55
+ let start = new Date ( ) . getTime ( ) ;
56
56
bindSourceFileWorker ( file ) ;
57
57
bindTime += new Date ( ) . getTime ( ) - start ;
58
58
}
59
59
60
60
function bindSourceFileWorker ( file : SourceFile ) : void {
61
61
var parent : Node ;
62
- var container : Node ;
63
- var blockScopeContainer : Node ;
64
- var lastContainer : Node ;
65
- var symbolCount = 0 ;
66
- var Symbol = objectAllocator . getSymbolConstructor ( ) ;
62
+ let container : Node ;
63
+ let blockScopeContainer : Node ;
64
+ let lastContainer : Node ;
65
+ let symbolCount = 0 ;
66
+ let Symbol = objectAllocator . getSymbolConstructor ( ) ;
67
67
68
68
if ( ! file . locals ) {
69
69
file . locals = { } ;
@@ -103,7 +103,7 @@ module ts {
103
103
return '"' + ( < LiteralExpression > node . name ) . text + '"' ;
104
104
}
105
105
if ( node . name . kind === SyntaxKind . ComputedPropertyName ) {
106
- var nameExpression = ( < ComputedPropertyName > node . name ) . expression ;
106
+ let nameExpression = ( < ComputedPropertyName > node . name ) . expression ;
107
107
Debug . assert ( isWellKnownSymbolSyntactically ( nameExpression ) ) ;
108
108
return getPropertyNameForKnownSymbolName ( ( < PropertyAccessExpression > nameExpression ) . name . text ) ;
109
109
}
@@ -138,18 +138,19 @@ module ts {
138
138
Debug . assert ( ! hasDynamicName ( node ) ) ;
139
139
140
140
// The exported symbol for an export default function/class node is always named "default"
141
- var name = node . flags & NodeFlags . Default && parent ? "default" : getDeclarationName ( node ) ;
141
+ let name = node . flags & NodeFlags . Default && parent ? "default" : getDeclarationName ( node ) ;
142
142
143
+ let symbol : Symbol ;
143
144
if ( name !== undefined ) {
144
- var symbol = hasProperty ( symbols , name ) ? symbols [ name ] : ( symbols [ name ] = createSymbol ( 0 , name ) ) ;
145
+ symbol = hasProperty ( symbols , name ) ? symbols [ name ] : ( symbols [ name ] = createSymbol ( 0 , name ) ) ;
145
146
if ( symbol . flags & excludes ) {
146
147
if ( node . name ) {
147
148
node . name . parent = node ;
148
149
}
149
150
150
151
// Report errors every position with duplicate declaration
151
152
// Report errors on previous encountered declarations
152
- var message = symbol . flags & SymbolFlags . BlockScopedVariable
153
+ let message = symbol . flags & SymbolFlags . BlockScopedVariable
153
154
? Diagnostics . Cannot_redeclare_block_scoped_variable_0
154
155
: Diagnostics . Duplicate_identifier_0 ;
155
156
@@ -172,7 +173,7 @@ module ts {
172
173
// Every class automatically contains a static property member named 'prototype',
173
174
// the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter.
174
175
// It is an error to explicitly declare a static property member with the name 'prototype'.
175
- var prototypeSymbol = createSymbol ( SymbolFlags . Property | SymbolFlags . Prototype , "prototype" ) ;
176
+ let prototypeSymbol = createSymbol ( SymbolFlags . Property | SymbolFlags . Prototype , "prototype" ) ;
176
177
if ( hasProperty ( symbol . exports , prototypeSymbol . name ) ) {
177
178
if ( node . name ) {
178
179
node . name . parent = node ;
@@ -196,7 +197,7 @@ module ts {
196
197
}
197
198
198
199
function declareModuleMember ( node : Declaration , symbolKind : SymbolFlags , symbolExcludes : SymbolFlags ) {
199
- var hasExportModifier = getCombinedNodeFlags ( node ) & NodeFlags . Export ;
200
+ let hasExportModifier = getCombinedNodeFlags ( node ) & NodeFlags . Export ;
200
201
if ( symbolKind & SymbolFlags . Alias ) {
201
202
if ( node . kind === SyntaxKind . ExportSpecifier || ( node . kind === SyntaxKind . ImportEqualsDeclaration && hasExportModifier ) ) {
202
203
declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
@@ -218,10 +219,10 @@ module ts {
218
219
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
219
220
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
220
221
if ( hasExportModifier || isAmbientContext ( container ) ) {
221
- var exportKind = ( symbolKind & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ) |
222
+ let exportKind = ( symbolKind & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ) |
222
223
( symbolKind & SymbolFlags . Type ? SymbolFlags . ExportType : 0 ) |
223
224
( symbolKind & SymbolFlags . Namespace ? SymbolFlags . ExportNamespace : 0 ) ;
224
- var local = declareSymbol ( container . locals , undefined , node , exportKind , symbolExcludes ) ;
225
+ let local = declareSymbol ( container . locals , undefined , node , exportKind , symbolExcludes ) ;
225
226
local . exportSymbol = declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
226
227
node . localSymbol = local ;
227
228
}
@@ -238,9 +239,9 @@ module ts {
238
239
node . locals = { } ;
239
240
}
240
241
241
- var saveParent = parent ;
242
- var saveContainer = container ;
243
- var savedBlockScopeContainer = blockScopeContainer ;
242
+ let saveParent = parent ;
243
+ let saveContainer = container ;
244
+ let savedBlockScopeContainer = blockScopeContainer ;
244
245
parent = node ;
245
246
if ( symbolKind & SymbolFlags . IsContainer ) {
246
247
container = node ;
@@ -315,7 +316,7 @@ module ts {
315
316
bindDeclaration ( node , SymbolFlags . ValueModule , SymbolFlags . ValueModuleExcludes , /*isBlockScopeContainer*/ true ) ;
316
317
}
317
318
else {
318
- var state = getModuleInstanceState ( node ) ;
319
+ let state = getModuleInstanceState ( node ) ;
319
320
if ( state === ModuleInstanceState . NonInstantiated ) {
320
321
bindDeclaration ( node , SymbolFlags . NamespaceModule , SymbolFlags . NamespaceModuleExcludes , /*isBlockScopeContainer*/ true ) ;
321
322
}
@@ -341,18 +342,18 @@ module ts {
341
342
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
342
343
// from an actual type literal symbol you would have gotten had you used the long form.
343
344
344
- var symbol = createSymbol ( SymbolFlags . Signature , getDeclarationName ( node ) ) ;
345
+ let symbol = createSymbol ( SymbolFlags . Signature , getDeclarationName ( node ) ) ;
345
346
addDeclarationToSymbol ( symbol , node , SymbolFlags . Signature ) ;
346
347
bindChildren ( node , SymbolFlags . Signature , /*isBlockScopeContainer:*/ false ) ;
347
348
348
- var typeLiteralSymbol = createSymbol ( SymbolFlags . TypeLiteral , "__type" ) ;
349
+ let typeLiteralSymbol = createSymbol ( SymbolFlags . TypeLiteral , "__type" ) ;
349
350
addDeclarationToSymbol ( typeLiteralSymbol , node , SymbolFlags . TypeLiteral ) ;
350
351
typeLiteralSymbol . members = { } ;
351
352
typeLiteralSymbol . members [ node . kind === SyntaxKind . FunctionType ? "__call" : "__new" ] = symbol
352
353
}
353
354
354
355
function bindAnonymousDeclaration ( node : Declaration , symbolKind : SymbolFlags , name : string , isBlockScopeContainer : boolean ) {
355
- var symbol = createSymbol ( symbolKind , name ) ;
356
+ let symbol = createSymbol ( symbolKind , name ) ;
356
357
addDeclarationToSymbol ( symbol , node , symbolKind ) ;
357
358
bindChildren ( node , symbolKind , isBlockScopeContainer ) ;
358
359
}
@@ -525,9 +526,9 @@ module ts {
525
526
// Otherwise this won't be considered as redeclaration of a block scoped local:
526
527
// function foo() {
527
528
// let x;
528
- // var x;
529
+ // let x;
529
530
// }
530
- // 'var x' will be placed into the function locals and 'let x' - into the locals of the block
531
+ // 'let x' will be placed into the function locals and 'let x' - into the locals of the block
531
532
bindChildren ( node , 0 , /*isBlockScopeContainer*/ ! isFunctionLike ( node . parent ) ) ;
532
533
break ;
533
534
case SyntaxKind . CatchClause :
@@ -538,7 +539,7 @@ module ts {
538
539
bindChildren ( node , 0 , /*isBlockScopeContainer*/ true ) ;
539
540
break ;
540
541
default :
541
- var saveParent = parent ;
542
+ let saveParent = parent ;
542
543
parent = node ;
543
544
forEachChild ( node , bind ) ;
544
545
parent = saveParent ;
@@ -559,7 +560,7 @@ module ts {
559
560
node . parent . kind === SyntaxKind . Constructor &&
560
561
node . parent . parent . kind === SyntaxKind . ClassDeclaration ) {
561
562
562
- var classDeclaration = < ClassDeclaration > node . parent . parent ;
563
+ let classDeclaration = < ClassDeclaration > node . parent . parent ;
563
564
declareSymbol ( classDeclaration . symbol . members , classDeclaration . symbol , node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
564
565
}
565
566
}
0 commit comments