Skip to content

Commit

Permalink
Do not tree-shake arguments that contain a spread element (#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 2, 2020
1 parent 1aeb23b commit 1ebaa09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ast/scopes/ParameterScope.ts
Expand Up @@ -51,6 +51,14 @@ export default class ParameterScope extends ChildScope {
let calledFromTryStatement = false;
let argIncluded = false;
const restParam = this.hasRest && this.parameters[this.parameters.length - 1];
for (const checkedArg of args) {
if (checkedArg instanceof SpreadElement) {
for (const arg of args) {
arg.include(context, false);
}
break;
}
}
for (let index = args.length - 1; index >= 0; index--) {
const paramVars = this.parameters[index] || restParam;
const arg = args[index];
Expand Down
4 changes: 4 additions & 0 deletions test/function/samples/spread-arguments-unused/_config.js
@@ -0,0 +1,4 @@
module.exports = {
description:
'handles using the spread operator to add arguments when the first argument is unused (#3652)'
};
5 changes: 5 additions & 0 deletions test/function/samples/spread-arguments-unused/main.js
@@ -0,0 +1,5 @@
function test(unused, used) {
assert.strictEqual(used, 'used');
}

test(...['unused', 'used']);

0 comments on commit 1ebaa09

Please sign in to comment.