@@ -165,6 +165,8 @@ namespace ts {
165
165
return visitVariableStatement ( node as VariableStatement ) ;
166
166
case SyntaxKind . ComputedPropertyName :
167
167
return visitComputedPropertyName ( node as ComputedPropertyName ) ;
168
+ case SyntaxKind . PropertyAccessExpression :
169
+ return visitPropertyAccessExpression ( node as PropertyAccessExpression ) ;
168
170
default :
169
171
return visitEachChild ( node , visitor , context ) ;
170
172
}
@@ -573,6 +575,19 @@ namespace ts {
573
575
return undefined ;
574
576
}
575
577
578
+ function visitPropertyAccessExpression ( node : PropertyAccessExpression ) {
579
+ if ( isPrivateName ( node . name ) ) {
580
+ const privateNameInfo = accessPrivateName ( node . name ) ;
581
+ if ( privateNameInfo ) {
582
+ switch ( privateNameInfo . type ) {
583
+ case PrivateNameType . InstanceField :
584
+ return createClassPrivateFieldGetHelper ( context , node . expression , privateNameInfo . weakMapName ) ;
585
+ }
586
+ }
587
+ }
588
+ return node ;
589
+ }
590
+
576
591
function enableSubstitutionForClassAliases ( ) {
577
592
if ( ( enabledSubstitutions & ESNextSubstitutionFlags . ClassAliases ) === 0 ) {
578
593
enabledSubstitutions |= ESNextSubstitutionFlags . ClassAliases ;
@@ -1573,4 +1588,15 @@ namespace ts {
1573
1588
location
1574
1589
) ;
1575
1590
}
1591
+
1592
+ const classPrivateFieldGetHelper : EmitHelper = {
1593
+ name : "typescript:classPrivateFieldGet" ,
1594
+ scoped : false ,
1595
+ 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); };`
1596
+ } ;
1597
+
1598
+ function createClassPrivateFieldGetHelper ( context : TransformationContext , receiver : Expression , privateField : Identifier ) {
1599
+ context . requestEmitHelper ( classPrivateFieldGetHelper ) ;
1600
+ return createCall ( getHelperName ( "_classPrivateFieldGet" ) , /* typeArguments */ undefined , [ receiver , privateField ] ) ;
1601
+ }
1576
1602
}
0 commit comments