Rename all proposal plugins to -proposal- from -transform- (#6570)

This commit is contained in:
Henry Zhu
2017-10-27 15:26:38 -04:00
committed by GitHub
parent a94aa54230
commit c41abd79a1
599 changed files with 372 additions and 372 deletions

View File

@@ -0,0 +1,3 @@
src
test
*.log

View File

@@ -0,0 +1,88 @@
# @babel/plugin-proposal-object-rest-spread
> This plugin allows Babel to transform rest properties for object destructuring assignment and spread properties for object literals.
## Example
### Rest Properties
```js
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
```
### Spread Properties
```js
let n = { x, y, ...z };
console.log(n); // { x: 1, y: 2, a: 3, b: 4 }
```
## Installation
```sh
npm install --save-dev @babel/plugin-proposal-object-rest-spread
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["@babel/proposal-object-rest-spread"]
}
```
### Via CLI
```sh
babel --plugins @babel/proposal-object-rest-spread script.js
```
### Via Node API
```javascript
require("@babel/core").transform("code", {
plugins: ["@babel/proposal-object-rest-spread"]
});
```
## Options
### `useBuiltIns`
`boolean`, defaults to `false`.
By default, this plugin uses Babel's `extends` helper which polyfills `Object.assign`. Enabling this option will use `Object.assign` directly.
**.babelrc**
```json
{
"plugins": [
["@babel/proposal-object-rest-spread", { "useBuiltIns": true }]
]
}
```
**In**
```js
z = { x, ...y };
```
**Out**
```js
z = Object.assign({ x }, y);
```
## References
* [Proposal: Object Rest/Spread Properties for ECMAScript](https://github.com/sebmarkbage/ecmascript-rest-spread)
* [Spec](http://sebmarkbage.github.io/ecmascript-rest-spread)

View File

@@ -0,0 +1,20 @@
{
"name": "@babel/plugin-proposal-object-rest-spread",
"version": "7.0.0-beta.3",
"description": "Compile object rest and spread to ES5",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-object-rest-spread",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.3"
},
"peerDependencies": {
"@babel/core": "7.0.0-beta.3"
},
"devDependencies": {
"@babel/helper-plugin-test-runner": "7.0.0-beta.3"
}
}

View File

@@ -0,0 +1,389 @@
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
export default function({ types: t }) {
function hasRestElement(path) {
let foundRestElement = false;
path.traverse({
RestElement() {
foundRestElement = true;
path.stop();
},
});
return foundRestElement;
}
function hasSpread(node) {
for (const prop of node.properties) {
if (t.isSpreadElement(prop)) {
return true;
}
}
return false;
}
// returns an array of all keys of an object, and a status flag indicating if all extracted keys
// were converted to stringLiterals or not
// e.g. extracts {keys: ["a", "b", "3", ++x], allLiteral: false }
// from ast of {a: "foo", b, 3: "bar", [++x]: "baz"}
function extractNormalizedKeys(path) {
const props = path.node.properties;
const keys = [];
let allLiteral = true;
for (const prop of props) {
if (t.isIdentifier(prop.key) && !prop.computed) {
// since a key {a: 3} is equivalent to {"a": 3}, use the latter
keys.push(t.stringLiteral(prop.key.name));
} else if (t.isLiteral(prop.key)) {
keys.push(t.stringLiteral(String(prop.key.value)));
} else {
keys.push(prop.key);
allLiteral = false;
}
}
return { keys, allLiteral };
}
// replaces impure computed keys with new identifiers
// and returns variable declarators of these new identifiers
function replaceImpureComputedKeys(path) {
const impureComputedPropertyDeclarators = [];
for (const propPath of path.get("properties")) {
const key = propPath.get("key");
if (propPath.node.computed && !key.isPure()) {
const identifier = path.scope.generateUidIdentifierBasedOnNode(
key.node,
);
const declarator = t.variableDeclarator(identifier, key.node);
impureComputedPropertyDeclarators.push(declarator);
key.replaceWith(identifier);
}
}
return impureComputedPropertyDeclarators;
}
//expects path to an object pattern
function createObjectSpread(path, file, objRef) {
const props = path.get("properties");
const last = props[props.length - 1];
t.assertRestElement(last.node);
const restElement = t.clone(last.node);
last.remove();
const impureComputedPropertyDeclarators = replaceImpureComputedKeys(path);
const { keys, allLiteral } = extractNormalizedKeys(path);
let keyExpression;
if (!allLiteral) {
// map to toPropertyKey to handle the possible non-string values
keyExpression = t.callExpression(
t.memberExpression(t.arrayExpression(keys), t.identifier("map")),
[file.addHelper("toPropertyKey")],
);
} else {
keyExpression = t.arrayExpression(keys);
}
return [
impureComputedPropertyDeclarators,
restElement.argument,
t.callExpression(file.addHelper("objectWithoutProperties"), [
objRef,
keyExpression,
]),
];
}
function replaceRestElement(parentPath, paramPath, i, numParams) {
if (paramPath.isAssignmentPattern()) {
replaceRestElement(parentPath, paramPath.get("left"), i, numParams);
return;
}
if (paramPath.isArrayPattern() && hasRestElement(paramPath)) {
const elements = paramPath.get("elements");
for (let i = 0; i < elements.length; i++) {
replaceRestElement(parentPath, elements[i], i, elements.length);
}
}
if (paramPath.isObjectPattern() && hasRestElement(paramPath)) {
const uid = parentPath.scope.generateUidIdentifier("ref");
const declar = t.variableDeclaration("let", [
t.variableDeclarator(paramPath.node, uid),
]);
parentPath.ensureBlock();
parentPath.get("body").unshiftContainer("body", declar);
paramPath.replaceWith(uid);
}
}
return {
inherits: syntaxObjectRestSpread,
visitor: {
// taken from transform-es2015-parameters/src/destructuring.js
// function a({ b, ...c }) {}
Function(path) {
const params = path.get("params");
for (let i = params.length - 1; i >= 0; i--) {
replaceRestElement(params[i].parentPath, params[i], i, params.length);
}
},
// adapted from transform-es2015-destructuring/src/index.js#pushObjectRest
// const { a, ...b } = c;
VariableDeclarator(path, file) {
if (!path.get("id").isObjectPattern()) {
return;
}
let insertionPath = path;
path.get("id").traverse(
{
RestElement(path) {
if (!path.parentPath.isObjectPattern()) {
// Return early if the parent is not an ObjectPattern, but
// (for example) an ArrayPattern or Function, because that
// means this RestElement is an not an object property.
return;
}
if (
// skip single-property case, e.g.
// const { ...x } = foo();
// since the RHS will not be duplicated
this.originalPath.node.id.properties.length > 1 &&
!t.isIdentifier(this.originalPath.node.init)
) {
// const { a, ...b } = foo();
// to avoid calling foo() twice, as a first step convert it to:
// const _foo = foo(),
// { a, ...b } = _foo;
const initRef = path.scope.generateUidIdentifierBasedOnNode(
this.originalPath.node.init,
"ref",
);
// insert _foo = foo()
this.originalPath.insertBefore(
t.variableDeclarator(initRef, this.originalPath.node.init),
);
// replace foo() with _foo
this.originalPath.replaceWith(
t.variableDeclarator(this.originalPath.node.id, initRef),
);
return;
}
let ref = this.originalPath.node.init;
const refPropertyPath = [];
path.findParent(path => {
if (path.isObjectProperty()) {
refPropertyPath.unshift(path.node.key.name);
} else if (path.isVariableDeclarator()) {
return true;
}
});
if (refPropertyPath.length) {
refPropertyPath.forEach(prop => {
ref = t.memberExpression(ref, t.identifier(prop));
});
}
const objectPatternPath = path.findParent(path =>
path.isObjectPattern(),
);
const [
impureComputedPropertyDeclarators,
argument,
callExpression,
] = createObjectSpread(objectPatternPath, file, ref);
t.assertIdentifier(argument);
insertionPath.insertBefore(impureComputedPropertyDeclarators);
insertionPath.insertAfter(
t.variableDeclarator(argument, callExpression),
);
insertionPath = insertionPath.getSibling(insertionPath.key + 1);
if (objectPatternPath.node.properties.length === 0) {
objectPatternPath
.findParent(
path =>
path.isObjectProperty() || path.isVariableDeclarator(),
)
.remove();
}
},
},
{
originalPath: path,
},
);
},
// taken from transform-es2015-destructuring/src/index.js#visitor
// export var { a, ...b } = c;
ExportNamedDeclaration(path) {
const declaration = path.get("declaration");
if (!declaration.isVariableDeclaration()) return;
if (!hasRestElement(declaration)) return;
const specifiers = [];
for (const name in path.getOuterBindingIdentifiers(path)) {
const id = t.identifier(name);
specifiers.push(t.exportSpecifier(id, id));
}
// Split the declaration and export list into two declarations so that the variable
// declaration can be split up later without needing to worry about not being a
// top-level statement.
path.replaceWith(declaration.node);
path.insertAfter(t.exportNamedDeclaration(null, specifiers));
},
// try {} catch ({a, ...b}) {}
CatchClause(path) {
const paramPath = path.get("param");
replaceRestElement(paramPath.parentPath, paramPath);
},
// ({a, ...b} = c);
AssignmentExpression(path, file) {
const leftPath = path.get("left");
if (leftPath.isObjectPattern() && hasRestElement(leftPath)) {
const nodes = [];
const ref = path.scope.generateUidIdentifierBasedOnNode(
path.node.right,
"ref",
);
nodes.push(
t.variableDeclaration("var", [
t.variableDeclarator(ref, path.node.right),
]),
);
const [
impureComputedPropertyDeclarators,
argument,
callExpression,
] = createObjectSpread(leftPath, file, ref);
if (impureComputedPropertyDeclarators.length > 0) {
nodes.push(
t.variableDeclaration("var", impureComputedPropertyDeclarators),
);
}
const nodeWithoutSpread = t.clone(path.node);
nodeWithoutSpread.right = ref;
nodes.push(t.expressionStatement(nodeWithoutSpread));
nodes.push(
t.toStatement(
t.assignmentExpression("=", argument, callExpression),
),
);
if (ref) {
nodes.push(t.expressionStatement(ref));
}
path.replaceWithMultiple(nodes);
}
},
// taken from transform-es2015-destructuring/src/index.js#visitor
ForXStatement(path) {
const { node, scope } = path;
const leftPath = path.get("left");
const left = node.left;
// for ({a, ...b} of []) {}
if (t.isObjectPattern(left) && hasRestElement(leftPath)) {
const temp = scope.generateUidIdentifier("ref");
node.left = t.variableDeclaration("var", [
t.variableDeclarator(temp),
]);
path.ensureBlock();
node.body.body.unshift(
t.variableDeclaration("var", [t.variableDeclarator(left, temp)]),
);
return;
}
if (!t.isVariableDeclaration(left)) return;
const pattern = left.declarations[0].id;
if (!t.isObjectPattern(pattern)) return;
const key = scope.generateUidIdentifier("ref");
node.left = t.variableDeclaration(left.kind, [
t.variableDeclarator(key, null),
]);
path.ensureBlock();
node.body.body.unshift(
t.variableDeclaration(node.left.kind, [
t.variableDeclarator(pattern, key),
]),
);
},
// var a = { ...b, ...c }
ObjectExpression(path, file) {
if (!hasSpread(path.node)) return;
const useBuiltIns = file.opts.useBuiltIns || false;
if (typeof useBuiltIns !== "boolean") {
throw new Error(
"proposal-object-rest-spread currently only accepts a boolean " +
"option for useBuiltIns (defaults to false)",
);
}
const args = [];
let props = [];
function push() {
if (!props.length) return;
args.push(t.objectExpression(props));
props = [];
}
for (const prop of (path.node.properties: Array)) {
if (t.isSpreadElement(prop)) {
push();
args.push(prop.argument);
} else {
props.push(prop);
}
}
push();
if (!t.isObjectExpression(args[0])) {
args.unshift(t.objectExpression([]));
}
const helper = useBuiltIns
? t.memberExpression(t.identifier("Object"), t.identifier("assign"))
: file.addHelper("extends");
path.replaceWith(t.callExpression(helper, args));
},
},
};
}

View File

@@ -0,0 +1,4 @@
({ a1 } = c1);
({ a2, ...b2 } = c2);
console.log({ a3, ...b3 } = c3);

View File

@@ -0,0 +1,14 @@
var _c2;
({
a1
} = c1);
var _c = c2;
({
a2
} = _c);
b2 = babelHelpers.objectWithoutProperties(_c, ["a2"]);
_c;
console.log((_c2 = c3, ({
a3
} = _c2), b3 = babelHelpers.objectWithoutProperties(_c2, ["a3"]), _c2));

View File

@@ -0,0 +1,8 @@
try {} catch({ ...a34 }) {}
try {} catch({a1, ...b1}) {}
try {} catch({a2, b2, ...c2}) {}
try {} catch({a2, b2, c2: { c3, ...c4 }}) {}
// Unchanged
try {} catch(a) {}
try {} catch({ b }) {}

View File

@@ -0,0 +1,36 @@
try {} catch (_ref) {
let a34 = babelHelpers.objectWithoutProperties(_ref, []);
}
try {} catch (_ref2) {
let {
a1
} = _ref2,
b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]);
}
try {} catch (_ref3) {
let {
a2,
b2
} = _ref3,
c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]);
}
try {} catch (_ref4) {
let {
a2,
b2,
c2: {
c3
}
} = _ref4,
c4 = babelHelpers.objectWithoutProperties(_ref4.c2, ["c3"]);
} // Unchanged
try {} catch (a) {}
try {} catch ({
b
}) {}

View File

@@ -0,0 +1,5 @@
// ExportNamedDeclaration
export var { b, ...c } = asdf2;
// Skip
export var { bb, cc } = ads;
export var [ dd, ee ] = ads;

View File

@@ -0,0 +1,12 @@
// ExportNamedDeclaration
var {
b
} = asdf2,
c = babelHelpers.objectWithoutProperties(asdf2, ["b"]); // Skip
export { b, c };
export var {
bb,
cc
} = ads;
export var [dd, ee] = ads;

View File

@@ -0,0 +1,19 @@
// ForXStatement
for (var {a, ...b} of []) {}
for ({a, ...b} of []) {}
async function a() {
for await ({a, ...b} of []) {}
}
// skip
for ({a} in {}) {}
for ({a} of []) {}
async function a() {
for await ({a} of []) {}
}
for (a in {}) {}
for (a of []) {}
async function a() {
for await (a of []) {}
}

View File

@@ -0,0 +1,46 @@
// ForXStatement
for (var _ref of []) {
var {
a
} = _ref,
b = babelHelpers.objectWithoutProperties(_ref, ["a"]);
}
for (var _ref2 of []) {
var {
a
} = _ref2,
b = babelHelpers.objectWithoutProperties(_ref2, ["a"]);
}
async function a() {
for await (var _ref3 of []) {
var {
a
} = _ref3,
b = babelHelpers.objectWithoutProperties(_ref3, ["a"]);
}
} // skip
for ({
a
} in {}) {}
for ({
a
} of []) {}
async function a() {
for await ({
a
} of []) {}
}
for (a in {}) {}
for (a of []) {}
async function a() {
for await (a of []) {}
}

View File

@@ -0,0 +1,21 @@
var key, x, y, z;
// impure
key = 1;
var { [key++]: y, ...x } = { 1: 1, a: 1 };
assert.deepEqual({ a: 1 }, x);
assert.equal(key, 2);
assert.equal(1, y);
// takes care of the order
key = 1;
var { [++key]: y, [++key]: z, ...rest} = {2: 2, 3: 3};
assert.equal(y, 2);
assert.equal(z, 3);
// pure, computed property should remain as-is
key = 2;
({ [key]: y, z, ...x } = {2: "two", z: "zee"});
assert.equal(y, "two");
assert.deepEqual(x, {});
assert.equal(z, "zee");

View File

@@ -0,0 +1,3 @@
{
"minNodeVersion": "6.0.0"
}

View File

@@ -0,0 +1,21 @@
var key, x, y, z;
// impure
key = 1;
var { [key++]: y, ...x } = { 1: 1, a: 1 };
assert.deepEqual({ a: 1 }, x);
assert.equal(key, 2);
assert.equal(1, y);
// takes care of the order
key = 1;
var { [++key]: y, [++key]: z, ...rest} = {2: 2, 3: 3};
assert.equal(y, 2);
assert.equal(z, 3);
// pure, computed property should remain as-is
key = 2;
({ [key]: y, z, ...x } = {2: "two", z: "zee"});
assert.equal(y, "two");
assert.deepEqual(x, {});
assert.equal(z, "zee");

View File

@@ -0,0 +1,51 @@
var key, x, y, z; // impure
key = 1;
var _$a = {
1: 1,
a: 1
},
_ref = key++,
{
[_ref]: y
} = _$a,
x = babelHelpers.objectWithoutProperties(_$a, [_ref].map(babelHelpers.toPropertyKey));
assert.deepEqual({
a: 1
}, x);
assert.equal(key, 2);
assert.equal(1, y); // takes care of the order
key = 1;
var _$ = {
2: 2,
3: 3
},
_ref2 = ++key,
_ref3 = ++key,
{
[_ref2]: y,
[_ref3]: z
} = _$,
rest = babelHelpers.objectWithoutProperties(_$, [_ref2, _ref3].map(babelHelpers.toPropertyKey));
assert.equal(y, 2);
assert.equal(z, 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;
assert.equal(y, "two");
assert.deepEqual(x, {});
assert.equal(z, "zee");

View File

@@ -0,0 +1,15 @@
const test = {
foo: {
bar: {
baz: {
a: {
x: 1,
y: 2,
z: 3,
},
},
},
},
};
const { foo: { bar: { baz: { a: { x, ...other } } } } } = test;

View File

@@ -0,0 +1,25 @@
const test = {
foo: {
bar: {
baz: {
a: {
x: 1,
y: 2,
z: 3
}
}
}
}
};
const {
foo: {
bar: {
baz: {
a: {
x
}
}
}
}
} = test,
other = babelHelpers.objectWithoutProperties(test.foo.bar.baz.a, ["x"]);

View File

@@ -0,0 +1,10 @@
const defunct = {
outer: {
inner: {
three: 'three',
four: 'four'
}
}
}
const { outer: { inner: { three, ...other } } } = defunct

View File

@@ -0,0 +1,16 @@
const defunct = {
outer: {
inner: {
three: 'three',
four: 'four'
}
}
};
const {
outer: {
inner: {
three
}
}
} = defunct,
other = babelHelpers.objectWithoutProperties(defunct.outer.inner, ["three"]);

View File

@@ -0,0 +1,54 @@
const a = {
"3": "three",
"foo": "bar"
}
const {
[3]: omit,
...rest
} = a;
assert.deepEqual(rest, {"foo": "bar"});
assert.equal(omit, "three");
const [k1, k2, k3, k4, k5] = [null, undefined, true, false, {toString() { return "warrior"; }}];
const c = {
[k1]: "1",
[k2]: "2",
[k3]: "3",
[k4]: "4",
[k5]: "5"
};
const {
[k1]: v1,
[k2]: v2,
[k3]: v3,
[k4]: v4,
[k5]: v5,
...vrest
} = c;
assert.equal(v1, "1");
assert.equal(v2, "2");
assert.equal(v3, "3");
assert.equal(v4, "4");
assert.equal(v5, "5");
assert.deepEqual(vrest, {});
// shouldn't convert symbols to strings
const sx = Symbol();
const sy = Symbol();
const d = {
[sx]: "sx",
[sy]: "sy"
}
const {
[sx]: dx,
[sy]: dy
} = d;
assert.equal(dx, "sx");
assert.equal(dy, "sy");

View File

@@ -0,0 +1,3 @@
{
"minNodeVersion": "6.0.0"
}

View File

@@ -0,0 +1,54 @@
const a = {
"3": "three",
"foo": "bar"
}
const {
[3]: omit,
...rest
} = a;
assert.deepEqual(rest, {"foo": "bar"});
assert.equal(omit, "three");
const [k1, k2, k3, k4, k5] = [null, undefined, true, false, {toString() { return "warrior"; }}];
const c = {
[k1]: "1",
[k2]: "2",
[k3]: "3",
[k4]: "4",
[k5]: "5"
};
const {
[k1]: v1,
[k2]: v2,
[k3]: v3,
[k4]: v4,
[k5]: v5,
...vrest
} = c;
assert.equal(v1, "1");
assert.equal(v2, "2");
assert.equal(v3, "3");
assert.equal(v4, "4");
assert.equal(v5, "5");
assert.deepEqual(vrest, {});
// shouldn't convert symbols to strings
const sx = Symbol();
const sy = Symbol();
const d = {
[sx]: "sx",
[sy]: "sy"
}
const {
[sx]: dx,
[sy]: dy
} = d;
assert.equal(dx, "sx");
assert.equal(dy, "sy");

View File

@@ -0,0 +1,52 @@
const a = {
"3": "three",
"foo": "bar"
};
const {
[3]: omit
} = a,
rest = babelHelpers.objectWithoutProperties(a, ["3"]);
assert.deepEqual(rest, {
"foo": "bar"
});
assert.equal(omit, "three");
const [k1, k2, k3, k4, k5] = [null, undefined, true, false, {
toString() {
return "warrior";
}
}];
const c = {
[k1]: "1",
[k2]: "2",
[k3]: "3",
[k4]: "4",
[k5]: "5"
};
const {
[k1]: v1,
[k2]: v2,
[k3]: v3,
[k4]: v4,
[k5]: v5
} = c,
vrest = babelHelpers.objectWithoutProperties(c, [k1, k2, k3, k4, k5].map(babelHelpers.toPropertyKey));
assert.equal(v1, "1");
assert.equal(v2, "2");
assert.equal(v3, "3");
assert.equal(v4, "4");
assert.equal(v5, "5");
assert.deepEqual(vrest, {}); // shouldn't convert symbols to strings
const sx = Symbol();
const sy = Symbol();
const d = {
[sx]: "sx",
[sy]: "sy"
};
const {
[sx]: dx,
[sy]: dy
} = d;
assert.equal(dx, "sx");
assert.equal(dy, "sy");

View File

@@ -0,0 +1,7 @@
{
"plugins": [
"syntax-async-generators",
"proposal-object-rest-spread",
"external-helpers"
]
}

View File

@@ -0,0 +1,14 @@
function a({ ...a34 }) {}
function a2({a1, ...b1}) {}
function a3({a2, b2, ...c2}) {}
function a4({a3, ...c3}, {a5, ...c5}) {}
function a5({a3, b2: { ba1, ...ba2 }, ...c3}) {}
function a6({a3, b2: { ba1, ...ba2 } }) {}
function a7({a1 = 1, ...b1} = {}) {}
function a8([{...a1}]) {}
function a9([{a1, ...a2}]) {}
function a10([a1, {...a2}]) {}
// Unchanged
function b(a) {}
function b2(a, ...b) {}
function b3({ b }) {}

View File

@@ -0,0 +1,81 @@
function a(_ref) {
let a34 = babelHelpers.objectWithoutProperties(_ref, []);
}
function a2(_ref2) {
let {
a1
} = _ref2,
b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]);
}
function a3(_ref3) {
let {
a2,
b2
} = _ref3,
c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]);
}
function a4(_ref5, _ref4) {
let {
a3
} = _ref5,
c3 = babelHelpers.objectWithoutProperties(_ref5, ["a3"]);
let {
a5
} = _ref4,
c5 = babelHelpers.objectWithoutProperties(_ref4, ["a5"]);
}
function a5(_ref6) {
let {
a3,
b2: {
ba1
}
} = _ref6,
ba2 = babelHelpers.objectWithoutProperties(_ref6.b2, ["ba1"]),
c3 = babelHelpers.objectWithoutProperties(_ref6, ["a3", "b2"]);
}
function a6(_ref7) {
let {
a3,
b2: {
ba1
}
} = _ref7,
ba2 = babelHelpers.objectWithoutProperties(_ref7.b2, ["ba1"]);
}
function a7(_ref8 = {}) {
let {
a1 = 1
} = _ref8,
b1 = babelHelpers.objectWithoutProperties(_ref8, ["a1"]);
}
function a8([_ref9]) {
let a1 = babelHelpers.objectWithoutProperties(_ref9, []);
}
function a9([_ref10]) {
let {
a1
} = _ref10,
a2 = babelHelpers.objectWithoutProperties(_ref10, ["a1"]);
}
function a10([a1, _ref11]) {
let a2 = babelHelpers.objectWithoutProperties(_ref11, []);
} // Unchanged
function b(a) {}
function b2(a, ...b) {}
function b3({
b
}) {}

View File

@@ -0,0 +1,20 @@
const sym = Symbol("test");
const sym2 = Symbol("not enumerable");
const src = { a: "string" };
Object.defineProperty(src, "b", { value: "not enumerable" })
Object.defineProperty(src, sym, { enumerable: true, value: "symbol" });
Object.defineProperty(src, sym2, { value: "not enumerable" });
const {...rest} = src;
assert.strictEqual(rest[sym], "symbol");
assert.strictEqual(rest.a, "string");
assert.deepEqual(Object.getOwnPropertyNames(rest), ["a"]);
assert.deepEqual(Object.getOwnPropertySymbols(rest), [sym]);
const { [sym]: dst, ...noSym } = src;
assert.strictEqual(dst, "symbol");
assert.strictEqual(noSym.a, "string");
assert.deepEqual(Object.getOwnPropertySymbols(noSym), []);

View File

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

View File

@@ -0,0 +1,8 @@
let {
[Symbol.for("foo")]: foo,
...rest
} = {};
({ [Symbol.for("foo")]: foo, ...rest } = {});
if ({ [Symbol.for("foo")]: foo, ...rest } = {}) {}

View File

@@ -0,0 +1,22 @@
var _ref3, _Symbol$for3;
let _ref = {},
_Symbol$for = Symbol.for("foo"),
{
[_Symbol$for]: foo
} = _ref,
rest = babelHelpers.objectWithoutProperties(_ref, [_Symbol$for].map(babelHelpers.toPropertyKey));
var _ref2 = {};
var _Symbol$for2 = Symbol.for("foo");
({
[_Symbol$for2]: foo
} = _ref2);
rest = babelHelpers.objectWithoutProperties(_ref2, [_Symbol$for2].map(babelHelpers.toPropertyKey));
_ref2;
if (_ref3 = {}, _Symbol$for3 = Symbol.for("foo"), ({
[_Symbol$for3]: foo
} = _ref3), rest = babelHelpers.objectWithoutProperties(_ref3, [_Symbol$for3].map(babelHelpers.toPropertyKey)), _ref3) {}

View File

@@ -0,0 +1,19 @@
var z = {};
var { ...x } = z;
var { ...a } = { a: 1 };
var { ...x } = a.b;
var { ...x } = a();
var {x1, ...y1} = z;
x1++;
var { [a]: b, ...c } = z;
var {x1, ...y1} = z;
let {x2, y2, ...z2} = z;
const {w3, x3, y3, ...z4} = z;
let {
x: { a: xa, [d]: f, ...asdf },
y: { ...d },
...g
} = complex;
let { x4: { ...y4 } } = z;

View File

@@ -0,0 +1,42 @@
var z = {};
var x = babelHelpers.objectWithoutProperties(z, []);
var a = babelHelpers.objectWithoutProperties({
a: 1
}, []);
var x = babelHelpers.objectWithoutProperties(a.b, []);
var x = babelHelpers.objectWithoutProperties(a(), []);
var {
x1
} = z,
y1 = babelHelpers.objectWithoutProperties(z, ["x1"]);
x1++;
var {
[a]: b
} = z,
c = babelHelpers.objectWithoutProperties(z, [a].map(babelHelpers.toPropertyKey));
var {
x1
} = z,
y1 = babelHelpers.objectWithoutProperties(z, ["x1"]);
let {
x2,
y2
} = z,
z2 = babelHelpers.objectWithoutProperties(z, ["x2", "y2"]);
const {
w3,
x3,
y3
} = z,
z4 = babelHelpers.objectWithoutProperties(z, ["w3", "x3", "y3"]);
let {
x: {
a: xa,
[d]: f
}
} = complex,
asdf = babelHelpers.objectWithoutProperties(complex.x, ["a", d].map(babelHelpers.toPropertyKey)),
d = babelHelpers.objectWithoutProperties(complex.y, []),
g = babelHelpers.objectWithoutProperties(complex, ["x"]);
let {} = z,
y4 = babelHelpers.objectWithoutProperties(z.x4, []);

View File

@@ -0,0 +1,22 @@
// var { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
// assert.equal(x, 1);
// assert.equal(y, 2);
// assert.deepEqual(z, { a: 3, b: 4 });
// var complex = {
// x: { a: 1, b: 2, c: 3 },
// };
// var {
// x: { a: xa, ...xbc }
// } = complex;
// assert.equal(xa, 1);
// assert.deepEqual(xbc, { b: 2, c: 3});
// // own properties
// function ownX({ ...properties }) {
// return properties.x;
// }
// assert.equal(ownX(Object.create({ x: 1 })), undefined);

View File

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

View File

@@ -0,0 +1,8 @@
let {
a: [b, ...arrayRest],
c = function(...functionRest){},
...objectRest
} = {
a: [1, 2, 3, 4],
d: "oyez"
};

View File

@@ -0,0 +1,9 @@
let _a$d = {
a: [1, 2, 3, 4],
d: "oyez"
},
{
a: [b, ...arrayRest],
c = function (...functionRest) {}
} = _a$d,
objectRest = babelHelpers.objectWithoutProperties(_a$d, ["a", "c"]);

View File

@@ -0,0 +1,3 @@
z = { x, ...y };
z = { x, w: { ...y } };

View File

@@ -0,0 +1,9 @@
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); }
z = _extends({
x
}, y);
z = {
x,
w: _extends({}, y)
};

View File

@@ -0,0 +1 @@
({ x, ...y, a, ...b, c });

View File

@@ -0,0 +1,9 @@
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); }
_extends({
x
}, y, {
a
}, b, {
c
});

View File

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

View File

@@ -0,0 +1,3 @@
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); }
var z = _extends({}, x);

View File

@@ -0,0 +1,9 @@
import props from "props";
console.log(props);
(function(){
const { ...props } = this.props;
console.log(props);
})();

View File

@@ -0,0 +1,10 @@
"use strict";
var _props = babelHelpers.interopRequireDefault(require("props"));
console.log(_props.default);
(function () {
const props = babelHelpers.objectWithoutProperties(this.props, []);
console.log(props);
})();

View File

@@ -0,0 +1,8 @@
{
"plugins": [
"transform-es2015-modules-commonjs",
"transform-es2015-destructuring",
"proposal-object-rest-spread",
"external-helpers"
]
}

View File

@@ -0,0 +1,7 @@
const { s, ...t } = foo();
const { s: { q1, ...q2 }, ...q3 } = bar();
const { a } = foo(({ b, ...c }) => {
console.log(b, c);
});

View File

@@ -0,0 +1,24 @@
const _foo = foo(),
{
s
} = _foo,
t = babelHelpers.objectWithoutProperties(_foo, ["s"]);
const _bar = bar(),
{
s: {
q1
}
} = _bar,
q2 = babelHelpers.objectWithoutProperties(_bar.s, ["q1"]),
q3 = babelHelpers.objectWithoutProperties(_bar, ["s"]);
const {
a
} = foo((_ref) => {
let {
b
} = _ref,
c = babelHelpers.objectWithoutProperties(_ref, ["b"]);
console.log(b, c);
});

View File

@@ -0,0 +1,10 @@
const { x, ...y } = a,
z = foo(y);
const { ...s } = r,
t = foo(s);
// ordering is preserved
var l = foo(),
{ m: { n, ...o }, ...p } = bar(),
q = baz();

View File

@@ -0,0 +1,18 @@
const {
x
} = a,
y = babelHelpers.objectWithoutProperties(a, ["x"]),
z = foo(y);
const s = babelHelpers.objectWithoutProperties(r, []),
t = foo(s); // ordering is preserved
var l = foo(),
_bar = bar(),
{
m: {
n
}
} = _bar,
o = babelHelpers.objectWithoutProperties(_bar.m, ["n"]),
p = babelHelpers.objectWithoutProperties(_bar, ["m"]),
q = baz();

View File

@@ -0,0 +1,6 @@
{
"plugins": [
"proposal-object-rest-spread",
"external-helpers"
]
}

View File

@@ -0,0 +1,4 @@
{
"plugins": [["proposal-object-rest-spread", { "useBuiltIns": "invalidOption" }]],
"throws": "proposal-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)"
}

View File

@@ -0,0 +1,3 @@
z = Object.assign({
x
}, y);

View File

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

View File

@@ -0,0 +1,3 @@
import runner from "@babel/helper-plugin-test-runner";
runner(__dirname);