@@ -993,16 +993,34 @@ module ts {
993
993
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
994
994
var _displayBuilder : SymbolDisplayBuilder ;
995
995
function getSymbolDisplayBuilder ( ) : SymbolDisplayBuilder {
996
- // Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
997
- // Meaning needs to be specified if the enclosing declaration is given
996
+ /**
997
+ * Writes only the name of the symbol out to the writer. Uses the original source text
998
+ * for the name of the symbol if it is available to match how the user inputted the name.
999
+ */
1000
+ function appendSymbolNameOnly ( symbol : Symbol , writer : SymbolWriter ) : void {
1001
+ if ( symbol . declarations && symbol . declarations . length > 0 ) {
1002
+ var declaration = symbol . declarations [ 0 ] ;
1003
+ if ( declaration . name ) {
1004
+ writer . writeSymbol ( identifierToString ( declaration . name ) , symbol ) ;
1005
+ return ;
1006
+ }
1007
+ }
1008
+
1009
+ writer . writeSymbol ( symbol . name , symbol ) ;
1010
+ }
1011
+
1012
+ /**
1013
+ * Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
1014
+ * Meaning needs to be specified if the enclosing declaration is given
1015
+ */
998
1016
function buildSymbolDisplay ( symbol : Symbol , writer : SymbolWriter , enclosingDeclaration ?: Node , meaning ?: SymbolFlags , flags ?: SymbolFormatFlags ) : void {
999
1017
var parentSymbol : Symbol ;
1000
- function writeSymbolName ( symbol : Symbol ) : void {
1018
+ function appendParentTypeArgumentsAndSymbolName ( symbol : Symbol ) : void {
1001
1019
if ( parentSymbol ) {
1002
1020
// Write type arguments of instantiated class/interface here
1003
1021
if ( flags & SymbolFormatFlags . WriteTypeParametersOrArguments ) {
1004
1022
if ( symbol . flags & SymbolFlags . Instantiated ) {
1005
- buildTypeArgumentListDisplay ( getTypeParametersOfClassOrInterface ( parentSymbol ) ,
1023
+ buildDisplayForTypeArgumentsAndDelimiters ( getTypeParametersOfClassOrInterface ( parentSymbol ) ,
1006
1024
( < TransientSymbol > symbol ) . mapper , writer , enclosingDeclaration ) ;
1007
1025
}
1008
1026
else {
@@ -1012,15 +1030,7 @@ module ts {
1012
1030
writePunctuation ( writer , SyntaxKind . DotToken ) ;
1013
1031
}
1014
1032
parentSymbol = symbol ;
1015
- if ( symbol . declarations && symbol . declarations . length > 0 ) {
1016
- var declaration = symbol . declarations [ 0 ] ;
1017
- if ( declaration . name ) {
1018
- writer . writeSymbol ( identifierToString ( declaration . name ) , symbol ) ;
1019
- return ;
1020
- }
1021
- }
1022
-
1023
- writer . writeSymbol ( symbol . name , symbol ) ;
1033
+ appendSymbolNameOnly ( symbol , writer ) ;
1024
1034
}
1025
1035
1026
1036
// Let the writer know we just wrote out a symbol. The declaration emitter writer uses
@@ -1046,7 +1056,7 @@ module ts {
1046
1056
1047
1057
if ( accessibleSymbolChain ) {
1048
1058
for ( var i = 0 , n = accessibleSymbolChain . length ; i < n ; i ++ ) {
1049
- writeSymbolName ( accessibleSymbolChain [ i ] ) ;
1059
+ appendParentTypeArgumentsAndSymbolName ( accessibleSymbolChain [ i ] ) ;
1050
1060
}
1051
1061
}
1052
1062
else {
@@ -1060,7 +1070,7 @@ module ts {
1060
1070
return ;
1061
1071
}
1062
1072
1063
- writeSymbolName ( symbol ) ;
1073
+ appendParentTypeArgumentsAndSymbolName ( symbol ) ;
1064
1074
}
1065
1075
}
1066
1076
}
@@ -1074,7 +1084,7 @@ module ts {
1074
1084
return ;
1075
1085
}
1076
1086
1077
- return writeSymbolName ( symbol ) ;
1087
+ return appendParentTypeArgumentsAndSymbolName ( symbol ) ;
1078
1088
}
1079
1089
1080
1090
function buildTypeDisplay ( type : Type , writer : SymbolWriter , enclosingDeclaration ?: Node , globalFlags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
@@ -1315,8 +1325,15 @@ module ts {
1315
1325
}
1316
1326
}
1317
1327
1328
+ function buildTypeParameterDisplayFromSymbol ( symbol : Symbol , writer : SymbolWriter , enclosingDeclaraiton ?: Node , flags ?: TypeFormatFlags ) {
1329
+ var targetSymbol = getTargetSymbol ( symbol ) ;
1330
+ if ( targetSymbol . flags & SymbolFlags . Class || targetSymbol . flags & SymbolFlags . Interface ) {
1331
+ buildDisplayForTypeParametersAndDelimiters ( getTypeParametersOfClassOrInterface ( symbol ) , writer , enclosingDeclaraiton , flags ) ;
1332
+ }
1333
+ }
1334
+
1318
1335
function buildTypeParameterDisplay ( tp : TypeParameter , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1319
- buildSymbolDisplay ( tp . symbol , writer ) ;
1336
+ appendSymbolNameOnly ( tp . symbol , writer ) ;
1320
1337
var constraint = getConstraintOfTypeParameter ( tp ) ;
1321
1338
if ( constraint ) {
1322
1339
writeSpace ( writer ) ;
@@ -1326,7 +1343,21 @@ module ts {
1326
1343
}
1327
1344
}
1328
1345
1329
- function buildTypeParameterListDisplay ( typeParameters : TypeParameter [ ] , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1346
+ function buildParameterDisplay ( p : Symbol , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1347
+ if ( getDeclarationFlagsFromSymbol ( p ) & NodeFlags . Rest ) {
1348
+ writePunctuation ( writer , SyntaxKind . DotDotDotToken ) ;
1349
+ }
1350
+ appendSymbolNameOnly ( p , writer ) ;
1351
+ if ( p . valueDeclaration . flags & NodeFlags . QuestionMark || ( < VariableDeclaration > p . valueDeclaration ) . initializer ) {
1352
+ writePunctuation ( writer , SyntaxKind . QuestionToken ) ;
1353
+ }
1354
+ writePunctuation ( writer , SyntaxKind . ColonToken ) ;
1355
+ writeSpace ( writer ) ;
1356
+
1357
+ buildTypeDisplay ( getTypeOfSymbol ( p ) , writer , enclosingDeclaration , flags , typeStack ) ;
1358
+ }
1359
+
1360
+ function buildDisplayForTypeParametersAndDelimiters ( typeParameters : TypeParameter [ ] , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1330
1361
if ( typeParameters && typeParameters . length ) {
1331
1362
writePunctuation ( writer , SyntaxKind . LessThanToken ) ;
1332
1363
for ( var i = 0 ; i < typeParameters . length ; i ++ ) {
@@ -1340,7 +1371,7 @@ module ts {
1340
1371
}
1341
1372
}
1342
1373
1343
- function buildTypeArgumentListDisplay ( typeParameters : TypeParameter [ ] , mapper : TypeMapper , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1374
+ function buildDisplayForTypeArgumentsAndDelimiters ( typeParameters : TypeParameter [ ] , mapper : TypeMapper , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1344
1375
if ( typeParameters && typeParameters . length ) {
1345
1376
writePunctuation ( writer , SyntaxKind . LessThanToken ) ;
1346
1377
for ( var i = 0 ; i < typeParameters . length ; i ++ ) {
@@ -1354,42 +1385,19 @@ module ts {
1354
1385
}
1355
1386
}
1356
1387
1357
- function buildTypeParameterDisplayFromSymbol ( symbol : Symbol , writer : SymbolWriter , enclosingDeclaraiton ?: Node , flags ?: TypeFormatFlags ) {
1358
- var targetSymbol = getTargetSymbol ( symbol ) ;
1359
- if ( targetSymbol . flags & SymbolFlags . Class || targetSymbol . flags & SymbolFlags . Interface ) {
1360
- buildTypeParameterListDisplay ( getTypeParametersOfClassOrInterface ( symbol ) , writer , enclosingDeclaraiton , flags ) ;
1361
- }
1362
- }
1363
-
1364
- function buildSignatureDisplay ( signature : Signature , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1365
- if ( signature . target && ( flags & TypeFormatFlags . WriteTypeArgumentsOfSignature ) ) {
1366
- // Instantiated signature, write type arguments instead
1367
- buildTypeArgumentListDisplay ( signature . target . typeParameters , signature . mapper , writer , enclosingDeclaration ) ;
1368
- }
1369
- else {
1370
- buildTypeParameterListDisplay ( signature . typeParameters , writer , enclosingDeclaration , flags , typeStack ) ;
1371
- }
1388
+ function buildDisplayForParametersAndDelimiters ( parameters : Symbol [ ] , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1372
1389
writePunctuation ( writer , SyntaxKind . OpenParenToken ) ;
1373
- for ( var i = 0 ; i < signature . parameters . length ; i ++ ) {
1390
+ for ( var i = 0 ; i < parameters . length ; i ++ ) {
1374
1391
if ( i > 0 ) {
1375
1392
writePunctuation ( writer , SyntaxKind . CommaToken ) ;
1376
1393
writeSpace ( writer ) ;
1377
1394
}
1378
- var p = signature . parameters [ i ] ;
1379
- if ( getDeclarationFlagsFromSymbol ( p ) & NodeFlags . Rest ) {
1380
- writePunctuation ( writer , SyntaxKind . DotDotDotToken ) ;
1381
- }
1382
- buildSymbolDisplay ( p , writer ) ;
1383
- if ( p . valueDeclaration . flags & NodeFlags . QuestionMark || ( < VariableDeclaration > p . valueDeclaration ) . initializer ) {
1384
- writePunctuation ( writer , SyntaxKind . QuestionToken ) ;
1385
- }
1386
- writePunctuation ( writer , SyntaxKind . ColonToken ) ;
1387
- writeSpace ( writer ) ;
1388
-
1389
- buildTypeDisplay ( getTypeOfSymbol ( p ) , writer , enclosingDeclaration , flags , typeStack ) ;
1395
+ buildParameterDisplay ( parameters [ i ] , writer , enclosingDeclaration , flags , typeStack ) ;
1390
1396
}
1391
-
1392
1397
writePunctuation ( writer , SyntaxKind . CloseParenToken ) ;
1398
+ }
1399
+
1400
+ function buildReturnTypeDisplay ( signature : Signature , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1393
1401
if ( flags & TypeFormatFlags . WriteArrowStyleSignature ) {
1394
1402
writeSpace ( writer ) ;
1395
1403
writePunctuation ( writer , SyntaxKind . EqualsGreaterThanToken ) ;
@@ -1398,20 +1406,36 @@ module ts {
1398
1406
writePunctuation ( writer , SyntaxKind . ColonToken ) ;
1399
1407
}
1400
1408
writeSpace ( writer ) ;
1401
-
1402
1409
buildTypeDisplay ( getReturnTypeOfSignature ( signature ) , writer , enclosingDeclaration , flags , typeStack ) ;
1403
1410
}
1411
+
1412
+ function buildSignatureDisplay ( signature : Signature , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1413
+ if ( signature . target && ( flags & TypeFormatFlags . WriteTypeArgumentsOfSignature ) ) {
1414
+ // Instantiated signature, write type arguments instead
1415
+ // This is achieved by passing in the mapper separately
1416
+ buildDisplayForTypeArgumentsAndDelimiters ( signature . target . typeParameters , signature . mapper , writer , enclosingDeclaration ) ;
1417
+ }
1418
+ else {
1419
+ buildDisplayForTypeParametersAndDelimiters ( signature . typeParameters , writer , enclosingDeclaration , flags , typeStack ) ;
1420
+ }
1421
+
1422
+ buildDisplayForParametersAndDelimiters ( signature . parameters , writer , enclosingDeclaration , flags , typeStack ) ;
1423
+ buildReturnTypeDisplay ( signature , writer , enclosingDeclaration , flags , typeStack ) ;
1424
+ }
1404
1425
1405
1426
return _displayBuilder || ( _displayBuilder = {
1406
1427
symbolToString : symbolToString ,
1407
1428
typeToString : typeToString ,
1408
1429
buildSymbolDisplay : buildSymbolDisplay ,
1409
1430
buildTypeDisplay : buildTypeDisplay ,
1410
1431
buildTypeParameterDisplay : buildTypeParameterDisplay ,
1411
- buildTypeParameterListDisplay : buildTypeParameterListDisplay ,
1412
- buildTypeArgumentListDisplay : buildTypeArgumentListDisplay ,
1432
+ buildParameterDisplay : buildParameterDisplay ,
1433
+ buildDisplayForParametersAndDelimiters : buildDisplayForParametersAndDelimiters ,
1434
+ buildDisplayForTypeParametersAndDelimiters : buildDisplayForTypeParametersAndDelimiters ,
1435
+ buildDisplayForTypeArgumentsAndDelimiters : buildDisplayForTypeArgumentsAndDelimiters ,
1413
1436
buildTypeParameterDisplayFromSymbol : buildTypeParameterDisplayFromSymbol ,
1414
- buildSignatureDisplay : buildSignatureDisplay
1437
+ buildSignatureDisplay : buildSignatureDisplay ,
1438
+ buildReturnTypeDisplay : buildReturnTypeDisplay
1415
1439
} ) ;
1416
1440
}
1417
1441
0 commit comments