@@ -254,13 +254,9 @@ namespace ts {
254
254
if ( some ( pendingExpressions ) ) {
255
255
statements . push ( createExpressionStatement ( inlineExpressions ( pendingExpressions ! ) ) ) ;
256
256
}
257
+ endPrivateNameEnvironment ( ) ;
257
258
pendingExpressions = savedPendingExpressions ;
258
259
259
- const privateNameExpressions = endPrivateNameEnvironment ( ) ;
260
- if ( some ( privateNameExpressions ) ) {
261
- statements . push ( createExpressionStatement ( inlineExpressions ( privateNameExpressions ) ) ) ;
262
- }
263
-
264
260
// Emit static property assignment. Because classDeclaration is lexically evaluated,
265
261
// it is safe to emit static property assignment after classDeclaration
266
262
// From ES6 specification:
@@ -277,6 +273,7 @@ namespace ts {
277
273
function visitClassExpression ( node : ClassExpression ) : Expression {
278
274
const savedPendingExpressions = pendingExpressions ;
279
275
pendingExpressions = undefined ;
276
+ startPrivateNameEnvironment ( ) ;
280
277
281
278
// If this class expression is a transformation of a decorated class declaration,
282
279
// then we want to output the pendingExpressions as statements, not as inlined
@@ -304,7 +301,7 @@ namespace ts {
304
301
if ( isDecoratedClassDeclaration ) {
305
302
Debug . assertDefined ( pendingStatements , "Decorated classes transformed by TypeScript are expected to be within a variable declaration." ) ;
306
303
307
- // Write any pending expressions from elided or moved computed property names
304
+ // Write any pending expressions from elided or moved computed property names or private names
308
305
if ( some ( pendingExpressions ) ) {
309
306
pendingStatements ! . push ( createExpressionStatement ( inlineExpressions ( pendingExpressions ! ) ) ) ;
310
307
}
@@ -313,6 +310,7 @@ namespace ts {
313
310
if ( some ( staticProperties ) ) {
314
311
addInitializedPropertyStatements ( pendingStatements ! , staticProperties , getInternalName ( node ) ) ;
315
312
}
313
+ endPrivateNameEnvironment ( ) ;
316
314
return classExpression ;
317
315
}
318
316
else {
@@ -337,11 +335,13 @@ namespace ts {
337
335
expressions . push ( startOnNewLine ( temp ) ) ;
338
336
339
337
pendingExpressions = savedPendingExpressions ;
338
+ endPrivateNameEnvironment ( ) ;
340
339
return inlineExpressions ( expressions ) ;
341
340
}
342
341
}
343
342
344
343
pendingExpressions = savedPendingExpressions ;
344
+ endPrivateNameEnvironment ( ) ;
345
345
return classExpression ;
346
346
}
347
347
@@ -508,36 +508,26 @@ namespace ts {
508
508
return env ;
509
509
}
510
510
511
- function endPrivateNameEnvironment ( ) : Expression [ ] {
512
- const env = privateNameEnvironmentStack . pop ( ) ;
513
- Debug . assertDefined ( env , "Tried to end private name environment that does not exist." ) ;
514
- const initializers : Expression [ ] = [ ] ;
515
- forEachEntry ( env ! , ( privateName ) => {
516
- switch ( privateName . type ) {
517
- case PrivateNameType . InstanceField : {
518
- hoistVariableDeclaration ( privateName . weakMapName ) ;
519
- initializers . push (
520
- createAssignment (
521
- privateName . weakMapName ,
522
- createNew (
523
- createIdentifier ( "WeakMap" ) ,
524
- /*typeArguments*/ undefined ,
525
- [ ]
526
- )
527
- )
528
- ) ;
529
- break ;
530
- }
531
- }
532
- } ) ;
533
- return initializers ;
511
+ function endPrivateNameEnvironment ( ) {
512
+ privateNameEnvironmentStack . pop ( ) ;
534
513
}
535
514
536
515
function addPrivateNameToEnvironment ( name : PrivateName ) {
537
516
const env = last ( privateNameEnvironmentStack ) ;
538
517
const text = getTextOfPropertyName ( name ) as string ;
539
518
const weakMapName = createFileLevelUniqueName ( "_" + text . substring ( 1 ) ) ;
519
+ hoistVariableDeclaration ( weakMapName ) ;
540
520
env . set ( name . escapedText , { type : PrivateNameType . InstanceField , weakMapName } ) ;
521
+ ( pendingExpressions || ( pendingExpressions = [ ] ) ) . push (
522
+ createAssignment (
523
+ weakMapName ,
524
+ createNew (
525
+ createIdentifier ( "WeakMap" ) ,
526
+ /*typeArguments*/ undefined ,
527
+ [ ]
528
+ )
529
+ )
530
+ ) ;
541
531
}
542
532
543
533
function enableSubstitutionForClassAliases ( ) {
0 commit comments