Skip to content

Commit e2f8545

Browse files
committed
Delete now-unused code
1 parent d99eb16 commit e2f8545

File tree

2 files changed

+38
-60
lines changed

2 files changed

+38
-60
lines changed

src/compiler/binder.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,15 +2574,15 @@ namespace ts {
25742574
const constructorSymbol = lookupSymbolForPropertyAccess(lhs.expression);
25752575
if (constructorSymbol) {
25762576
addDeclarationToSymbol(constructorSymbol, constructorSymbol.valueDeclaration, SymbolFlags.Class);
2577-
} // TODO: addDeclarationToSymbol and bindPropertyAssignment overlap about 50%
2578-
bindPropertyAssignment(lhs.expression, lhs, /*isPrototypeProperty*/ false);
2577+
}
2578+
bindPropertyAssignment(constructorSymbol, lhs, /*isPrototypeProperty*/ false);
25792579
}
25802580

25812581
function bindObjectDefinePrototypeProperty(node: BindableObjectDefinePropertyCall) {
25822582
const namespaceSymbol = lookupSymbolForPropertyAccess((node.arguments[0] as PropertyAccessExpression).expression as EntityNameExpression);
25832583
if (namespaceSymbol) {
25842584
addDeclarationToSymbol(namespaceSymbol, namespaceSymbol.valueDeclaration, SymbolFlags.Class);
2585-
} // TODO: addDeclarationToSymbol and bindPropertyAssignment overlap about 50%
2585+
}
25862586
bindPotentiallyNewExpandoMemberToNamespace(node, namespaceSymbol, /*isPrototypeProperty*/ true);
25872587
}
25882588

@@ -2604,8 +2604,8 @@ namespace ts {
26042604
const constructorSymbol = lookupSymbolForPropertyAccess(constructorFunction);
26052605
if (constructorSymbol) {
26062606
addDeclarationToSymbol(constructorSymbol, constructorSymbol.valueDeclaration, SymbolFlags.Class);
2607-
} // TODO: addDeclarationToSymbol and bindPrototypePropertyAssignment overlap about 50%
2608-
bindPropertyAssignment(constructorFunction, lhs, /*isPrototypeProperty*/ true);
2607+
}
2608+
bindPropertyAssignment(constructorSymbol, lhs, /*isPrototypeProperty*/ true);
26092609
}
26102610

26112611
function bindObjectDefinePropertyAssignment(node: BindableObjectDefinePropertyCall) {
@@ -2642,7 +2642,7 @@ namespace ts {
26422642
*/
26432643
function bindStaticPropertyAssignment(node: PropertyAccessEntityNameExpression) {
26442644
node.expression.parent = node;
2645-
bindPropertyAssignment(node.expression, node, /*isPrototypeProperty*/ false);
2645+
bindPropertyAssignment(lookupSymbolForPropertyAccess(node.expression), node, /*isPrototypeProperty*/ false);
26462646
}
26472647

26482648
function bindPotentiallyMissingNamespaces(namespaceSymbol: Symbol | undefined, entityName: EntityNameExpression, isToplevel: boolean, isPrototypeProperty: boolean) {
@@ -2687,8 +2687,7 @@ namespace ts {
26872687
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
26882688
}
26892689

2690-
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
2691-
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
2690+
function bindPropertyAssignment(namespaceSymbol: Symbol | undefined, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
26922691
const isToplevel = isTopLevelNamespaceAssignment(propertyAccess);
26932692
namespaceSymbol = bindPotentiallyMissingNamespaces(namespaceSymbol, propertyAccess.expression, isToplevel, isPrototypeProperty);
26942693
bindPotentiallyNewExpandoMemberToNamespace(propertyAccess, namespaceSymbol, isPrototypeProperty);

src/compiler/checker.ts

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,7 @@ namespace ts {
20492049
const declaration = find(
20502050
result.declarations,
20512051
d => isBlockOrCatchScoped(d) || isClassLike(d) || (d.kind === SyntaxKind.EnumDeclaration));
2052+
20522053
if (declaration === undefined) return Debug.fail("checkResolvedBlockScopedVariable could not find block-scoped declaration");
20532054

20542055
if (!(declaration.flags & NodeFlags.Ambient) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
@@ -5973,11 +5974,10 @@ namespace ts {
59735974
if (!links.type) {
59745975
const jsDeclaration = getDeclarationOfExpando(symbol.valueDeclaration);
59755976
if (jsDeclaration) {
5976-
const merged = jsMerge(symbol, getSymbolOfNode(jsDeclaration));
5977+
const merged = mergeJSSymbols(symbol, getSymbolOfNode(jsDeclaration));
59775978
if (merged) {
59785979
// note:we overwrite links because we just cloned the symbol
5979-
symbol = merged;
5980-
links = merged;
5980+
symbol = links = merged;
59815981
}
59825982
}
59835983
originalLinks.type = links.type = getTypeOfFuncClassEnumModuleWorker(symbol);
@@ -6153,6 +6153,7 @@ namespace ts {
61536153
while (true) {
61546154
node = node.parent; // TODO: GH#18217 Use SourceFile kind check instead
61556155
if (node && isBinaryExpression(node)) {
6156+
// prototype assignments get the outer type parameters of their constructor function
61566157
const assignmentKind = getAssignmentDeclarationKind(node);
61576158
if (assignmentKind === AssignmentDeclarationKind.Prototype || assignmentKind === AssignmentDeclarationKind.PrototypeProperty) {
61586159
const symbol = getSymbolOfNode(node.left);
@@ -6249,7 +6250,7 @@ namespace ts {
62496250
const constraint = getBaseConstraintOfType(type);
62506251
return !!constraint && isValidBaseType(constraint) && isMixinConstructorType(constraint);
62516252
}
6252-
return isJSConstructorType(type);
6253+
return false;
62536254
}
62546255

62556256
function getBaseTypeNodeOfClass(type: InterfaceType): ExpressionWithTypeArguments | undefined {
@@ -6351,9 +6352,7 @@ namespace ts {
63516352
const baseTypeNode = getBaseTypeNodeOfClass(type)!;
63526353
const typeArgs = typeArgumentsFromTypeReferenceNode(baseTypeNode);
63536354
let baseType: Type;
6354-
const originalBaseType = isJSConstructorType(baseConstructorType) ? baseConstructorType :
6355-
baseConstructorType.symbol ? getDeclaredTypeOfSymbol(baseConstructorType.symbol) :
6356-
undefined;
6355+
const originalBaseType = baseConstructorType.symbol ? getDeclaredTypeOfSymbol(baseConstructorType.symbol) : undefined;
63576356
if (baseConstructorType.symbol && baseConstructorType.symbol.flags & SymbolFlags.Class &&
63586357
areAllOuterTypeParametersApplied(originalBaseType!)) {
63596358
// When base constructor type is a class with no captured type arguments we know that the constructors all have the same type parameters as the
@@ -6364,9 +6363,6 @@ namespace ts {
63646363
else if (baseConstructorType.flags & TypeFlags.Any) {
63656364
baseType = baseConstructorType;
63666365
}
6367-
else if (isJSConstructorType(baseConstructorType)) {
6368-
baseType = !baseTypeNode.typeArguments && getJSClassType(baseConstructorType.symbol) || anyType;
6369-
}
63706366
else {
63716367
// The class derives from a "class-like" constructor function, check that we have at least one construct signature
63726368
// with a matching number of type parameters and use the return type of the first instantiated signature. Elsewhere
@@ -6478,32 +6474,15 @@ namespace ts {
64786474
return true;
64796475
}
64806476

6481-
function jsMerge(target: Symbol, source: Symbol | undefined) {
6482-
if (source && (hasEntries(source.exports) || hasEntries(source.members))) {
6483-
target = cloneSymbol(target);
6484-
if (hasEntries(source.exports)) {
6485-
target.exports = target.exports || createSymbolTable();
6486-
mergeSymbolTable(target.exports, source.exports);
6487-
}
6488-
if (hasEntries(source.members)) {
6489-
target.members = target.members || createSymbolTable();
6490-
mergeSymbolTable(target.members, source.members);
6491-
}
6492-
target.flags |= source.flags & SymbolFlags.Class;
6493-
return target as TransientSymbol;
6494-
}
6495-
}
6496-
64976477
function getDeclaredTypeOfClassOrInterface(symbol: Symbol): InterfaceType {
64986478
let links = getSymbolLinks(symbol);
64996479
const originalLinks = links;
65006480
if (!links.declaredType) {
65016481
const kind = symbol.flags & SymbolFlags.Class ? ObjectFlags.Class : ObjectFlags.Interface;
6502-
const merged = jsMerge(symbol, getAssignedClassSymbol(symbol.valueDeclaration));
6482+
const merged = mergeJSSymbols(symbol, getAssignedClassSymbol(symbol.valueDeclaration));
65036483
if (merged) {
65046484
// note:we overwrite links because we just cloned the symbol
6505-
symbol = merged;
6506-
links = merged;
6485+
symbol = links = merged;
65076486
}
65086487

65096488
const type = originalLinks.declaredType = links.declaredType = <InterfaceType>createObjectType(kind, symbol);
@@ -7548,7 +7527,6 @@ namespace ts {
75487527
if (!constructSignatures.length) {
75497528
constructSignatures = getDefaultConstructSignatures(classType);
75507529
}
7551-
75527530
type.constructSignatures = constructSignatures;
75537531
}
75547532
}
@@ -11123,15 +11101,17 @@ namespace ts {
1112311101
}
1112411102
}
1112511103

11126-
// TODO: Make the symbol.parent approach as complete as getClassNameFromPrototypeMethod(container),
11127-
// then make getThisType and checkThisExpression both use that.
11104+
// inside x.prototype = { ... }
1112811105
if (parent && isObjectLiteralExpression(parent) && isBinaryExpression(parent.parent) && getAssignmentDeclarationKind(parent.parent) === AssignmentDeclarationKind.Prototype) {
1112911106
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent.parent.left)!.parent!).thisType!;
1113011107
}
11108+
// /** @return {this} */
11109+
// x.prototype.m = function() { ... }
1113111110
const host = node.flags & NodeFlags.JSDoc ? getHostSignatureFromJSDoc(node) : undefined;
1113211111
if (host && isFunctionExpression(host) && isBinaryExpression(host.parent) && getAssignmentDeclarationKind(host.parent) === AssignmentDeclarationKind.PrototypeProperty) {
1113311112
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(host.parent.left)!.parent!).thisType!;
1113411113
}
11114+
// inside constructor function C() { ... }
1113511115
if (isJSConstructor(container) && isNodeDescendantOf(node, container.body)) {
1113611116
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(container)).thisType!;
1113711117
}
@@ -12428,13 +12408,15 @@ namespace ts {
1242812408
if (!ignoreReturnTypes) {
1242912409
// If a signature resolution is already in-flight, skip issuing a circularity error
1243012410
// here and just use the `any` type directly
12431-
const targetReturnType = isResolvingReturnTypeOfSignature(target) ? anyType : (target.declaration && isJSConstructor(target.declaration)) ?
12432-
getJSClassType(target.declaration.symbol)! : getReturnTypeOfSignature(target);
12411+
const targetReturnType = isResolvingReturnTypeOfSignature(target) ? anyType
12412+
: target.declaration && isJSConstructor(target.declaration) ? getDeclaredTypeOfClassOrInterface(target.declaration.symbol)
12413+
: getReturnTypeOfSignature(target);
1243312414
if (targetReturnType === voidType) {
1243412415
return result;
1243512416
}
12436-
const sourceReturnType = isResolvingReturnTypeOfSignature(source) ? anyType : (source.declaration && isJSConstructor(source.declaration)) ?
12437-
getJSClassType(source.declaration.symbol)! : getReturnTypeOfSignature(source);
12417+
const sourceReturnType = isResolvingReturnTypeOfSignature(source) ? anyType
12418+
: source.declaration && isJSConstructor(source.declaration) ? getDeclaredTypeOfClassOrInterface(source.declaration.symbol)
12419+
: getReturnTypeOfSignature(source);
1243812420

1243912421
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
1244012422
const targetTypePredicate = getTypePredicateOfSignature(target);
@@ -18312,8 +18294,6 @@ namespace ts {
1831218294
// If this is a function in a JS file, it might be a class method.
1831318295
const className = getClassNameFromPrototypeMethod(container);
1831418296
if (isInJS && className) {
18315-
// TODO: Why isn't this getSymbolOfNode(className).parent? Seems like it pulls way too early on the type
18316-
// (should be able to use the symbol.parent trick instead)
1831718297
const classSymbol = checkExpression(className).symbol;
1831818298
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
1831918299
const classType = (getDeclaredTypeOfSymbol(classSymbol) as InterfaceType).thisType!;
@@ -18327,7 +18307,6 @@ namespace ts {
1832718307
else if (isInJS &&
1832818308
(container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) &&
1832918309
getJSDocClassTag(container)) {
18330-
// TODO: might be able to merge this code with the ClassLike path
1833118310
const classType = (getDeclaredTypeOfSymbol(getMergedSymbol(container.symbol)) as InterfaceType).thisType!;
1833218311
return getFlowTypeOfReference(node, classType);
1833318312
}
@@ -22878,19 +22857,19 @@ namespace ts {
2287822857
return false;
2287922858
}
2288022859

22881-
// TODO: This is probably wrong now (or redundant)
22882-
function isJSConstructorType(type: Type) {
22883-
if (type.flags & TypeFlags.Object) {
22884-
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
22885-
return resolved.callSignatures.length === 1 && isJSConstructor(resolved.callSignatures[0].declaration);
22886-
}
22887-
return false;
22888-
}
22889-
22890-
// TODO: Remove this function
22891-
function getJSClassType(symbol: Symbol): Type | undefined {
22892-
if (isJSConstructor(symbol.valueDeclaration)) {
22893-
return getDeclaredTypeOfClassOrInterface(symbol);
22860+
function mergeJSSymbols(target: Symbol, source: Symbol | undefined) {
22861+
if (source && (hasEntries(source.exports) || hasEntries(source.members))) {
22862+
target = cloneSymbol(target);
22863+
if (hasEntries(source.exports)) {
22864+
target.exports = target.exports || createSymbolTable();
22865+
mergeSymbolTable(target.exports, source.exports);
22866+
}
22867+
if (hasEntries(source.members)) {
22868+
target.members = target.members || createSymbolTable();
22869+
mergeSymbolTable(target.members, source.members);
22870+
}
22871+
target.flags |= source.flags & SymbolFlags.Class;
22872+
return target as TransientSymbol;
2289422873
}
2289522874
}
2289622875

0 commit comments

Comments
 (0)