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.

208 changes: 0 additions & 208 deletions tests/baselines/reference/contextualTypedSpecialAssignment.types

This file was deleted.

26 changes: 13 additions & 13 deletions tests/baselines/reference/moduleExportAlias.types
Original file line number Diff line number Diff line change
@@ -223,19 +223,19 @@ multipleDeclarationAlias5.func9 = function () { };
>function () { } : () => void

var multipleDeclarationAlias6 = exports = module.exports = {};
>multipleDeclarationAlias6 : {}
>exports = module.exports = {} : {}
>multipleDeclarationAlias6 : { [x: string]: any; }
>exports = module.exports = {} : { [x: string]: any; }
>exports : typeof import("tests/cases/conformance/salsa/b")
>module.exports = {} : {}
>module.exports = {} : { [x: string]: any; }
>module.exports : any
>module : any
>exports : any
>{} : {}
>{} : { [x: string]: any; }

multipleDeclarationAlias6.func10 = function () { };
>multipleDeclarationAlias6.func10 = function () { } : () => void
>multipleDeclarationAlias6.func10 : any
>multipleDeclarationAlias6 : {}
>multipleDeclarationAlias6 : { [x: string]: any; }
>func10 : any
>function () { } : () => void

@@ -294,13 +294,13 @@ module.exports.func12 = function () { };
>function () { } : () => void

exports = module.exports = {};
>exports = module.exports = {} : {}
>exports = module.exports = {} : { [x: string]: any; }
>exports : typeof import("tests/cases/conformance/salsa/b")
>module.exports = {} : {}
>module.exports = {} : { [x: string]: any; }
>module.exports : any
>module : any
>exports : any
>{} : {}
>{} : { [x: string]: any; }

exports.func13 = function () { };
>exports.func13 = function () { } : () => void
@@ -319,13 +319,13 @@ module.exports.func14 = function () { };
>function () { } : () => void

exports = module.exports = {};
>exports = module.exports = {} : {}
>exports = module.exports = {} : { [x: string]: any; }
>exports : typeof import("tests/cases/conformance/salsa/b")
>module.exports = {} : {}
>module.exports = {} : { [x: string]: any; }
>module.exports : any
>module : any
>exports : any
>{} : {}
>{} : { [x: string]: any; }

exports.func15 = function () { };
>exports.func15 = function () { } : () => void
@@ -369,11 +369,11 @@ module.exports.func18 = function () { };
>function () { } : () => void

module.exports = {};
>module.exports = {} : {}
>module.exports = {} : { [x: string]: any; }
>module.exports : any
>module : any
>exports : any
>{} : {}
>{} : { [x: string]: any; }

exports.func19 = function () { };
>exports.func19 = function () { } : () => void
12 changes: 6 additions & 6 deletions tests/baselines/reference/typeFromPropertyAssignment11.types
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ var Inner = function() {}

Inner.prototype = {
>Inner.prototype = { m() { }, i: 1} : { [x: string]: any; m(): void; i: number; }
>Inner.prototype : { [x: string]: any; m(): void; i: number; }
>Inner.prototype : { [x: string]: any; }
>Inner : typeof Inner
>prototype : { [x: string]: any; m(): void; i: number; }
>prototype : { [x: string]: any; }
>{ m() { }, i: 1} : { [x: string]: any; m(): void; i: number; }

m() { },
@@ -21,18 +21,18 @@ Inner.prototype = {
Inner.prototype.j = 2
>Inner.prototype.j = 2 : 2
>Inner.prototype.j : any
>Inner.prototype : { [x: string]: any; m(): void; i: number; }
>Inner.prototype : { [x: string]: any; }
>Inner : typeof Inner
>prototype : { [x: string]: any; m(): void; i: number; }
>prototype : { [x: string]: any; }
>j : any
>2 : 2

/** @type {string} */
Inner.prototype.k;
>Inner.prototype.k : any
>Inner.prototype : { [x: string]: any; m(): void; i: number; }
>Inner.prototype : { [x: string]: any; }
>Inner : typeof Inner
>prototype : { [x: string]: any; m(): void; i: number; }
>prototype : { [x: string]: any; }
>k : any

var inner = new Inner()
12 changes: 6 additions & 6 deletions tests/baselines/reference/typeFromPropertyAssignment13.types
Original file line number Diff line number Diff line change
@@ -12,11 +12,11 @@ Outer.Inner = function() {}

Outer.Inner.prototype = {
>Outer.Inner.prototype = { m() { }, i: 1} : { [x: string]: any; m(): void; i: number; }
>Outer.Inner.prototype : { [x: string]: any; m(): void; i: number; }
>Outer.Inner.prototype : { [x: string]: any; }
>Outer.Inner : typeof Inner
>Outer : typeof Outer
>Inner : typeof Inner
>prototype : { [x: string]: any; m(): void; i: number; }
>prototype : { [x: string]: any; }
>{ m() { }, i: 1} : { [x: string]: any; m(): void; i: number; }

m() { },
@@ -30,22 +30,22 @@ Outer.Inner.prototype = {
Outer.Inner.prototype.j = 2
>Outer.Inner.prototype.j = 2 : 2
>Outer.Inner.prototype.j : any
>Outer.Inner.prototype : { [x: string]: any; m(): void; i: number; }
>Outer.Inner.prototype : { [x: string]: any; }
>Outer.Inner : typeof Inner
>Outer : typeof Outer
>Inner : typeof Inner
>prototype : { [x: string]: any; m(): void; i: number; }
>prototype : { [x: string]: any; }
>j : any
>2 : 2

/** @type {string} */
Outer.Inner.prototype.k;
>Outer.Inner.prototype.k : any
>Outer.Inner.prototype : { [x: string]: any; m(): void; i: number; }
>Outer.Inner.prototype : { [x: string]: any; }
>Outer.Inner : typeof Inner
>Outer : typeof Outer
>Inner : typeof Inner
>prototype : { [x: string]: any; m(): void; i: number; }
>prototype : { [x: string]: any; }
>k : any

var inner = new Outer.Inner()
20 changes: 10 additions & 10 deletions tests/baselines/reference/typeFromPropertyAssignment14.types
Original file line number Diff line number Diff line change
@@ -5,19 +5,19 @@ var Outer = {};

=== tests/cases/conformance/salsa/work.js ===
Outer.Inner = function () {}
>Outer.Inner = function () {} : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner = function () {} : { (): void; prototype: { [x: string]: any; }; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; }; }
>Outer : typeof Outer
>Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>function () {} : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Inner : { (): void; prototype: { [x: string]: any; }; }
>function () {} : { (): void; prototype: { [x: string]: any; }; }

Outer.Inner.prototype = {
>Outer.Inner.prototype = { x: 1, m() { }} : { [x: string]: any; x: number; m(): void; }
>Outer.Inner.prototype : { [x: string]: any; x: number; m(): void; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner.prototype : { [x: string]: any; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; }; }
>Outer : typeof Outer
>Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>prototype : { [x: string]: any; x: number; m(): void; }
>Inner : { (): void; prototype: { [x: string]: any; }; }
>prototype : { [x: string]: any; }
>{ x: 1, m() { }} : { [x: string]: any; x: number; m(): void; }

x: 1,
@@ -47,9 +47,9 @@ inner.m()
var inno = new Outer.Inner()
>inno : { [x: string]: any; x: number; m(): void; }
>new Outer.Inner() : { [x: string]: any; x: number; m(): void; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; }; }
>Outer : typeof Outer
>Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Inner : { (): void; prototype: { [x: string]: any; }; }

inno.x
>inno.x : number
20 changes: 10 additions & 10 deletions tests/baselines/reference/typeFromPropertyAssignment16.types
Original file line number Diff line number Diff line change
@@ -4,19 +4,19 @@ var Outer = {};
>{} : { [x: string]: any; }

Outer.Inner = function () {}
>Outer.Inner = function () {} : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner = function () {} : { (): void; prototype: { [x: string]: any; }; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; }; }
>Outer : typeof Outer
>Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>function () {} : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Inner : { (): void; prototype: { [x: string]: any; }; }
>function () {} : { (): void; prototype: { [x: string]: any; }; }

Outer.Inner.prototype = {
>Outer.Inner.prototype = { x: 1, m() { }} : { [x: string]: any; x: number; m(): void; }
>Outer.Inner.prototype : { [x: string]: any; x: number; m(): void; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner.prototype : { [x: string]: any; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; }; }
>Outer : typeof Outer
>Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>prototype : { [x: string]: any; x: number; m(): void; }
>Inner : { (): void; prototype: { [x: string]: any; }; }
>prototype : { [x: string]: any; }
>{ x: 1, m() { }} : { [x: string]: any; x: number; m(): void; }

x: 1,
@@ -45,9 +45,9 @@ inner.m()
var inno = new Outer.Inner()
>inno : { [x: string]: any; x: number; m(): void; }
>new Outer.Inner() : { [x: string]: any; x: number; m(): void; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Outer.Inner : { (): void; prototype: { [x: string]: any; }; }
>Outer : typeof Outer
>Inner : { (): void; prototype: { [x: string]: any; x: number; m(): void; }; }
>Inner : { (): void; prototype: { [x: string]: any; }; }

inno.x
>inno.x : number
4 changes: 2 additions & 2 deletions tests/baselines/reference/typeFromPropertyAssignment27.types
Original file line number Diff line number Diff line change
@@ -10,9 +10,9 @@ function C() { this.p = 1; }

C.prototype = { q: 2 };
>C.prototype = { q: 2 } : { [x: string]: any; q: number; }
>C.prototype : { [x: string]: any; q: number; }
>C.prototype : { [x: string]: any; }
>C : typeof C
>prototype : { [x: string]: any; q: number; }
>prototype : { [x: string]: any; }
>{ q: 2 } : { [x: string]: any; q: number; }
>q : number
>2 : 2
84 changes: 0 additions & 84 deletions tests/cases/conformance/salsa/contextualTypedSpecialAssignment.ts

This file was deleted.