@@ -414,17 +414,8 @@ namespace ts {
414
414
const containsPropertyInitializer = forEach ( node . members , isInitializedProperty ) ;
415
415
let body = constructor ? constructor . body : undefined ;
416
416
let parameters = constructor ? constructor . parameters : undefined ;
417
- const shouldTransformConstructorBody = containsPropertyInitializer || declaresPrivateNames ;
418
- if ( shouldTransformConstructorBody ) {
419
- if ( containsPropertyInitializer ) {
420
- parameters = visitParameterList ( constructor ? constructor . parameters : undefined , visitor , context ) ;
421
- }
422
- else {
423
- // provide a scope for hoisted declarations for WeakSet or WeakMap for private name brand checks
424
- // not needed if `visitParameterList` was called, because that starts/suspends the lexical environment
425
- context . startLexicalEnvironment ( ) ;
426
- context . suspendLexicalEnvironment ( ) ;
427
- }
417
+ if ( containsPropertyInitializer || declaresPrivateNames ) {
418
+ parameters = visitParameterList ( constructor ? constructor . parameters : undefined , visitor , context ) ;
428
419
body = transformConstructorBody ( node , constructor , isDerivedClass , declaresPrivateNames ) ;
429
420
}
430
421
if ( ! body ) {
@@ -486,22 +477,11 @@ namespace ts {
486
477
indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall ( constructor , statements , visitor ) ;
487
478
}
488
479
489
- // Add the property initializers. Transforms this:
490
- //
491
- // public x = 1;
492
- //
493
- // Into this:
494
- //
495
- // constructor() {
496
- // this.x = 1;
497
- // }
498
- //
499
- addInitializedPropertyStatements ( statements , properties , createThis ( ) ) ;
500
480
if ( classDeclaresPrivateNames ) {
501
481
last ( privateNameEnvironmentStack ) . forEach ( ( { placement, accumulator } ) => {
502
482
switch ( placement ) {
503
483
case PrivateNamePlacement . InstanceField :
504
- // TODO: instance field add accumulator
484
+ // handled in addInitializedPropertyStatements
505
485
break ;
506
486
case PrivateNamePlacement . InstanceMethod :
507
487
statements . push (
@@ -517,6 +497,17 @@ namespace ts {
517
497
}
518
498
} ) ;
519
499
}
500
+ // Add the property initializers. Transforms this:
501
+ //
502
+ // public x = 1;
503
+ //
504
+ // Into this:
505
+ //
506
+ // constructor() {
507
+ // this.x = 1;
508
+ // }
509
+ //
510
+ addInitializedPropertyStatements ( statements , properties , createThis ( ) ) ;
520
511
521
512
// Add existing statements, skipping the initial super call.
522
513
if ( constructor ) {
@@ -705,21 +696,18 @@ namespace ts {
705
696
function visitPropertyAccessExpression ( node : PropertyAccessExpression ) {
706
697
if ( isPrivateName ( node . name ) ) {
707
698
const privateNameInfo = accessPrivateName ( node . name ) ;
708
- if ( privateNameInfo ) {
709
- switch ( privateNameInfo . placement ) {
710
- case PrivateNamePlacement . InstanceField :
711
- return setOriginalNode (
712
- setTextRange (
713
- createClassPrivateFieldGetHelper (
714
- context ,
715
- visitNode ( node . expression , visitor , isExpression ) ,
716
- privateNameInfo . accumulator
717
- ) ,
718
- node
719
- ) ,
720
- node
721
- ) ;
722
- }
699
+ if ( privateNameInfo && privateNameInfo . placement === PrivateNamePlacement . InstanceField ) {
700
+ return setOriginalNode (
701
+ setTextRange (
702
+ createClassPrivateFieldGetHelper (
703
+ context ,
704
+ visitNode ( node . expression , visitor , isExpression ) ,
705
+ privateNameInfo . accumulator
706
+ ) ,
707
+ node
708
+ ) ,
709
+ node
710
+ ) ;
723
711
}
724
712
}
725
713
return visitEachChild ( node , visitor , context ) ;
@@ -808,7 +796,9 @@ namespace ts {
808
796
) ;
809
797
receiver = generatedName ;
810
798
}
811
- const privateNameEntry = last ( privateNameEnvironmentStack ) . get ( node . expression . name . escapedText ) ;
799
+ const privateNameEntry = privateNameEnvironmentStack . length
800
+ ? last ( privateNameEnvironmentStack ) . get ( node . expression . name . escapedText )
801
+ : undefined ;
812
802
if ( privateNameEntry && privateNameEntry . placement === PrivateNamePlacement . InstanceMethod ) {
813
803
return setOriginalNode (
814
804
setTextRange (
0 commit comments