@@ -149,7 +149,7 @@ namespace ts {
149
149
if ( capturedSuperProperties && isPropertyAccessExpression ( node ) && node . expression . kind === SyntaxKind . SuperKeyword ) {
150
150
capturedSuperProperties . set ( node . name . escapedText , true ) ;
151
151
}
152
- return visitEachChild ( node , visitor , context ) ;
152
+ return visitPropertyAccessExpression ( node as PropertyAccessExpression ) ;
153
153
case SyntaxKind . ElementAccessExpression :
154
154
if ( capturedSuperProperties && ( < ElementAccessExpression > node ) . expression . kind === SyntaxKind . SuperKeyword ) {
155
155
hasSuperElementAccess = true ;
@@ -583,6 +583,29 @@ namespace ts {
583
583
return undefined ;
584
584
}
585
585
586
+ function visitPropertyAccessExpression ( node : PropertyAccessExpression ) {
587
+ if ( isPrivateName ( node . name ) ) {
588
+ const privateNameInfo = accessPrivateName ( node . name ) ;
589
+ if ( privateNameInfo ) {
590
+ switch ( privateNameInfo . type ) {
591
+ case PrivateNameType . InstanceField :
592
+ return setOriginalNode (
593
+ setTextRange (
594
+ createClassPrivateFieldGetHelper (
595
+ context ,
596
+ visitNode ( node . expression , visitor , isExpression ) ,
597
+ privateNameInfo . weakMapName
598
+ ) ,
599
+ node
600
+ ) ,
601
+ node
602
+ ) ;
603
+ }
604
+ }
605
+ }
606
+ return visitEachChild ( node , visitor , context ) ;
607
+ }
608
+
586
609
function enableSubstitutionForClassAliases ( ) {
587
610
if ( ( enabledSubstitutions & ESNextSubstitutionFlags . ClassAliases ) === 0 ) {
588
611
enabledSubstitutions |= ESNextSubstitutionFlags . ClassAliases ;
@@ -1583,4 +1606,15 @@ namespace ts {
1583
1606
location
1584
1607
) ;
1585
1608
}
1609
+
1610
+ const classPrivateFieldGetHelper : EmitHelper = {
1611
+ name : "typescript:classPrivateFieldGet" ,
1612
+ scoped : false ,
1613
+ text : `var _classPrivateFieldGet = function (receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); };`
1614
+ } ;
1615
+
1616
+ function createClassPrivateFieldGetHelper ( context : TransformationContext , receiver : Expression , privateField : Identifier ) {
1617
+ context . requestEmitHelper ( classPrivateFieldGetHelper ) ;
1618
+ return createCall ( getHelperName ( "_classPrivateFieldGet" ) , /* typeArguments */ undefined , [ receiver , privateField ] ) ;
1619
+ }
1586
1620
}
0 commit comments