Skip to content

Commit

Permalink
Filter null array elements, add early return, remove optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-kez committed Sep 2, 2021
1 parent 8ace7f1 commit ab3b603
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/babel-plugin-proposal-object-rest-spread/src/index.js
Expand Up @@ -242,21 +242,25 @@ export default declare((api, opts) => {

function hasMoreThanOneBinding(node) {
// ArrayPattern
if (node?.elements) {
if (node.elements.length > 1) return true;
else return hasMoreThanOneBinding(node.elements[0]);
if (node.elements) {
const nonNullElements = node.elements.filter(element => element !== null);
if (nonNullElements.length > 1) return true;
else return hasMoreThanOneBinding(nonNullElements[0]);
// ObjectPattern
} else if (node?.properties) {
} else if (node.properties) {
if (node.properties.length > 1) return true;
// Case of `const {} = {}`. This shouldn't be hit as
// we currently call `hasMoreThanOneBinding` only under visitRestElements.
else if (node.properties.length === 0) return false;
else return hasMoreThanOneBinding(node.properties[0]);
// ObjectProperty
} else if (node?.value) {
else return hasMoreThanOneBinding(node.value);
} else if (node.value) {
return hasMoreThanOneBinding(node.value);
// AssignmentPattern
} else if (node?.left) {
} else if (node.left) {
return hasMoreThanOneBinding(node.left);
// RestElement
} else if (node?.argument) {
} else if (node.argument) {
return hasMoreThanOneBinding(node.argument);
} else {
// node is Identifier or MemberExpression
Expand Down
Expand Up @@ -28,3 +28,11 @@ const [[ ...y23 ] = []] = z();
const [{ ...y24 } = []] = z();
const { x25: [ ...y25 ] = []} = z();
const { x26: [ q26, ...y26 ] = []} = z();
const {} = {};
const [,,x27] = z();
const {x28: [,,{...y28}]} = z();
const {x29: [,,{q29, ...y29}]} = z();
const [,,{y30, ...x30}] = z();
const [,,{...x31}] = z();
const { x32: { }, w32: { ...y32 } } = z();
const [,,{}, {...q32}] = z();
Expand Up @@ -138,3 +138,34 @@ const {
const {
x26: [q26, ...y26] = []
} = z();
const {} = {};
const [,, x27] = z();

const _z14 = z(),
{} = _z14,
y28 = babelHelpers.extends({}, _z14.x28);

const _z15 = z(),
{
x29: [,, {
q29
}]
} = _z15,
y29 = babelHelpers.objectWithoutProperties(_z15.x29, ["q29"]);

const [,, _ref4] = z();
const {
y30
} = _ref4,
x30 = babelHelpers.objectWithoutProperties(_ref4, ["y30"]);
const [,, _ref5] = z();
const x31 = babelHelpers.extends({}, _ref5);

const _z16 = z(),
{
x32: {}
} = _z16,
y32 = babelHelpers.extends({}, _z16.w32);

const [,, {}, _ref6] = z();
const q32 = babelHelpers.extends({}, _ref6);

0 comments on commit ab3b603

Please sign in to comment.