-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
Bug Report
π Search Terms
array object assign destructuring invalid code syntax error
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
var x, y, a, b;
// Should print: {"abc":1}
[{ ...x }] = [{ abc: 1 }]; console.log(JSON.stringify(x));
// Should print: {"abc":1}
for ([{ ...y }] of [[{ abc: 1 }]]) console.log(JSON.stringify(y));
// Should print: {"a":"a","b":{"1":"b","2":"c"}}
for ({ 0: a, ...b } in { abc: 1 }) console.log(JSON.stringify({a, b}));
π Actual behavior
Compiling this with a target of ES2017
results in code with a syntax error:
"use strict";
var x, y, a, b;
// Should print: {"abc":1}
[Object.assign({}, x)] = [{ abc: 1 }];
console.log(JSON.stringify(x));
// Should print: {"abc":1}
for ([Object.assign({}, y)] of [[{ abc: 1 }]])
console.log(JSON.stringify(y));
// Should print: {"a":"a","b":{"1":"b","2":"c"}}
for (Object.assign({ 0: a }, b) in { abc: 1 })
console.log(JSON.stringify({ a, b }));
The specific syntax error is SyntaxError: Invalid destructuring assignment target
, and happens because of the call to Object.assign
in assignment position.
π Expected behavior
This should result in valid code, and that code should print this:
{"abc":1}
{"abc":1}
{"a":"a","b":{"1":"b","2":"c"}}
I have reported this same issue in the past: #39181 (comment). It must be that either the fix has regressed or the fix was incomplete.
RyanCavanaugh and a-tarasyuk
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone