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

Commit

Permalink
Fix #358: handle array destructuring assignment (#379)
Browse files Browse the repository at this point in the history
Also a new test case is added to `misc tests -> misc tests`
  • Loading branch information
Tundon authored and lukastaegert committed Mar 25, 2019
1 parent e4eb949 commit c66829b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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

0 comments on commit c66829b

Please sign in to comment.