Skip to content

Revert explicitly typed special assignments #25699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -4714,10 +4714,6 @@ namespace ts {
// function/class/{} assignments are fresh declarations, not property assignments, so only add prototype assignments
const specialDeclaration = getAssignedJavascriptInitializer(symbol.valueDeclaration);
if (specialDeclaration) {
const tag = getJSDocTypeTag(specialDeclaration);
if (tag && tag.typeExpression) {
return getTypeFromTypeNode(tag.typeExpression);
}
return getWidenedLiteralType(checkExpressionCached(specialDeclaration));
}
const types: Type[] = [];
@@ -5085,7 +5081,7 @@ namespace ts {
}

function getJSInitializerType(decl: Node, symbol: Symbol, init: Expression | undefined): Type | undefined {
if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init) && init.properties.length === 0) {
if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init)) {
const exports = createSymbolTable();
while (isBinaryExpression(decl) || isPropertyAccessExpression(decl)) {
const s = getSymbolOfNode(decl);
@@ -15790,22 +15786,22 @@ namespace ts {
}

// In an assignment expression, the right operand is contextually typed by the type of the left operand.
// Don't do this for special property assignments unless there is a type tag on the assignment, to avoid circularity from checking the right operand.
// Don't do this for special property assignments to avoid circularity.
function isContextSensitiveAssignment(binaryExpression: BinaryExpression): boolean {
const kind = getSpecialPropertyAssignmentKind(binaryExpression);
switch (kind) {
case SpecialPropertyAssignmentKind.None:
return true;
case SpecialPropertyAssignmentKind.Property:
case SpecialPropertyAssignmentKind.ExportsProperty:
case SpecialPropertyAssignmentKind.Prototype:
case SpecialPropertyAssignmentKind.PrototypeProperty:
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
// See `bindStaticPropertyAssignment` in `binder.ts`.
return !binaryExpression.left.symbol || binaryExpression.left.symbol.valueDeclaration && !!getJSDocTypeTag(binaryExpression.left.symbol.valueDeclaration);
case SpecialPropertyAssignmentKind.ThisProperty:
return !binaryExpression.left.symbol;
case SpecialPropertyAssignmentKind.ExportsProperty:
case SpecialPropertyAssignmentKind.ModuleExports:
return !binaryExpression.symbol || binaryExpression.symbol.valueDeclaration && !!getJSDocTypeTag(binaryExpression.symbol.valueDeclaration);
case SpecialPropertyAssignmentKind.PrototypeProperty:
case SpecialPropertyAssignmentKind.ThisProperty:
case SpecialPropertyAssignmentKind.Prototype:
return false;
default:
return Debug.assertNever(kind);
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/chainedPrototypeAssignment.types
Original file line number Diff line number Diff line change
@@ -86,9 +86,9 @@ A.prototype = B.prototype = {
>A : typeof A
>prototype : { [x: string]: any; m(n: number): number; }
>B.prototype = { /** @param {number} n */ m(n) { return n + 1 }} : { [x: string]: any; m(n: number): number; }
>B.prototype : { [x: string]: any; m(n: number): number; }
>B.prototype : { [x: string]: any; }
>B : typeof B
>prototype : { [x: string]: any; m(n: number): number; }
>prototype : { [x: string]: any; }
>{ /** @param {number} n */ m(n) { return n + 1 }} : { [x: string]: any; m(n: number): number; }

/** @param {number} n */
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ export function abc(a, b, c) { return 5; }
>5 : 5

module.exports = { abc };
>module.exports = { abc } : { abc: (a: any, b: any, c: any) => number; }
>module.exports = { abc } : { [x: string]: any; abc: (a: any, b: any, c: any) => number; }
>module.exports : any
>module : any
>exports : any
>{ abc } : { abc: (a: any, b: any, c: any) => number; }
>{ abc } : { [x: string]: any; abc: (a: any, b: any, c: any) => number; }
>abc : (a: any, b: any, c: any) => number

=== tests/cases/conformance/salsa/use.js ===

This file was deleted.

173 changes: 0 additions & 173 deletions tests/baselines/reference/contextualTypedSpecialAssignment.symbols

This file was deleted.

Loading