@@ -190,6 +190,7 @@ namespace ts {
190190 const writer = < EmitTextWriterWithSymbolWriter > createTextWriter ( newLine ) ;
191191 writer . trackSymbol = trackSymbol ;
192192 writer . reportInaccessibleThisError = reportInaccessibleThisError ;
193+ writer . reportInaccessibleUniqueSymbolError = reportInaccessibleUniqueSymbolError ;
193194 writer . reportPrivateInBaseOfClassExpression = reportPrivateInBaseOfClassExpression ;
194195 writer . writeKeyword = writer . write ;
195196 writer . writeOperator = writer . write ;
@@ -322,11 +323,21 @@ namespace ts {
322323 }
323324 }
324325
326+ function reportInaccessibleUniqueSymbolError ( ) {
327+ if ( errorNameNode ) {
328+ reportedDeclarationError = true ;
329+ emitterDiagnostics . add ( createDiagnosticForNode ( errorNameNode , Diagnostics . The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary ,
330+ declarationNameToString ( errorNameNode ) ,
331+ "unique symbol" ) ) ;
332+ }
333+ }
334+
325335 function reportInaccessibleThisError ( ) {
326336 if ( errorNameNode ) {
327337 reportedDeclarationError = true ;
328- emitterDiagnostics . add ( createDiagnosticForNode ( errorNameNode , Diagnostics . The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary ,
329- declarationNameToString ( errorNameNode ) ) ) ;
338+ emitterDiagnostics . add ( createDiagnosticForNode ( errorNameNode , Diagnostics . The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary ,
339+ declarationNameToString ( errorNameNode ) ,
340+ "this" ) ) ;
330341 }
331342 }
332343
@@ -1227,7 +1238,7 @@ namespace ts {
12271238 }
12281239
12291240 function emitPropertyDeclaration ( node : Declaration ) {
1230- if ( hasDynamicName ( node ) ) {
1241+ if ( hasDynamicName ( node ) && ! resolver . isLateBound ( node ) ) {
12311242 return ;
12321243 }
12331244
@@ -1246,10 +1257,8 @@ namespace ts {
12461257 emitBindingPattern ( < BindingPattern > node . name ) ;
12471258 }
12481259 else {
1249- // If this node is a computed name, it can only be a symbol, because we've already skipped
1250- // it if it's not a well known symbol. In that case, the text of the name will be exactly
1251- // what we want, namely the name expression enclosed in brackets.
1252- writeTextOfNode ( currentText , node . name ) ;
1260+ writeNameOfDeclaration ( node , getVariableDeclarationTypeVisibilityError ) ;
1261+
12531262 // If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
12541263 // we don't want to emit property declaration with "?"
12551264 if ( ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ||
@@ -1387,7 +1396,7 @@ namespace ts {
13871396 }
13881397
13891398 function emitAccessorDeclaration ( node : AccessorDeclaration ) {
1390- if ( hasDynamicName ( node ) ) {
1399+ if ( hasDynamicName ( node ) && ! resolver . isLateBound ( node ) ) {
13911400 return ;
13921401 }
13931402
@@ -1398,7 +1407,7 @@ namespace ts {
13981407 emitJsDocComments ( accessors . getAccessor ) ;
13991408 emitJsDocComments ( accessors . setAccessor ) ;
14001409 emitClassMemberDeclarationFlags ( getModifierFlags ( node ) | ( accessors . setAccessor ? 0 : ModifierFlags . Readonly ) ) ;
1401- writeTextOfNode ( currentText , node . name ) ;
1410+ writeNameOfDeclaration ( node , getAccessorNameVisibilityError ) ;
14021411 if ( ! hasModifier ( node , ModifierFlags . Private ) ) {
14031412 accessorWithTypeAnnotation = node ;
14041413 let type = getTypeAnnotationFromAccessor ( node ) ;
@@ -1426,6 +1435,37 @@ namespace ts {
14261435 }
14271436 }
14281437
1438+ function getAccessorNameVisibilityError ( symbolAccessibilityResult : SymbolAccessibilityResult ) {
1439+ const diagnosticMessage = getAccessorNameVisibilityDiagnosticMessage ( symbolAccessibilityResult ) ;
1440+ return diagnosticMessage !== undefined ? {
1441+ diagnosticMessage,
1442+ errorNode : node ,
1443+ typeName : node . name
1444+ } : undefined ;
1445+ }
1446+
1447+ function getAccessorNameVisibilityDiagnosticMessage ( symbolAccessibilityResult : SymbolAccessibilityResult ) {
1448+ if ( hasModifier ( node , ModifierFlags . Static ) ) {
1449+ return symbolAccessibilityResult . errorModuleName ?
1450+ symbolAccessibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1451+ Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1452+ Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1453+ Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_private_name_1 ;
1454+ }
1455+ else if ( node . parent . kind === SyntaxKind . ClassDeclaration ) {
1456+ return symbolAccessibilityResult . errorModuleName ?
1457+ symbolAccessibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1458+ Diagnostics . Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1459+ Diagnostics . Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1460+ Diagnostics . Public_property_0_of_exported_class_has_or_is_using_private_name_1 ;
1461+ }
1462+ else {
1463+ return symbolAccessibilityResult . errorModuleName ?
1464+ Diagnostics . Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
1465+ Diagnostics . Property_0_of_exported_interface_has_or_is_using_private_name_1 ;
1466+ }
1467+ }
1468+
14291469 function getAccessorDeclarationTypeVisibilityError ( symbolAccessibilityResult : SymbolAccessibilityResult ) : SymbolAccessibilityDiagnostic {
14301470 let diagnosticMessage : DiagnosticMessage ;
14311471 if ( accessorWithTypeAnnotation . kind === SyntaxKind . SetAccessor ) {
@@ -1467,7 +1507,7 @@ namespace ts {
14671507 }
14681508
14691509 function writeFunctionDeclaration ( node : FunctionLikeDeclaration ) {
1470- if ( hasDynamicName ( node ) ) {
1510+ if ( hasDynamicName ( node ) && ! resolver . isLateBound ( node ) ) {
14711511 return ;
14721512 }
14731513
@@ -1489,13 +1529,69 @@ namespace ts {
14891529 write ( "constructor" ) ;
14901530 }
14911531 else {
1492- writeTextOfNode ( currentText , node . name ) ;
1532+ writeNameOfDeclaration ( node , getMethodNameVisibilityError ) ;
14931533 if ( hasQuestionToken ( node ) ) {
14941534 write ( "?" ) ;
14951535 }
14961536 }
14971537 emitSignatureDeclaration ( node ) ;
14981538 }
1539+
1540+ function getMethodNameVisibilityError ( symbolAccessibilityResult : SymbolAccessibilityResult ) : SymbolAccessibilityDiagnostic {
1541+ const diagnosticMessage = getMethodNameVisibilityDiagnosticMessage ( symbolAccessibilityResult ) ;
1542+ return diagnosticMessage !== undefined ? {
1543+ diagnosticMessage,
1544+ errorNode : node ,
1545+ typeName : node . name
1546+ } : undefined ;
1547+ }
1548+
1549+ function getMethodNameVisibilityDiagnosticMessage ( symbolAccessibilityResult : SymbolAccessibilityResult ) {
1550+ if ( hasModifier ( node , ModifierFlags . Static ) ) {
1551+ return symbolAccessibilityResult . errorModuleName ?
1552+ symbolAccessibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1553+ Diagnostics . Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1554+ Diagnostics . Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1555+ Diagnostics . Public_static_method_0_of_exported_class_has_or_is_using_private_name_1 ;
1556+ }
1557+ else if ( node . parent . kind === SyntaxKind . ClassDeclaration ) {
1558+ return symbolAccessibilityResult . errorModuleName ?
1559+ symbolAccessibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1560+ Diagnostics . Public_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1561+ Diagnostics . Public_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1562+ Diagnostics . Public_method_0_of_exported_class_has_or_is_using_private_name_1 ;
1563+ }
1564+ else {
1565+ return symbolAccessibilityResult . errorModuleName ?
1566+ Diagnostics . Method_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
1567+ Diagnostics . Method_0_of_exported_interface_has_or_is_using_private_name_1 ;
1568+ }
1569+ }
1570+ }
1571+
1572+ function writeNameOfDeclaration ( node : NamedDeclaration , getSymbolAccessibilityDiagnostic : GetSymbolAccessibilityDiagnostic ) {
1573+ if ( hasDynamicName ( node ) ) {
1574+ // If this node has a dynamic name, it can only be an identifier or property access because
1575+ // we've already skipped it otherwise.
1576+ Debug . assert ( resolver . isLateBound ( node ) ) ;
1577+
1578+ writeLateBoundNameOfDeclaration ( node as LateBoundDeclaration , getSymbolAccessibilityDiagnostic ) ;
1579+ }
1580+ else {
1581+ // If this node is a computed name, it can only be a symbol, because we've already skipped
1582+ // it if it's not a well known symbol. In that case, the text of the name will be exactly
1583+ // what we want, namely the name expression enclosed in brackets.
1584+ writeTextOfNode ( currentText , node . name ) ;
1585+ }
1586+ }
1587+
1588+ function writeLateBoundNameOfDeclaration ( node : LateBoundDeclaration , getSymbolAccessibilityDiagnostic : GetSymbolAccessibilityDiagnostic ) {
1589+ writer . getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic ;
1590+ const entityName = node . name . expression ;
1591+ const visibilityResult = resolver . isEntityNameVisible ( entityName , enclosingDeclaration ) ;
1592+ handleSymbolAccessibilityError ( visibilityResult ) ;
1593+ recordTypeReferenceDirectivesIfNecessary ( resolver . getTypeReferenceDirectivesForEntityName ( entityName ) ) ;
1594+ writeTextOfNode ( currentText , node . name ) ;
14991595 }
15001596
15011597 function emitSignatureDeclarationWithJsDocComments ( node : SignatureDeclaration ) {
0 commit comments