@@ -163,6 +163,7 @@ namespace ts {
163
163
let currentText : string ;
164
164
let currentParent : Node ;
165
165
let currentNode : Node ;
166
+ let enclosingVariableStatement : VariableStatement ;
166
167
let enclosingBlockScopeContainer : Node ;
167
168
let enclosingBlockScopeContainerParent : Node ;
168
169
let containingNonArrowFunction : FunctionLikeDeclaration | ClassElement ;
@@ -210,6 +211,7 @@ namespace ts {
210
211
const savedSuperScopeContainer = superScopeContainer ;
211
212
const savedCurrentParent = currentParent ;
212
213
const savedCurrentNode = currentNode ;
214
+ const savedEnclosingVariableStatement = enclosingVariableStatement ;
213
215
const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer ;
214
216
const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent ;
215
217
@@ -227,6 +229,7 @@ namespace ts {
227
229
superScopeContainer = savedSuperScopeContainer ;
228
230
currentParent = savedCurrentParent ;
229
231
currentNode = savedCurrentNode ;
232
+ enclosingVariableStatement = savedEnclosingVariableStatement ;
230
233
enclosingBlockScopeContainer = savedEnclosingBlockScopeContainer ;
231
234
enclosingBlockScopeContainerParent = savedEnclosingBlockScopeContainerParent ;
232
235
return visited ;
@@ -320,7 +323,7 @@ namespace ts {
320
323
return visitFunctionExpression ( < FunctionExpression > node ) ;
321
324
322
325
case SyntaxKind . VariableDeclaration :
323
- return visitVariableDeclaration ( < VariableDeclaration > node , /*offset*/ undefined ) ;
326
+ return visitVariableDeclaration ( < VariableDeclaration > node ) ;
324
327
325
328
case SyntaxKind . Identifier :
326
329
return visitIdentifier ( < Identifier > node ) ;
@@ -432,6 +435,25 @@ namespace ts {
432
435
}
433
436
break ;
434
437
}
438
+
439
+ // keep track of the enclosing variable statement when in the context of
440
+ // variable statements, variable declarations, binding elements, and binding
441
+ // patterns.
442
+ switch ( currentParent . kind ) {
443
+ case SyntaxKind . VariableStatement :
444
+ enclosingVariableStatement = < VariableStatement > currentParent ;
445
+ break ;
446
+
447
+ case SyntaxKind . VariableDeclarationList :
448
+ case SyntaxKind . VariableDeclaration :
449
+ case SyntaxKind . BindingElement :
450
+ case SyntaxKind . ObjectBindingPattern :
451
+ case SyntaxKind . ArrayBindingPattern :
452
+ break ;
453
+
454
+ default :
455
+ enclosingVariableStatement = undefined ;
456
+ }
435
457
}
436
458
}
437
459
@@ -1334,7 +1356,7 @@ namespace ts {
1334
1356
return setOriginalNode (
1335
1357
createFunctionDeclaration (
1336
1358
/*decorators*/ undefined ,
1337
- /* modifiers*/ undefined ,
1359
+ node . modifiers ,
1338
1360
node . asteriskToken ,
1339
1361
node . name ,
1340
1362
/*typeParameters*/ undefined ,
@@ -1663,13 +1685,13 @@ namespace ts {
1663
1685
*
1664
1686
* @param node A VariableDeclaration node.
1665
1687
*/
1666
- function visitVariableDeclarationInLetDeclarationList ( node : VariableDeclaration , offset : number ) {
1688
+ function visitVariableDeclarationInLetDeclarationList ( node : VariableDeclaration ) {
1667
1689
// For binding pattern names that lack initializers there is no point to emit
1668
1690
// explicit initializer since downlevel codegen for destructuring will fail
1669
1691
// in the absence of initializer so all binding elements will say uninitialized
1670
1692
const name = node . name ;
1671
1693
if ( isBindingPattern ( name ) ) {
1672
- return visitVariableDeclaration ( node , offset ) ;
1694
+ return visitVariableDeclaration ( node ) ;
1673
1695
}
1674
1696
1675
1697
if ( ! node . initializer && shouldEmitExplicitInitializerForLetDeclaration ( node ) ) {
@@ -1686,10 +1708,13 @@ namespace ts {
1686
1708
*
1687
1709
* @param node A VariableDeclaration node.
1688
1710
*/
1689
- function visitVariableDeclaration ( node : VariableDeclaration , offset : number ) : VisitResult < VariableDeclaration > {
1711
+ function visitVariableDeclaration ( node : VariableDeclaration ) : VisitResult < VariableDeclaration > {
1690
1712
// If we are here it is because the name contains a binding pattern.
1691
1713
if ( isBindingPattern ( node . name ) ) {
1692
- return flattenVariableDestructuring ( context , node , /*value*/ undefined , visitor ) ;
1714
+ const recordTempVariablesInLine = ! enclosingVariableStatement
1715
+ || ! hasModifier ( enclosingVariableStatement , ModifierFlags . Export ) ;
1716
+ return flattenVariableDestructuring ( context , node , /*value*/ undefined , visitor ,
1717
+ recordTempVariablesInLine ? undefined : hoistVariableDeclaration ) ;
1693
1718
}
1694
1719
1695
1720
return visitEachChild ( node , visitor , context ) ;
0 commit comments