@@ -92,6 +92,8 @@ namespace ts {
9292 let lexicalEnvironmentFunctionDeclarations : FunctionDeclaration [ ] ;
9393 let lexicalEnvironmentVariableDeclarationsStack : VariableDeclaration [ ] [ ] = [ ] ;
9494 let lexicalEnvironmentFunctionDeclarationsStack : FunctionDeclaration [ ] [ ] = [ ] ;
95+ let lexicalEnvironmentScopingStack : LexicalEnvironmentScoping [ ] = [ ] ;
96+ let lexicalEnvironmentScoping : LexicalEnvironmentScoping ;
9597 let lexicalEnvironmentStackOffset = 0 ;
9698 let lexicalEnvironmentSuspended = false ;
9799 let emitHelpers : EmitHelper [ ] | undefined ;
@@ -266,7 +268,7 @@ namespace ts {
266268 * Starts a new lexical environment. Any existing hoisted variable or function declarations
267269 * are pushed onto a stack, and the related storage variables are reset.
268270 */
269- function startLexicalEnvironment ( ) : void {
271+ function startLexicalEnvironment ( scoping : LexicalEnvironmentScoping = LexicalEnvironmentScoping . Function ) : void {
270272 Debug . assert ( state > TransformationState . Uninitialized , "Cannot modify the lexical environment during initialization." ) ;
271273 Debug . assert ( state < TransformationState . Completed , "Cannot modify the lexical environment after transformation has completed." ) ;
272274 Debug . assert ( ! lexicalEnvironmentSuspended , "Lexical environment is suspended." ) ;
@@ -275,11 +277,13 @@ namespace ts {
275277 // stack size variable. This allows us to reuse existing array slots we've
276278 // already allocated between transformations to avoid allocation and GC overhead during
277279 // transformation.
280+ lexicalEnvironmentScopingStack [ lexicalEnvironmentStackOffset ] = lexicalEnvironmentScoping ;
278281 lexicalEnvironmentVariableDeclarationsStack [ lexicalEnvironmentStackOffset ] = lexicalEnvironmentVariableDeclarations ;
279282 lexicalEnvironmentFunctionDeclarationsStack [ lexicalEnvironmentStackOffset ] = lexicalEnvironmentFunctionDeclarations ;
280283 lexicalEnvironmentStackOffset ++ ;
281284 lexicalEnvironmentVariableDeclarations = undefined ! ;
282285 lexicalEnvironmentFunctionDeclarations = undefined ! ;
286+ lexicalEnvironmentScoping = scoping ;
283287 }
284288
285289 /** Suspends the current lexical environment, usually after visiting a parameter list. */
@@ -316,7 +320,10 @@ namespace ts {
316320 if ( lexicalEnvironmentVariableDeclarations ) {
317321 const statement = createVariableStatement (
318322 /*modifiers*/ undefined ,
319- createVariableDeclarationList ( lexicalEnvironmentVariableDeclarations )
323+ createVariableDeclarationList (
324+ lexicalEnvironmentVariableDeclarations ,
325+ lexicalEnvironmentScoping === LexicalEnvironmentScoping . Block ? NodeFlags . Let : undefined
326+ )
320327 ) ;
321328
322329 if ( ! statements ) {
@@ -332,9 +339,11 @@ namespace ts {
332339 lexicalEnvironmentStackOffset -- ;
333340 lexicalEnvironmentVariableDeclarations = lexicalEnvironmentVariableDeclarationsStack [ lexicalEnvironmentStackOffset ] ;
334341 lexicalEnvironmentFunctionDeclarations = lexicalEnvironmentFunctionDeclarationsStack [ lexicalEnvironmentStackOffset ] ;
342+ lexicalEnvironmentScoping = lexicalEnvironmentScopingStack [ lexicalEnvironmentStackOffset ] ;
335343 if ( lexicalEnvironmentStackOffset === 0 ) {
336344 lexicalEnvironmentVariableDeclarationsStack = [ ] ;
337345 lexicalEnvironmentFunctionDeclarationsStack = [ ] ;
346+ lexicalEnvironmentScopingStack = [ ] ;
338347 }
339348 return statements ;
340349 }
@@ -366,6 +375,7 @@ namespace ts {
366375 lexicalEnvironmentVariableDeclarationsStack = undefined ! ;
367376 lexicalEnvironmentFunctionDeclarations = undefined ! ;
368377 lexicalEnvironmentFunctionDeclarationsStack = undefined ! ;
378+ lexicalEnvironmentScopingStack = undefined ! ;
369379 onSubstituteNode = undefined ! ;
370380 onEmitNode = undefined ! ;
371381 emitHelpers = undefined ;
0 commit comments