@@ -165,6 +165,8 @@ namespace ts {
165165 return visitVariableStatement ( node as VariableStatement ) ;
166166 case SyntaxKind . ComputedPropertyName :
167167 return visitComputedPropertyName ( node as ComputedPropertyName ) ;
168+ case SyntaxKind . PropertyAccessExpression :
169+ return visitPropertyAccessExpression ( node as PropertyAccessExpression ) ;
168170 default :
169171 return visitEachChild ( node , visitor , context ) ;
170172 }
@@ -573,6 +575,19 @@ namespace ts {
573575 return undefined ;
574576 }
575577
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+
576591 function enableSubstitutionForClassAliases ( ) {
577592 if ( ( enabledSubstitutions & ESNextSubstitutionFlags . ClassAliases ) === 0 ) {
578593 enabledSubstitutions |= ESNextSubstitutionFlags . ClassAliases ;
@@ -1573,4 +1588,15 @@ namespace ts {
15731588 location
15741589 ) ;
15751590 }
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+ }
15761602}
0 commit comments