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
21 lines
431 B
JavaScript
21 lines
431 B
JavaScript
var key, x, y, z;
|
|
// impure
|
|
key = 1;
|
|
var { [key++]: { y, ...x } } = { 1: { a: 1, y: 1 } };
|
|
expect(x).toEqual({ a: 1 });
|
|
expect(key).toBe(2);
|
|
expect(y).toBe(1);
|
|
|
|
// takes care of the order
|
|
|
|
key = 1;
|
|
var {
|
|
[++key]: { y, ...rest_y },
|
|
[++key]: { z, ...rest_z }
|
|
} = {2: { y: 2, z: 3 }, 3: { y: 4, z: 6 } };
|
|
expect(y).toBe(2);
|
|
expect(rest_y).toEqual({z: 3});
|
|
expect(z).toBe(6);
|
|
expect(rest_z).toEqual({ y: 4 });
|
|
expect(key).toBe(3);
|