@@ -149,6 +149,8 @@ namespace ts {
149149 return visitVariableStatement ( node as VariableStatement ) ;
150150 case SyntaxKind . ComputedPropertyName :
151151 return visitComputedPropertyName ( node as ComputedPropertyName ) ;
152+ case SyntaxKind . PropertyAccessExpression :
153+ return visitPropertyAccessExpression ( node as PropertyAccessExpression ) ;
152154 default :
153155 return visitEachChild ( node , visitor , context ) ;
154156 }
@@ -556,6 +558,19 @@ namespace ts {
556558 return undefined ;
557559 }
558560
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+
559574 function enableSubstitutionForClassAliases ( ) {
560575 if ( ( enabledSubstitutions & ESNextSubstitutionFlags . ClassAliases ) === 0 ) {
561576 enabledSubstitutions |= ESNextSubstitutionFlags . ClassAliases ;
@@ -1528,4 +1543,15 @@ namespace ts {
15281543 location
15291544 ) ;
15301545 }
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+ }
15311557}
0 commit comments