@@ -149,6 +149,8 @@ namespace ts {
149
149
return visitVariableStatement ( node as VariableStatement ) ;
150
150
case SyntaxKind . ComputedPropertyName :
151
151
return visitComputedPropertyName ( node as ComputedPropertyName ) ;
152
+ case SyntaxKind . PropertyAccessExpression :
153
+ return visitPropertyAccessExpression ( node as PropertyAccessExpression ) ;
152
154
default :
153
155
return visitEachChild ( node , visitor , context ) ;
154
156
}
@@ -556,6 +558,19 @@ namespace ts {
556
558
return undefined ;
557
559
}
558
560
561
+ function visitPropertyAccessExpression ( node : PropertyAccessExpression ) {
562
+ if ( isPrivateName ( node . name ) ) {
563
+ const privateNameInfo = accessPrivateName ( node . name ) ;
564
+ if ( privateNameInfo ) {
565
+ switch ( privateNameInfo . type ) {
566
+ case PrivateNameType . InstanceField :
567
+ return createClassPrivateFieldGetHelper ( context , node . expression , privateNameInfo . weakMapName ) ;
568
+ }
569
+ }
570
+ }
571
+ return node ;
572
+ }
573
+
559
574
function enableSubstitutionForClassAliases ( ) {
560
575
if ( ( enabledSubstitutions & ESNextSubstitutionFlags . ClassAliases ) === 0 ) {
561
576
enabledSubstitutions |= ESNextSubstitutionFlags . ClassAliases ;
@@ -1528,4 +1543,15 @@ namespace ts {
1528
1543
location
1529
1544
) ;
1530
1545
}
1546
+
1547
+ const classPrivateFieldGetHelper : EmitHelper = {
1548
+ name : "typescript:classPrivateFieldGet" ,
1549
+ scoped : false ,
1550
+ 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); };`
1551
+ } ;
1552
+
1553
+ function createClassPrivateFieldGetHelper ( context : TransformationContext , receiver : Expression , privateField : Identifier ) {
1554
+ context . requestEmitHelper ( classPrivateFieldGetHelper ) ;
1555
+ return createCall ( getHelperName ( "_classPrivateFieldGet" ) , /* typeArguments */ undefined , [ receiver , privateField ] ) ;
1556
+ }
1531
1557
}
0 commit comments