Skip to content

Commit 7318c2c

Browse files
author
Arthur Ozga
committed
some cleanup
1 parent a88be7c commit 7318c2c

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

src/compiler/checker.ts

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,22 +2327,22 @@ namespace ts {
23272327
if (objectFlags & ObjectFlags.ClassOrInterface) {
23282328
Debug.assert(!!(type.flags & TypeFlags.Object));
23292329
// TODO: Detect whether class is named and fail if not.
2330-
const name = getNameOfSymbol(type.symbol);
2330+
const name = createNameFromSymbol(type.symbol);
23312331
// TODO: handle type arguments.
23322332
return createTypeReferenceNode(name, /*typeParameters*/undefined);
23332333
}
23342334
if (type.flags & TypeFlags.TypeParameter) {
23352335
// TODO: get qualified name when necessary instead of string.
2336-
const name = symbolToString(type.symbol);
2336+
const name = createNameFromSymbol(type.symbol);
23372337
// Ignore constraint/default when creating a usage (as opposed to declaration) of a type parameter.
23382338
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
23392339
}
23402340

23412341
// TODO: move back up later on?
23422342
if (checkAlias && type.aliasSymbol) {
2343-
const name = getNameOfSymbol(type.aliasSymbol);
2343+
const name = createNameFromSymbol(type.aliasSymbol);
23442344
const typeArgumentNodes = mapToTypeNodeArray(type.aliasTypeArguments);
2345-
return createTypeReferenceNode(createIdentifier(name), typeArgumentNodes);
2345+
return createTypeReferenceNode(name, typeArgumentNodes);
23462346
}
23472347
checkAlias = false;
23482348

@@ -2357,15 +2357,12 @@ namespace ts {
23572357
if (objectFlags & (ObjectFlags.Anonymous | ObjectFlags.Mapped)) {
23582358
Debug.assert(!!(type.flags & TypeFlags.Object));
23592359
// 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-
23672360
return createAnonymousTypeNode(<ObjectType>type);
23682361
}
2362+
2363+
// TODO: implement when this is testable.
2364+
// else if (type.flags & TypeFlags.StringOrNumberLiteral) {
2365+
// writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
23692366

23702367
if (type.flags & TypeFlags.Index) {
23712368
// TODO: test.
@@ -2382,14 +2379,17 @@ namespace ts {
23822379

23832380
Debug.fail("Should be unreachable.");
23842381

2385-
/** Note that mapToTypeNodeArray(undefined) === undefined. */
23862382
function mapToTypeNodeArray(types: Type[]): NodeArray<TypeNode> {
2387-
return asNodeArray(types && types.map(createTypeNodeWorker) as TypeNode[]);
2383+
return types && asNodeArray(types.map(createTypeNodeWorker) as TypeNode[]);
23882384
}
23892385

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+
}
23932393

23942394
function createMappedTypeNodeFromType(type: MappedType) {
23952395
Debug.assert(!!(type.flags & TypeFlags.Object));
@@ -2414,8 +2414,6 @@ namespace ts {
24142414
if (symbol.flags & SymbolFlags.Class && !getBaseTypeVariableOfClass(symbol) ||
24152415
symbol.flags & (SymbolFlags.Enum | SymbolFlags.ValueModule) ||
24162416
shouldWriteTypeOfFunctionSymbol()) {
2417-
// TODO: test.
2418-
// TODO: get entity name from symbol.
24192417
return createTypeQueryNodeFromType(type);
24202418
}
24212419
else if (contains(symbolStack, symbol)) {
@@ -2443,7 +2441,7 @@ namespace ts {
24432441
}
24442442
}
24452443
else {
2446-
// Anonymous types with no symbol are never circular
2444+
// Anonymous types without a symbol are never circular.
24472445
return createTypeNodeFromObjectType(type);
24482446
}
24492447

@@ -2496,18 +2494,11 @@ namespace ts {
24962494
function createTypeQueryNodeFromType(type: Type) {
24972495
const symbol = type.symbol;
24982496
if (symbol) {
2499-
// TODO: get entity name instead.
25002497
const entityName = createNameFromSymbol(symbol);
25012498
return createTypeQueryNode(entityName);
25022499
}
25032500
}
25042501

2505-
function createNameFromSymbol(symbol: Symbol): EntityName {
2506-
symbol; enclosingDeclaration;
2507-
// TODO: actually implement this
2508-
return createIdentifier(symbolToString(symbol, enclosingDeclaration));
2509-
}
2510-
25112502
function createTypeReferenceNodeFromType(type: TypeReference) {
25122503
const typeArguments: Type[] = type.typeArguments || emptyArray;
25132504
if (type.target === globalArrayType) {
@@ -2535,8 +2526,8 @@ namespace ts {
25352526
// the default outer type arguments), we don't show the group.
25362527
// TODO: figure out how to handle type arguments
25372528
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)));
25402531
if (!qualifiedName) {
25412532
qualifiedName = createQualifiedName(qualifiedNamePart, /*right*/undefined);
25422533
}
@@ -2549,7 +2540,7 @@ namespace ts {
25492540
}
25502541
}
25512542
let entityName: EntityName = undefined;
2552-
const nameIdentifier = createIdentifier(symbolToString(type.symbol));
2543+
const nameIdentifier = createNameFromSymbol(type.symbol);
25532544
if (qualifiedName) {
25542545
// TODO: handle checking of type arguments for qualified names?
25552546
Debug.assert(!qualifiedName.right);

src/compiler/factory.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,12 @@ namespace ts {
6868
}
6969

7070
/* @internal */
71-
/**
72-
* Note this implementation is inefficient in that all nodes except leaves are cloned twice,
73-
* First by the explicit call below and then again as part of updateNode.
74-
* We need to clone before visiting the children because otherwise updateNode
75-
* will overwrite the synthesized span with the original node's span.
76-
*/
7771
export function getSynthesizedDeepClone<T extends Node>(node: T | undefined): T {
7872
if (node === undefined) {
7973
return undefined;
8074
}
81-
const clone = getSynthesizedClone(node);
82-
return visitEachChild(clone, getSynthesizedDeepClone, nullTransformationContext);
75+
const clone = visitEachChild(node, getSynthesizedDeepClone, nullTransformationContext);
76+
return clone === node ? getSynthesizedClone(node) : clone;
8377
}
8478

8579
// Literals

tests/cases/fourslash/codeFixClassImplementInterfaceNamespaceConflict.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
//// namespace N1 {
44
//// export interface I1 {
55
//// x: number;
6+
//// y: I1;
67
//// }
78
//// }
89
//// interface I1 {
910
//// f1();
1011
//// }
11-
////
1212
//// class C1 implements N1.I1 {[| |]}
1313

1414
verify.rangeAfterCodeFix(`
1515
x: number;
16+
y: N1.I1;
1617
`);

0 commit comments

Comments
 (0)