diff --git a/src/ast-utils.js b/src/ast-utils.js index cc6e901..4eaeb7f 100644 --- a/src/ast-utils.js +++ b/src/ast-utils.js @@ -60,6 +60,10 @@ const extractors = { AssignmentPattern(names, node) { extractors[node.left.type](names, node.left); + }, + + MemberExpression(names, node) { + extractors[node.property.type](names, node.property) } }; diff --git a/test/samples/array-destructuring-assignment/main.js b/test/samples/array-destructuring-assignment/main.js new file mode 100644 index 0000000..451ba3e --- /dev/null +++ b/test/samples/array-destructuring-assignment/main.js @@ -0,0 +1,9 @@ + +function shuffleArray(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } +} + +exports.shuffleArray = shuffleArray; diff --git a/test/test.js b/test/test.js index f4b4033..6deae88 100644 --- a/test/test.js +++ b/test/test.js @@ -727,6 +727,38 @@ var esm = /*#__PURE__*/Object.freeze({ var main = esm; module.exports = main; +` + ); + }); + + it('handles array destructuring assignment', async () => { + const bundle = await rollup({ + input: 'samples/array-destructuring-assignment/main.js', + plugins: [commonjs({ sourceMap: true })] + }); + + const code = await getCodeFromBundle(bundle); + assert.equal( + code, + `'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +function shuffleArray(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } +} + +var shuffleArray_1 = shuffleArray; + +var main = { + shuffleArray: shuffleArray_1 +}; + +exports.default = main; +exports.shuffleArray = shuffleArray_1; ` ); });