@@ -270,13 +270,9 @@ namespace ts {
270
270
if ( some ( pendingExpressions ) ) {
271
271
statements . push ( createExpressionStatement ( inlineExpressions ( pendingExpressions ! ) ) ) ;
272
272
}
273
+ endPrivateNameEnvironment ( ) ;
273
274
pendingExpressions = savedPendingExpressions ;
274
275
275
- const privateNameExpressions = endPrivateNameEnvironment ( ) ;
276
- if ( some ( privateNameExpressions ) ) {
277
- statements . push ( createExpressionStatement ( inlineExpressions ( privateNameExpressions ) ) ) ;
278
- }
279
-
280
276
// Emit static property assignment. Because classDeclaration is lexically evaluated,
281
277
// it is safe to emit static property assignment after classDeclaration
282
278
// From ES6 specification:
@@ -293,6 +289,7 @@ namespace ts {
293
289
function visitClassExpression ( node : ClassExpression ) : Expression {
294
290
const savedPendingExpressions = pendingExpressions ;
295
291
pendingExpressions = undefined ;
292
+ startPrivateNameEnvironment ( ) ;
296
293
297
294
// If this class expression is a transformation of a decorated class declaration,
298
295
// then we want to output the pendingExpressions as statements, not as inlined
@@ -320,7 +317,7 @@ namespace ts {
320
317
if ( isDecoratedClassDeclaration ) {
321
318
Debug . assertDefined ( pendingStatements , "Decorated classes transformed by TypeScript are expected to be within a variable declaration." ) ;
322
319
323
- // Write any pending expressions from elided or moved computed property names
320
+ // Write any pending expressions from elided or moved computed property names or private names
324
321
if ( some ( pendingExpressions ) ) {
325
322
pendingStatements ! . push ( createExpressionStatement ( inlineExpressions ( pendingExpressions ! ) ) ) ;
326
323
}
@@ -329,6 +326,7 @@ namespace ts {
329
326
if ( some ( staticProperties ) ) {
330
327
addInitializedPropertyStatements ( pendingStatements ! , staticProperties , getInternalName ( node ) ) ;
331
328
}
329
+ endPrivateNameEnvironment ( ) ;
332
330
return classExpression ;
333
331
}
334
332
else {
@@ -353,11 +351,13 @@ namespace ts {
353
351
expressions . push ( startOnNewLine ( temp ) ) ;
354
352
355
353
pendingExpressions = savedPendingExpressions ;
354
+ endPrivateNameEnvironment ( ) ;
356
355
return inlineExpressions ( expressions ) ;
357
356
}
358
357
}
359
358
360
359
pendingExpressions = savedPendingExpressions ;
360
+ endPrivateNameEnvironment ( ) ;
361
361
return classExpression ;
362
362
}
363
363
@@ -525,36 +525,26 @@ namespace ts {
525
525
return env ;
526
526
}
527
527
528
- function endPrivateNameEnvironment ( ) : Expression [ ] {
529
- const env = privateNameEnvironmentStack . pop ( ) ;
530
- Debug . assertDefined ( env , "Tried to end private name environment that does not exist." ) ;
531
- const initializers : Expression [ ] = [ ] ;
532
- forEachEntry ( env ! , ( privateName ) => {
533
- switch ( privateName . type ) {
534
- case PrivateNameType . InstanceField : {
535
- hoistVariableDeclaration ( privateName . weakMapName ) ;
536
- initializers . push (
537
- createAssignment (
538
- privateName . weakMapName ,
539
- createNew (
540
- createIdentifier ( "WeakMap" ) ,
541
- /*typeArguments*/ undefined ,
542
- [ ]
543
- )
544
- )
545
- ) ;
546
- break ;
547
- }
548
- }
549
- } ) ;
550
- return initializers ;
528
+ function endPrivateNameEnvironment ( ) {
529
+ privateNameEnvironmentStack . pop ( ) ;
551
530
}
552
531
553
532
function addPrivateNameToEnvironment ( name : PrivateName ) {
554
533
const env = last ( privateNameEnvironmentStack ) ;
555
534
const text = getTextOfPropertyName ( name ) as string ;
556
535
const weakMapName = createFileLevelUniqueName ( "_" + text . substring ( 1 ) ) ;
536
+ hoistVariableDeclaration ( weakMapName ) ;
557
537
env . set ( name . escapedText , { type : PrivateNameType . InstanceField , weakMapName } ) ;
538
+ ( pendingExpressions || ( pendingExpressions = [ ] ) ) . push (
539
+ createAssignment (
540
+ weakMapName ,
541
+ createNew (
542
+ createIdentifier ( "WeakMap" ) ,
543
+ /*typeArguments*/ undefined ,
544
+ [ ]
545
+ )
546
+ )
547
+ ) ;
558
548
}
559
549
560
550
function enableSubstitutionForClassAliases ( ) {
0 commit comments