parent
a7728f8fa1
commit
125dd57a75
|
@ -9469,11 +9469,19 @@ namespace ts {
|
|||
}
|
||||
|
||||
function getAssignedTypeOfBinaryExpression(node: BinaryExpression): Type {
|
||||
return node.parent.kind === SyntaxKind.ArrayLiteralExpression || node.parent.kind === SyntaxKind.PropertyAssignment ?
|
||||
const isDestructuringDefaultAssignment =
|
||||
node.parent.kind === SyntaxKind.ArrayLiteralExpression && isDestructuringAssignmentTarget(node.parent) ||
|
||||
node.parent.kind === SyntaxKind.PropertyAssignment && isDestructuringAssignmentTarget(node.parent.parent);
|
||||
return isDestructuringDefaultAssignment ?
|
||||
getTypeWithDefault(getAssignedType(node), node.right) :
|
||||
getTypeOfExpression(node.right);
|
||||
}
|
||||
|
||||
function isDestructuringAssignmentTarget(parent: Node) {
|
||||
return parent.parent.kind === SyntaxKind.BinaryExpression && (parent.parent as BinaryExpression).left === parent ||
|
||||
parent.parent.kind === SyntaxKind.ForOfStatement && (parent.parent as ForOfStatement).initializer === parent;
|
||||
}
|
||||
|
||||
function getAssignedTypeOfArrayLiteralElement(node: ArrayLiteralExpression, element: Expression): Type {
|
||||
return getTypeOfDestructuredArrayElement(getAssignedType(node), indexOf(node.elements, element));
|
||||
}
|
||||
|
|
13
tests/baselines/reference/assignmentNestedInLiterals.js
Normal file
13
tests/baselines/reference/assignmentNestedInLiterals.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
//// [assignmentNestedInLiterals.ts]
|
||||
var target, x, y;
|
||||
target = [x = 1, y = x];
|
||||
|
||||
var aegis, a, b;
|
||||
aegis = { x: a = 1, y: b = a };
|
||||
|
||||
|
||||
//// [assignmentNestedInLiterals.js]
|
||||
var target, x, y;
|
||||
target = [x = 1, y = x];
|
||||
var aegis, a, b;
|
||||
aegis = { x: a = 1, y: b = a };
|
25
tests/baselines/reference/assignmentNestedInLiterals.symbols
Normal file
25
tests/baselines/reference/assignmentNestedInLiterals.symbols
Normal file
|
@ -0,0 +1,25 @@
|
|||
=== tests/cases/compiler/assignmentNestedInLiterals.ts ===
|
||||
var target, x, y;
|
||||
>target : Symbol(target, Decl(assignmentNestedInLiterals.ts, 0, 3))
|
||||
>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 0, 11))
|
||||
>y : Symbol(y, Decl(assignmentNestedInLiterals.ts, 0, 14))
|
||||
|
||||
target = [x = 1, y = x];
|
||||
>target : Symbol(target, Decl(assignmentNestedInLiterals.ts, 0, 3))
|
||||
>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 0, 11))
|
||||
>y : Symbol(y, Decl(assignmentNestedInLiterals.ts, 0, 14))
|
||||
>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 0, 11))
|
||||
|
||||
var aegis, a, b;
|
||||
>aegis : Symbol(aegis, Decl(assignmentNestedInLiterals.ts, 3, 3))
|
||||
>a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10))
|
||||
>b : Symbol(b, Decl(assignmentNestedInLiterals.ts, 3, 13))
|
||||
|
||||
aegis = { x: a = 1, y: b = a };
|
||||
>aegis : Symbol(aegis, Decl(assignmentNestedInLiterals.ts, 3, 3))
|
||||
>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 4, 9))
|
||||
>a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10))
|
||||
>y : Symbol(y, Decl(assignmentNestedInLiterals.ts, 4, 19))
|
||||
>b : Symbol(b, Decl(assignmentNestedInLiterals.ts, 3, 13))
|
||||
>a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10))
|
||||
|
35
tests/baselines/reference/assignmentNestedInLiterals.types
Normal file
35
tests/baselines/reference/assignmentNestedInLiterals.types
Normal file
|
@ -0,0 +1,35 @@
|
|||
=== tests/cases/compiler/assignmentNestedInLiterals.ts ===
|
||||
var target, x, y;
|
||||
>target : any
|
||||
>x : any
|
||||
>y : any
|
||||
|
||||
target = [x = 1, y = x];
|
||||
>target = [x = 1, y = x] : number[]
|
||||
>target : any
|
||||
>[x = 1, y = x] : number[]
|
||||
>x = 1 : 1
|
||||
>x : any
|
||||
>1 : 1
|
||||
>y = x : number
|
||||
>y : any
|
||||
>x : number
|
||||
|
||||
var aegis, a, b;
|
||||
>aegis : any
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
aegis = { x: a = 1, y: b = a };
|
||||
>aegis = { x: a = 1, y: b = a } : { x: number; y: number; }
|
||||
>aegis : any
|
||||
>{ x: a = 1, y: b = a } : { x: number; y: number; }
|
||||
>x : number
|
||||
>a = 1 : 1
|
||||
>a : any
|
||||
>1 : 1
|
||||
>y : number
|
||||
>b = a : number
|
||||
>b : any
|
||||
>a : number
|
||||
|
6
tests/cases/compiler/assignmentNestedInLiterals.ts
Normal file
6
tests/cases/compiler/assignmentNestedInLiterals.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @noImplicitAny: true
|
||||
var target, x, y;
|
||||
target = [x = 1, y = x];
|
||||
|
||||
var aegis, a, b;
|
||||
aegis = { x: a = 1, y: b = a };
|
Loading…
Reference in a new issue