mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-16 06:28:12 -05:00
Improve ancestor lookup when checking if an expression is spread into an object
This commit is contained in:
@@ -28086,8 +28086,7 @@ namespace ts {
|
||||
// type with those properties for which the binding pattern specifies a default value.
|
||||
// If the object literal is spread into another object literal, skip this step and let the top-level object
|
||||
// literal handle it instead.
|
||||
const spreadOrOutsidePossibleObjectParent = findAncestor(node, n => n.kind === SyntaxKind.SpreadAssignment || isStatement(n) || isArrowFunction(n))!;
|
||||
if (contextualTypeHasPattern && spreadOrOutsidePossibleObjectParent.kind !== SyntaxKind.SpreadAssignment) {
|
||||
if (contextualTypeHasPattern && findAncestor(node, n => n === contextualType.pattern!.parent || (n.kind === SyntaxKind.SpreadAssignment && getContextualType(n.parent as Expression, /*contextFlags*/undefined)!.pattern === contextualType.pattern))!.kind !== SyntaxKind.SpreadAssignment) {
|
||||
for (const prop of getPropertiesOfType(contextualType)) {
|
||||
if (!propertiesTable.get(prop.escapedName) && !getPropertyOfType(spread, prop.escapedName)) {
|
||||
if (!(prop.flags & SymbolFlags.Optional)) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/spreadExpressionContainingObjectExpressionContextualType.ts ===
|
||||
// repro #49585
|
||||
|
||||
const { value } = (() => ({
|
||||
>value : Symbol(value, Decl(spreadExpressionContainingObjectExpressionContextualType.ts, 2, 7))
|
||||
|
||||
value: "",
|
||||
>value : Symbol(value, Decl(spreadExpressionContainingObjectExpressionContextualType.ts, 2, 27))
|
||||
|
||||
...(true ? {} : {}),
|
||||
}))();
|
||||
|
||||
// repro 49684#discussion_r920545763
|
||||
|
||||
const { value2 } = {
|
||||
>value2 : Symbol(value2, Decl(spreadExpressionContainingObjectExpressionContextualType.ts, 9, 7))
|
||||
|
||||
value2: "",
|
||||
>value2 : Symbol(value2, Decl(spreadExpressionContainingObjectExpressionContextualType.ts, 9, 20))
|
||||
|
||||
...(() => true ? {} : {})(),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
=== tests/cases/compiler/spreadExpressionWithinIIFEReturnAssignedtoPattern.ts ===
|
||||
=== tests/cases/compiler/spreadExpressionContainingObjectExpressionContextualType.ts ===
|
||||
// repro #49585
|
||||
|
||||
const { value } = (() => ({
|
||||
@@ -21,3 +21,25 @@ const { value } = (() => ({
|
||||
>{} : {}
|
||||
|
||||
}))();
|
||||
|
||||
// repro 49684#discussion_r920545763
|
||||
|
||||
const { value2 } = {
|
||||
>value2 : string
|
||||
>{ value2: "", ...(() => true ? {} : {})(),} : { value2: string; }
|
||||
|
||||
value2: "",
|
||||
>value2 : string
|
||||
>"" : ""
|
||||
|
||||
...(() => true ? {} : {})(),
|
||||
>(() => true ? {} : {})() : {}
|
||||
>(() => true ? {} : {}) : () => {}
|
||||
>() => true ? {} : {} : () => {}
|
||||
>true ? {} : {} : {}
|
||||
>true : true
|
||||
>{} : {}
|
||||
>{} : {}
|
||||
|
||||
};
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
=== tests/cases/compiler/spreadExpressionWithinIIFEReturnAssignedtoPattern.ts ===
|
||||
// repro #49585
|
||||
|
||||
const { value } = (() => ({
|
||||
>value : Symbol(value, Decl(spreadExpressionWithinIIFEReturnAssignedtoPattern.ts, 2, 7))
|
||||
|
||||
value: "",
|
||||
>value : Symbol(value, Decl(spreadExpressionWithinIIFEReturnAssignedtoPattern.ts, 2, 27))
|
||||
|
||||
...(true ? {} : {}),
|
||||
}))();
|
||||
@@ -0,0 +1,15 @@
|
||||
// @noEmit: true
|
||||
|
||||
// repro #49585
|
||||
|
||||
const { value } = (() => ({
|
||||
value: "",
|
||||
...(true ? {} : {}),
|
||||
}))();
|
||||
|
||||
// repro 49684#discussion_r920545763
|
||||
|
||||
const { value2 } = {
|
||||
value2: "",
|
||||
...(() => true ? {} : {})(),
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
// @noEmit: true
|
||||
|
||||
// repro #49585
|
||||
|
||||
const { value } = (() => ({
|
||||
value: "",
|
||||
...(true ? {} : {}),
|
||||
}))();
|
||||
Reference in New Issue
Block a user