diff --git a/packages/babel-plugin-proposal-object-rest-spread/src/index.js b/packages/babel-plugin-proposal-object-rest-spread/src/index.js index 1ac3b3af3b..2bf068e21e 100644 --- a/packages/babel-plugin-proposal-object-rest-spread/src/index.js +++ b/packages/babel-plugin-proposal-object-rest-spread/src/index.js @@ -150,6 +150,12 @@ export default function(api, opts) { path.get("id").traverse( { + // If there's a default-value AssignmentPattern within the ObjectPattern, + // we should not traverse into it, lest we end up in another function body. + // (The parent traversal will handle it.) + AssignmentPattern(path) { + path.skip(); + }, RestElement(path) { if (!path.parentPath.isObjectPattern()) { // Return early if the parent is not an ObjectPattern, but diff --git a/packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7388/input.js b/packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7388/input.js new file mode 100644 index 0000000000..a311921880 --- /dev/null +++ b/packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7388/input.js @@ -0,0 +1,12 @@ +function fn0(obj0) { + const { + fn1 = (obj1 = {}) => { + const { + fn2 = (obj2 = {}) => { + const {a, ...rest} = obj2; + console.log(rest); + } + } = obj1; + } + } = obj0; +} diff --git a/packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7388/output.js b/packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7388/output.js new file mode 100644 index 0000000000..97254741cb --- /dev/null +++ b/packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7388/output.js @@ -0,0 +1,15 @@ +function fn0(obj0) { + const { + fn1 = (obj1 = {}) => { + const { + fn2 = (obj2 = {}) => { + const { + a + } = obj2, + rest = babelHelpers.objectWithoutProperties(obj2, ["a"]); + console.log(rest); + } + } = obj1; + } + } = obj0; +}