Ensure destructuring's computed key handling matches object-rest-spread (#8793)

This commit is contained in:
Brian Ng
2018-10-02 20:46:08 -05:00
committed by GitHub
parent 2575312d1f
commit 36d12b5969
8 changed files with 43 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ var _z2 = z,
y = babelHelpers.objectWithoutProperties(_z2, ["x"]);
var _z3 = z,
x = _z3[x],
y = babelHelpers.objectWithoutProperties(_z3, [x]);
y = babelHelpers.objectWithoutProperties(_z3, [x].map(babelHelpers.toPropertyKey));
(function (_ref) {
var x = _ref.x,

View File

@@ -1,3 +1,5 @@
function _toPropertyKey(key) { if (typeof key === "symbol") { return key; } else { return String(key); } }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
@@ -13,7 +15,7 @@ var _z2 = z,
var _z3 = z,
x = _z3[x],
y = _objectWithoutPropertiesLoose(_z3, [x]);
y = _objectWithoutPropertiesLoose(_z3, [x].map(_toPropertyKey));
(function (_ref) {
let x = _ref.x,

View File

@@ -6,7 +6,7 @@ var _z2 = z,
y = babelHelpers.objectWithoutProperties(_z2, ["x"]);
var _z3 = z,
x = _z3[x],
y = babelHelpers.objectWithoutProperties(_z3, [x]);
y = babelHelpers.objectWithoutProperties(_z3, [x].map(babelHelpers.toPropertyKey));
(function (_ref) {
var x = _ref.x,

View File

@@ -0,0 +1,4 @@
const { [(() => 1)()]: a, ...rest } = { 1: "a" };
expect(a).toBe("a");
expect(rest).toEqual({});

View File

@@ -0,0 +1,3 @@
{
"plugins": ["transform-destructuring", "proposal-object-rest-spread"]
}

View File

@@ -0,0 +1,10 @@
const foo = {
1: "a",
2: "b",
3: "c",
};
const { [1]: bar, ...rest } = foo;
expect(bar).toBe("a");
expect(rest).toEqual({ 2: "b", 3: "c" });

View File

@@ -0,0 +1,3 @@
{
"plugins": ["transform-destructuring", "proposal-object-rest-spread"]
}