@@ -2327,22 +2327,22 @@ namespace ts {
2327
2327
if (objectFlags & ObjectFlags.ClassOrInterface) {
2328
2328
Debug.assert(!!(type.flags & TypeFlags.Object));
2329
2329
// TODO: Detect whether class is named and fail if not.
2330
- const name = getNameOfSymbol (type.symbol);
2330
+ const name = createNameFromSymbol (type.symbol);
2331
2331
// TODO: handle type arguments.
2332
2332
return createTypeReferenceNode(name, /*typeParameters*/undefined);
2333
2333
}
2334
2334
if (type.flags & TypeFlags.TypeParameter) {
2335
2335
// TODO: get qualified name when necessary instead of string.
2336
- const name = symbolToString (type.symbol);
2336
+ const name = createNameFromSymbol (type.symbol);
2337
2337
// Ignore constraint/default when creating a usage (as opposed to declaration) of a type parameter.
2338
2338
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
2339
2339
}
2340
2340
2341
2341
// TODO: move back up later on?
2342
2342
if (checkAlias && type.aliasSymbol) {
2343
- const name = getNameOfSymbol (type.aliasSymbol);
2343
+ const name = createNameFromSymbol (type.aliasSymbol);
2344
2344
const typeArgumentNodes = mapToTypeNodeArray(type.aliasTypeArguments);
2345
- return createTypeReferenceNode(createIdentifier( name) , typeArgumentNodes);
2345
+ return createTypeReferenceNode(name, typeArgumentNodes);
2346
2346
}
2347
2347
checkAlias = false;
2348
2348
@@ -2357,15 +2357,12 @@ namespace ts {
2357
2357
if (objectFlags & (ObjectFlags.Anonymous | ObjectFlags.Mapped)) {
2358
2358
Debug.assert(!!(type.flags & TypeFlags.Object));
2359
2359
// The type is an object literal type.
2360
- if (!type.symbol) {
2361
- // Anonymous types without symbols are literals.
2362
- // TODO: handle this case correctly.
2363
- // TODO: test.
2364
- noop();
2365
- }
2366
-
2367
2360
return createAnonymousTypeNode(<ObjectType>type);
2368
2361
}
2362
+
2363
+ // TODO: implement when this is testable.
2364
+ // else if (type.flags & TypeFlags.StringOrNumberLiteral) {
2365
+ // writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
2369
2366
2370
2367
if (type.flags & TypeFlags.Index) {
2371
2368
// TODO: test.
@@ -2382,14 +2379,17 @@ namespace ts {
2382
2379
2383
2380
Debug.fail("Should be unreachable.");
2384
2381
2385
- /** Note that mapToTypeNodeArray(undefined) === undefined. */
2386
2382
function mapToTypeNodeArray(types: Type[]): NodeArray<TypeNode> {
2387
- return asNodeArray( types && types.map(createTypeNodeWorker) as TypeNode[]);
2383
+ return types && asNodeArray( types.map(createTypeNodeWorker) as TypeNode[]);
2388
2384
}
2389
2385
2390
- // TODO: implement when this is testable.
2391
- // else if (type.flags & TypeFlags.StringOrNumberLiteral) {
2392
- // writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
2386
+ function createNameFromSymbol(symbol: Symbol): Identifier;
2387
+ function createNameFromSymbol(symbol: Symbol): EntityName;
2388
+ function createNameFromSymbol(symbol: Symbol): EntityName {
2389
+ symbol; enclosingDeclaration;
2390
+ // TODO: actually implement this
2391
+ return createIdentifier(symbolToString(symbol, enclosingDeclaration));
2392
+ }
2393
2393
2394
2394
function createMappedTypeNodeFromType(type: MappedType) {
2395
2395
Debug.assert(!!(type.flags & TypeFlags.Object));
@@ -2414,8 +2414,6 @@ namespace ts {
2414
2414
if (symbol.flags & SymbolFlags.Class && !getBaseTypeVariableOfClass(symbol) ||
2415
2415
symbol.flags & (SymbolFlags.Enum | SymbolFlags.ValueModule) ||
2416
2416
shouldWriteTypeOfFunctionSymbol()) {
2417
- // TODO: test.
2418
- // TODO: get entity name from symbol.
2419
2417
return createTypeQueryNodeFromType(type);
2420
2418
}
2421
2419
else if (contains(symbolStack, symbol)) {
@@ -2443,7 +2441,7 @@ namespace ts {
2443
2441
}
2444
2442
}
2445
2443
else {
2446
- // Anonymous types with no symbol are never circular
2444
+ // Anonymous types without a symbol are never circular.
2447
2445
return createTypeNodeFromObjectType(type);
2448
2446
}
2449
2447
@@ -2496,18 +2494,11 @@ namespace ts {
2496
2494
function createTypeQueryNodeFromType(type: Type) {
2497
2495
const symbol = type.symbol;
2498
2496
if (symbol) {
2499
- // TODO: get entity name instead.
2500
2497
const entityName = createNameFromSymbol(symbol);
2501
2498
return createTypeQueryNode(entityName);
2502
2499
}
2503
2500
}
2504
2501
2505
- function createNameFromSymbol(symbol: Symbol): EntityName {
2506
- symbol; enclosingDeclaration;
2507
- // TODO: actually implement this
2508
- return createIdentifier(symbolToString(symbol, enclosingDeclaration));
2509
- }
2510
-
2511
2502
function createTypeReferenceNodeFromType(type: TypeReference) {
2512
2503
const typeArguments: Type[] = type.typeArguments || emptyArray;
2513
2504
if (type.target === globalArrayType) {
@@ -2535,8 +2526,8 @@ namespace ts {
2535
2526
// the default outer type arguments), we don't show the group.
2536
2527
// TODO: figure out how to handle type arguments
2537
2528
if (!rangeEquals(outerTypeParameters, typeArguments, start, i)) {
2538
- const name = symbolToString (parent);
2539
- const qualifiedNamePart = createIdentifier( name) ; // createTypeReferenceNode(name, mapToTypeNodeArray(typeArguments.slice(start, i - start)));
2529
+ const name = createNameFromSymbol (parent);
2530
+ const qualifiedNamePart = name; // createTypeReferenceNode(name, mapToTypeNodeArray(typeArguments.slice(start, i - start)));
2540
2531
if (!qualifiedName) {
2541
2532
qualifiedName = createQualifiedName(qualifiedNamePart, /*right*/undefined);
2542
2533
}
@@ -2549,7 +2540,7 @@ namespace ts {
2549
2540
}
2550
2541
}
2551
2542
let entityName: EntityName = undefined;
2552
- const nameIdentifier = createIdentifier(symbolToString( type.symbol) );
2543
+ const nameIdentifier = createNameFromSymbol( type.symbol);
2553
2544
if (qualifiedName) {
2554
2545
// TODO: handle checking of type arguments for qualified names?
2555
2546
Debug.assert(!qualifiedName.right);
0 commit comments