* Add test case demonstrating invalid behavior * Add conditional check for child properties so RHS is not duplicated * Add recursive check to find any nested non single-property case * Add case for array destructuring * Add test case for a nested rest element * More safely recurse through array destructuring * Traverse assignment and nested rest operations * Refactor to be more clear which case statement we are executing against * Update missed snapshots * Update packages/babel-plugin-proposal-object-rest-spread/src/index.js Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> * Filter null array elements, add early return, remove optional chaining * Use stronger type assertions * Update fall through to be false; add early return to RestElement case * Move hasMoreThanOneBinding to its own file with distinct tests * Rename testing helper to more appropriately match business logic * Yarn Dedup & rename hasMoreThanOneBinding to shouldStoreRHSInTemporaryVariable Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
59 lines
751 B
JavaScript
59 lines
751 B
JavaScript
var key, x, y, z; // impure
|
|
|
|
key = 1;
|
|
|
|
var _ = {
|
|
1: {
|
|
a: 1,
|
|
y: 1
|
|
}
|
|
},
|
|
_key = key++,
|
|
{
|
|
[_key]: {
|
|
y
|
|
}
|
|
} = _,
|
|
x = babelHelpers.objectWithoutProperties(_[_key], ["y"]);
|
|
|
|
expect(x).toEqual({
|
|
a: 1
|
|
});
|
|
expect(key).toBe(2);
|
|
expect(y).toBe(1); // takes care of the order
|
|
|
|
key = 1;
|
|
|
|
var _$ = {
|
|
2: {
|
|
y: 2,
|
|
z: 3
|
|
},
|
|
3: {
|
|
y: 2,
|
|
z: 3
|
|
}
|
|
},
|
|
_key2 = ++key,
|
|
_key3 = ++key,
|
|
{
|
|
[_key3]: {
|
|
y
|
|
},
|
|
[_key2]: {
|
|
z
|
|
}
|
|
} = _$,
|
|
rest_y = babelHelpers.objectWithoutProperties(_$[_key3], ["y"]),
|
|
rest_z = babelHelpers.objectWithoutProperties(_$[_key2], ["z"]);
|
|
|
|
expect(y).toBe(2);
|
|
expect(rest_y).toEqual({
|
|
z: 3
|
|
});
|
|
expect(z).toBe(3);
|
|
expect(rest_z).toEqual({
|
|
y: 2
|
|
});
|
|
expect(key).toBe(3);
|