Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Fix #358: handle array destructuring assignment #379

Merged
merged 1 commit into from Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ast-utils.js
Expand Up @@ -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)
}
};

Expand Down
9 changes: 9 additions & 0 deletions 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;
32 changes: 32 additions & 0 deletions test/test.js
Expand Up @@ -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;
`
);
});
Expand Down