mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* fix: Preserve computed key evaluation order in nested object rest (#17274) * fix: use inline memoization for computed keys to preserve eval order * test: use distinct values to properly validate computed key ordering fix * docs: update comments to reflect inline memoization approach * refactor: remove redundant state flags and AST mutations * fix: only memoize computed keys when rest elements are present * refactor: address review feedback
49 lines
854 B
JavaScript
49 lines
854 B
JavaScript
var _key, _key2, _key3;
|
|
var key, x, y, z;
|
|
// impure
|
|
key = 1;
|
|
var _$a = {
|
|
1: 1,
|
|
a: 1
|
|
},
|
|
{
|
|
[_key = key++]: y
|
|
} = _$a,
|
|
x = babelHelpers.objectWithoutProperties(_$a, [_key].map(babelHelpers.toPropertyKey));
|
|
expect(x).toEqual({
|
|
a: 1
|
|
});
|
|
expect(key).toBe(2);
|
|
expect(y).toBe(1);
|
|
|
|
// takes care of the order
|
|
|
|
key = 1;
|
|
var _$ = {
|
|
2: 2,
|
|
3: 3
|
|
},
|
|
{
|
|
[_key2 = ++key]: y,
|
|
[_key3 = ++key]: z
|
|
} = _$,
|
|
rest = babelHelpers.objectWithoutProperties(_$, [_key2, _key3].map(babelHelpers.toPropertyKey));
|
|
expect(y).toBe(2);
|
|
expect(z).toBe(3);
|
|
|
|
// pure, computed property should remain as-is
|
|
key = 2;
|
|
var _$z = {
|
|
2: "two",
|
|
z: "zee"
|
|
};
|
|
({
|
|
[key]: y,
|
|
z
|
|
} = _$z);
|
|
x = babelHelpers.objectWithoutProperties(_$z, [key, "z"].map(babelHelpers.toPropertyKey));
|
|
_$z;
|
|
expect(y).toBe("two");
|
|
expect(x).toEqual({});
|
|
expect(z).toBe("zee");
|