mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-27 04:48:33 -05:00
Fix duplicate errors in js special assignments (#24508)
* Fix duplicate errors in js special assignments * Simplify checkExpressionCached call to checkExpression * Accept baselines after merge * Use Map for deferredNodes and improve NoDeferredCheck comment I added an assert when a duplicate was added, but it caused 18 failures in our test suite. * Remove NoDeferredCheck
This commit is contained in:
committed by
GitHub
parent
38dab7417a
commit
9044589377
@@ -465,7 +465,7 @@ namespace ts {
|
||||
let deferredGlobalImportMetaType: ObjectType;
|
||||
let deferredGlobalExtractSymbol: Symbol;
|
||||
|
||||
let deferredNodes: Node[] | undefined;
|
||||
let deferredNodes: Map<Node> | undefined;
|
||||
const allPotentiallyUnusedIdentifiers = createMap<PotentiallyUnusedIdentifier[]>(); // key is file name
|
||||
|
||||
let flowLoopStart = 0;
|
||||
@@ -26070,12 +26070,13 @@ namespace ts {
|
||||
// Delaying the type check of the body ensures foo has been assigned a type.
|
||||
function checkNodeDeferred(node: Node) {
|
||||
if (deferredNodes) {
|
||||
deferredNodes.push(node);
|
||||
const id = "" + getNodeId(node);
|
||||
deferredNodes.set(id, node);
|
||||
}
|
||||
}
|
||||
|
||||
function checkDeferredNodes() {
|
||||
for (const node of deferredNodes!) {
|
||||
deferredNodes!.forEach(node => {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
@@ -26091,7 +26092,7 @@ namespace ts {
|
||||
checkClassExpressionDeferred(<ClassExpression>node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkSourceFile(node: SourceFile) {
|
||||
@@ -26133,7 +26134,7 @@ namespace ts {
|
||||
clear(potentialThisCollisions);
|
||||
clear(potentialNewTargetCollisions);
|
||||
|
||||
deferredNodes = [];
|
||||
deferredNodes = createMap<Node>();
|
||||
forEach(node.statements, checkSourceElement);
|
||||
|
||||
checkDeferredNodes();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
tests/cases/conformance/salsa/bug24252.js(8,9): error TS2322: Type 'string[]' is not assignable to type 'number[]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/salsa/bug24252.js (1 errors) ====
|
||||
var A = {};
|
||||
A.B = class {
|
||||
m() {
|
||||
/** @type {string[]} */
|
||||
var x = [];
|
||||
/** @type {number[]} */
|
||||
var y;
|
||||
y = x;
|
||||
~
|
||||
!!! error TS2322: Type 'string[]' is not assignable to type 'number[]'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
=== tests/cases/conformance/salsa/bug24252.js ===
|
||||
var A = {};
|
||||
>A : Symbol(A, Decl(bug24252.js, 0, 3), Decl(bug24252.js, 0, 11))
|
||||
|
||||
A.B = class {
|
||||
>A.B : Symbol(A.B, Decl(bug24252.js, 0, 11))
|
||||
>A : Symbol(A, Decl(bug24252.js, 0, 3), Decl(bug24252.js, 0, 11))
|
||||
>B : Symbol(A.B, Decl(bug24252.js, 0, 11))
|
||||
|
||||
m() {
|
||||
>m : Symbol(B.m, Decl(bug24252.js, 1, 13))
|
||||
|
||||
/** @type {string[]} */
|
||||
var x = [];
|
||||
>x : Symbol(x, Decl(bug24252.js, 4, 11))
|
||||
|
||||
/** @type {number[]} */
|
||||
var y;
|
||||
>y : Symbol(y, Decl(bug24252.js, 6, 11))
|
||||
|
||||
y = x;
|
||||
>y : Symbol(y, Decl(bug24252.js, 6, 11))
|
||||
>x : Symbol(x, Decl(bug24252.js, 4, 11))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
=== tests/cases/conformance/salsa/bug24252.js ===
|
||||
var A = {};
|
||||
>A : typeof A
|
||||
>{} : { [x: string]: any; }
|
||||
|
||||
A.B = class {
|
||||
>A.B = class { m() { /** @type {string[]} */ var x = []; /** @type {number[]} */ var y; y = x; }} : typeof B
|
||||
>A.B : typeof B
|
||||
>A : typeof A
|
||||
>B : typeof B
|
||||
>class { m() { /** @type {string[]} */ var x = []; /** @type {number[]} */ var y; y = x; }} : typeof B
|
||||
|
||||
m() {
|
||||
>m : () => void
|
||||
|
||||
/** @type {string[]} */
|
||||
var x = [];
|
||||
>x : string[]
|
||||
>[] : undefined[]
|
||||
|
||||
/** @type {number[]} */
|
||||
var y;
|
||||
>y : number[]
|
||||
|
||||
y = x;
|
||||
>y = x : string[]
|
||||
>y : number[]
|
||||
>x : string[]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @noEmit: true
|
||||
// @checkJs: true
|
||||
// @allowJs: true
|
||||
// @Filename: bug24252.js
|
||||
var A = {};
|
||||
A.B = class {
|
||||
m() {
|
||||
/** @type {string[]} */
|
||||
var x = [];
|
||||
/** @type {number[]} */
|
||||
var y;
|
||||
y = x;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user