fix: add computed property support for object Ref (#10863)

* fix: add computed property support for object Ref

* Apply suggestions from code review

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Update output.js
This commit is contained in:
Huáng Jùnliàng
2019-12-18 19:29:46 -05:00
committed by Nicolò Ribaudo
parent c0d0bf2e5e
commit 9be27bcfea
4 changed files with 120 additions and 10 deletions

View File

@@ -0,0 +1,20 @@
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: 2, z: 3 } };
expect(y).toBe(2);
expect(rest_y).toEqual({z: 3});
expect(z).toBe(3);
expect(rest_z).toEqual({ y: 2 });
expect(key).toBe(3);

View File

@@ -0,0 +1,20 @@
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: 2, z: 3 } };
expect(y).toBe(2);
expect(rest_y).toEqual({z: 3});
expect(z).toBe(3);
expect(rest_z).toEqual({ y: 2 });
expect(key).toBe(3);

View File

@@ -0,0 +1,62 @@
var key, x, y, z; // impure
key = 1;
var _ref = key++,
{
[_ref]: {
y
}
} = {
1: {
a: 1,
y: 1
}
},
x = babelHelpers.objectWithoutProperties({
1: {
a: 1,
y: 1
}
}[_ref], ["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
}
},
_ref2 = ++key,
_ref3 = ++key,
{
[_ref3]: {
y
},
[_ref2]: {
z
}
} = _$,
rest_y = babelHelpers.objectWithoutProperties(_$[_ref3], ["y"]),
rest_z = babelHelpers.objectWithoutProperties(_$[_ref2], ["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);