Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Destructuring: Fix handling of impure computed keys with object rest (#…
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...nsform-destructuring/test/fixtures/destructuring/object-rest-impure-computed-keys/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var key, x, y, z; | ||
// impure | ||
key = 1; | ||
var { [key++]: y, ...x } = { 1: 1, a: 1 }; | ||
expect(x).toEqual({ a: 1 }); | ||
expect(key).toBe(2); | ||
expect(1).toBe(y); | ||
|
||
// takes care of the order | ||
|
||
key = 1; | ||
var { [++key]: y, [++key]: z, ...rest} = {2: 2, 3: 3}; | ||
expect(y).toBe(2); | ||
expect(z).toBe(3); | ||
|
||
// pure, computed property should remain as-is | ||
key = 2; | ||
({ [key]: y, z, ...x } = {2: "two", z: "zee"}); | ||
expect(y).toBe("two"); | ||
expect(x).toEqual({}); | ||
expect(z).toBe("zee"); | ||
|
||
// rhs evaluated before lhs | ||
var order = []; | ||
function left() { | ||
order.push("left"); | ||
return 0; | ||
} | ||
function right() { | ||
order.push("right"); | ||
return {}; | ||
} | ||
var { [left()]: y, ...x} = right(); | ||
expect(order).toEqual(["right", "left"]); |
1 change: 1 addition & 0 deletions
1
...sform-destructuring/test/fixtures/destructuring/object-rest-impure-computed-keys/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var { [fn()]: x, ...y } = z; |
4 changes: 4 additions & 0 deletions
4
...form-destructuring/test/fixtures/destructuring/object-rest-impure-computed-keys/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var _z = z, | ||
_fn = fn(), | ||
x = _z[_fn], | ||
y = babelHelpers.objectWithoutProperties(_z, [_fn].map(babelHelpers.toPropertyKey)); |