Merge pull request #9574 from Microsoft/fix-union-of-salsa-property-types
Fix type union of differing Salsa assignment-properties
This commit is contained in:
commit
135cc12218
5 changed files with 84 additions and 11 deletions
|
@ -3166,17 +3166,17 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
let type: Type = undefined;
|
let type: Type = undefined;
|
||||||
// Handle module.exports = expr or this.p = expr
|
// Handle certain special assignment kinds, which happen to union across multiple declarations:
|
||||||
if (declaration.kind === SyntaxKind.BinaryExpression) {
|
// * module.exports = expr
|
||||||
type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right)));
|
// * exports.p = expr
|
||||||
}
|
// * this.p = expr
|
||||||
else if (declaration.kind === SyntaxKind.PropertyAccessExpression) {
|
// * className.prototype.method = expr
|
||||||
// Declarations only exist for property access expressions for certain
|
if (declaration.kind === SyntaxKind.BinaryExpression ||
|
||||||
// special assignment kinds
|
declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) {
|
||||||
if (declaration.parent.kind === SyntaxKind.BinaryExpression) {
|
type = getUnionType(map(symbol.declarations,
|
||||||
// Handle exports.p = expr or className.prototype.method = expr
|
decl => decl.kind === SyntaxKind.BinaryExpression ?
|
||||||
type = checkExpressionCached((<BinaryExpression>declaration.parent).right);
|
checkExpressionCached((<BinaryExpression>decl).right) :
|
||||||
}
|
checkExpressionCached((<BinaryExpression>decl.parent).right)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === undefined) {
|
if (type === undefined) {
|
||||||
|
|
17
tests/baselines/reference/multipleDeclarations.js
Normal file
17
tests/baselines/reference/multipleDeclarations.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//// [input.js]
|
||||||
|
|
||||||
|
function C() {
|
||||||
|
this.m = null;
|
||||||
|
}
|
||||||
|
C.prototype.m = function() {
|
||||||
|
this.nothing();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//// [output.js]
|
||||||
|
function C() {
|
||||||
|
this.m = null;
|
||||||
|
}
|
||||||
|
C.prototype.m = function () {
|
||||||
|
this.nothing();
|
||||||
|
};
|
17
tests/baselines/reference/multipleDeclarations.symbols
Normal file
17
tests/baselines/reference/multipleDeclarations.symbols
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
=== tests/cases/conformance/salsa/input.js ===
|
||||||
|
|
||||||
|
function C() {
|
||||||
|
>C : Symbol(C, Decl(input.js, 0, 0))
|
||||||
|
|
||||||
|
this.m = null;
|
||||||
|
>m : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1))
|
||||||
|
}
|
||||||
|
C.prototype.m = function() {
|
||||||
|
>C.prototype : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1))
|
||||||
|
>C : Symbol(C, Decl(input.js, 0, 0))
|
||||||
|
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
|
||||||
|
>m : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1))
|
||||||
|
|
||||||
|
this.nothing();
|
||||||
|
};
|
||||||
|
|
29
tests/baselines/reference/multipleDeclarations.types
Normal file
29
tests/baselines/reference/multipleDeclarations.types
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
=== tests/cases/conformance/salsa/input.js ===
|
||||||
|
|
||||||
|
function C() {
|
||||||
|
>C : () => void
|
||||||
|
|
||||||
|
this.m = null;
|
||||||
|
>this.m = null : null
|
||||||
|
>this.m : any
|
||||||
|
>this : any
|
||||||
|
>m : any
|
||||||
|
>null : null
|
||||||
|
}
|
||||||
|
C.prototype.m = function() {
|
||||||
|
>C.prototype.m = function() { this.nothing();} : () => void
|
||||||
|
>C.prototype.m : any
|
||||||
|
>C.prototype : any
|
||||||
|
>C : () => void
|
||||||
|
>prototype : any
|
||||||
|
>m : any
|
||||||
|
>function() { this.nothing();} : () => void
|
||||||
|
|
||||||
|
this.nothing();
|
||||||
|
>this.nothing() : any
|
||||||
|
>this.nothing : any
|
||||||
|
>this : { m: () => void; }
|
||||||
|
>nothing : any
|
||||||
|
|
||||||
|
};
|
||||||
|
|
10
tests/cases/conformance/salsa/multipleDeclarations.ts
Normal file
10
tests/cases/conformance/salsa/multipleDeclarations.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// @filename: input.js
|
||||||
|
// @out: output.js
|
||||||
|
// @allowJs: true
|
||||||
|
|
||||||
|
function C() {
|
||||||
|
this.m = null;
|
||||||
|
}
|
||||||
|
C.prototype.m = function() {
|
||||||
|
this.nothing();
|
||||||
|
};
|
Loading…
Reference in a new issue