@@ -1733,26 +1733,15 @@ namespace ts {
17331733 increaseIndent ( ) ;
17341734 }
17351735
1736- if ( getEmitFlags ( node ) & EmitFlags . ReuseTempVariableScope ) {
1737- emitSignatureHead ( node ) ;
1738- if ( onEmitNode ) {
1739- onEmitNode ( EmitHint . Unspecified , body , emitBlockCallback ) ;
1740- }
1741- else {
1742- emitBlockFunctionBody ( body ) ;
1743- }
1736+ pushNameGenerationScope ( node ) ;
1737+ emitSignatureHead ( node ) ;
1738+ if ( onEmitNode ) {
1739+ onEmitNode ( EmitHint . Unspecified , body , emitBlockCallback ) ;
17441740 }
17451741 else {
1746- pushNameGenerationScope ( ) ;
1747- emitSignatureHead ( node ) ;
1748- if ( onEmitNode ) {
1749- onEmitNode ( EmitHint . Unspecified , body , emitBlockCallback ) ;
1750- }
1751- else {
1752- emitBlockFunctionBody ( body ) ;
1753- }
1754- popNameGenerationScope ( ) ;
1742+ emitBlockFunctionBody ( body ) ;
17551743 }
1744+ popNameGenerationScope ( node ) ;
17561745
17571746 if ( indentedFlag ) {
17581747 decreaseIndent ( ) ;
@@ -1871,11 +1860,9 @@ namespace ts {
18711860 emitTypeParameters ( node , node . typeParameters ) ;
18721861 emitList ( node , node . heritageClauses , ListFormat . ClassHeritageClauses ) ;
18731862
1874- pushNameGenerationScope ( ) ;
18751863 write ( " {" ) ;
18761864 emitList ( node , node . members , ListFormat . ClassMembers ) ;
18771865 write ( "}" ) ;
1878- popNameGenerationScope ( ) ;
18791866
18801867 if ( indentedFlag ) {
18811868 decreaseIndent ( ) ;
@@ -1909,11 +1896,9 @@ namespace ts {
19091896 emitModifiers ( node , node . modifiers ) ;
19101897 write ( "enum " ) ;
19111898 emit ( node . name ) ;
1912- pushNameGenerationScope ( ) ;
19131899 write ( " {" ) ;
19141900 emitList ( node , node . members , ListFormat . EnumMembers ) ;
19151901 write ( "}" ) ;
1916- popNameGenerationScope ( ) ;
19171902 }
19181903
19191904 function emitModuleDeclaration ( node : ModuleDeclaration ) {
@@ -1935,11 +1920,11 @@ namespace ts {
19351920 }
19361921
19371922 function emitModuleBlock ( node : ModuleBlock ) {
1938- pushNameGenerationScope ( ) ;
1923+ pushNameGenerationScope ( node ) ;
19391924 write ( "{" ) ;
19401925 emitBlockStatements ( node , /*forceSingleLine*/ isEmptyBlock ( node ) ) ;
19411926 write ( "}" ) ;
1942- popNameGenerationScope ( ) ;
1927+ popNameGenerationScope ( node ) ;
19431928 }
19441929
19451930 function emitCaseBlock ( node : CaseBlock ) {
@@ -2284,11 +2269,11 @@ namespace ts {
22842269
22852270 function emitSourceFileWorker ( node : SourceFile ) {
22862271 const statements = node . statements ;
2287- pushNameGenerationScope ( ) ;
2272+ pushNameGenerationScope ( node ) ;
22882273 emitHelpersIndirect ( node ) ;
22892274 const index = findIndex ( statements , statement => ! isPrologueDirective ( statement ) ) ;
22902275 emitList ( node , statements , ListFormat . MultiLine , index === - 1 ? statements . length : index ) ;
2291- popNameGenerationScope ( ) ;
2276+ popNameGenerationScope ( node ) ;
22922277 }
22932278
22942279 // Transformation nodes
@@ -2751,7 +2736,7 @@ namespace ts {
27512736 }
27522737 }
27532738 else {
2754- return nextNode . startsOnNewLine ;
2739+ return getStartsOnNewLine ( nextNode ) ;
27552740 }
27562741 }
27572742
@@ -2782,7 +2767,7 @@ namespace ts {
27822767
27832768 function synthesizedNodeStartsOnNewLine ( node : Node , format ?: ListFormat ) {
27842769 if ( nodeIsSynthesized ( node ) ) {
2785- const startsOnNewLine = node . startsOnNewLine ;
2770+ const startsOnNewLine = getStartsOnNewLine ( node ) ;
27862771 if ( startsOnNewLine === undefined ) {
27872772 return ( format & ListFormat . PreferNewLine ) !== 0 ;
27882773 }
@@ -2799,7 +2784,7 @@ namespace ts {
27992784 node2 = skipSynthesizedParentheses ( node2 ) ;
28002785
28012786 // Always use a newline for synthesized code if the synthesizer desires it.
2802- if ( node2 . startsOnNewLine ) {
2787+ if ( getStartsOnNewLine ( node2 ) ) {
28032788 return true ;
28042789 }
28052790
@@ -2858,15 +2843,21 @@ namespace ts {
28582843 /**
28592844 * Push a new name generation scope.
28602845 */
2861- function pushNameGenerationScope ( ) {
2846+ function pushNameGenerationScope ( node : Node | undefined ) {
2847+ if ( node && getEmitFlags ( node ) & EmitFlags . ReuseTempVariableScope ) {
2848+ return ;
2849+ }
28622850 tempFlagsStack . push ( tempFlags ) ;
28632851 tempFlags = 0 ;
28642852 }
28652853
28662854 /**
28672855 * Pop the current name generation scope.
28682856 */
2869- function popNameGenerationScope ( ) {
2857+ function popNameGenerationScope ( node : Node | undefined ) {
2858+ if ( node && getEmitFlags ( node ) & EmitFlags . ReuseTempVariableScope ) {
2859+ return ;
2860+ }
28702861 tempFlags = tempFlagsStack . pop ( ) ;
28712862 }
28722863
@@ -2877,8 +2868,17 @@ namespace ts {
28772868 if ( name . autoGenerateKind === GeneratedIdentifierKind . Node ) {
28782869 // Node names generate unique names based on their original node
28792870 // and are cached based on that node's id.
2880- const node = getNodeForGeneratedName ( name ) ;
2881- return generateNameCached ( node ) ;
2871+ if ( name . skipNameGenerationScope ) {
2872+ const savedTempFlags = tempFlags ;
2873+ popNameGenerationScope ( /*node*/ undefined ) ;
2874+ const result = generateNameCached ( getNodeForGeneratedName ( name ) ) ;
2875+ pushNameGenerationScope ( /*node*/ undefined ) ;
2876+ tempFlags = savedTempFlags ;
2877+ return result ;
2878+ }
2879+ else {
2880+ return generateNameCached ( getNodeForGeneratedName ( name ) ) ;
2881+ }
28822882 }
28832883 else {
28842884 // Auto, Loop, and Unique names are cached based on their unique
0 commit comments