@@ -190,6 +190,7 @@ namespace ts {
190
190
const writer = < EmitTextWriterWithSymbolWriter > createTextWriter ( newLine ) ;
191
191
writer . trackSymbol = trackSymbol ;
192
192
writer . reportInaccessibleThisError = reportInaccessibleThisError ;
193
+ writer . reportInaccessibleUniqueSymbolError = reportInaccessibleUniqueSymbolError ;
193
194
writer . reportPrivateInBaseOfClassExpression = reportPrivateInBaseOfClassExpression ;
194
195
writer . writeKeyword = writer . write ;
195
196
writer . writeOperator = writer . write ;
@@ -322,11 +323,21 @@ namespace ts {
322
323
}
323
324
}
324
325
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
+
325
335
function reportInaccessibleThisError ( ) {
326
336
if ( errorNameNode ) {
327
337
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" ) ) ;
330
341
}
331
342
}
332
343
@@ -1227,7 +1238,7 @@ namespace ts {
1227
1238
}
1228
1239
1229
1240
function emitPropertyDeclaration ( node : Declaration ) {
1230
- if ( hasDynamicName ( node ) ) {
1241
+ if ( hasDynamicName ( node ) && ! resolver . isLateBound ( node ) ) {
1231
1242
return ;
1232
1243
}
1233
1244
@@ -1246,10 +1257,8 @@ namespace ts {
1246
1257
emitBindingPattern ( < BindingPattern > node . name ) ;
1247
1258
}
1248
1259
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
+
1253
1262
// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
1254
1263
// we don't want to emit property declaration with "?"
1255
1264
if ( ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ||
@@ -1387,7 +1396,7 @@ namespace ts {
1387
1396
}
1388
1397
1389
1398
function emitAccessorDeclaration ( node : AccessorDeclaration ) {
1390
- if ( hasDynamicName ( node ) ) {
1399
+ if ( hasDynamicName ( node ) && ! resolver . isLateBound ( node ) ) {
1391
1400
return ;
1392
1401
}
1393
1402
@@ -1398,7 +1407,7 @@ namespace ts {
1398
1407
emitJsDocComments ( accessors . getAccessor ) ;
1399
1408
emitJsDocComments ( accessors . setAccessor ) ;
1400
1409
emitClassMemberDeclarationFlags ( getModifierFlags ( node ) | ( accessors . setAccessor ? 0 : ModifierFlags . Readonly ) ) ;
1401
- writeTextOfNode ( currentText , node . name ) ;
1410
+ writeNameOfDeclaration ( node , getAccessorNameVisibilityError ) ;
1402
1411
if ( ! hasModifier ( node , ModifierFlags . Private ) ) {
1403
1412
accessorWithTypeAnnotation = node ;
1404
1413
let type = getTypeAnnotationFromAccessor ( node ) ;
@@ -1426,6 +1435,37 @@ namespace ts {
1426
1435
}
1427
1436
}
1428
1437
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
+
1429
1469
function getAccessorDeclarationTypeVisibilityError ( symbolAccessibilityResult : SymbolAccessibilityResult ) : SymbolAccessibilityDiagnostic {
1430
1470
let diagnosticMessage : DiagnosticMessage ;
1431
1471
if ( accessorWithTypeAnnotation . kind === SyntaxKind . SetAccessor ) {
@@ -1467,7 +1507,7 @@ namespace ts {
1467
1507
}
1468
1508
1469
1509
function writeFunctionDeclaration ( node : FunctionLikeDeclaration ) {
1470
- if ( hasDynamicName ( node ) ) {
1510
+ if ( hasDynamicName ( node ) && ! resolver . isLateBound ( node ) ) {
1471
1511
return ;
1472
1512
}
1473
1513
@@ -1489,13 +1529,69 @@ namespace ts {
1489
1529
write ( "constructor" ) ;
1490
1530
}
1491
1531
else {
1492
- writeTextOfNode ( currentText , node . name ) ;
1532
+ writeNameOfDeclaration ( node , getMethodNameVisibilityError ) ;
1493
1533
if ( hasQuestionToken ( node ) ) {
1494
1534
write ( "?" ) ;
1495
1535
}
1496
1536
}
1497
1537
emitSignatureDeclaration ( node ) ;
1498
1538
}
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 ) ;
1499
1595
}
1500
1596
1501
1597
function emitSignatureDeclarationWithJsDocComments ( node : SignatureDeclaration ) {
0 commit comments