Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not tree-shake arguments that contain a spread element #3654

Merged
merged 1 commit into from Jul 2, 2020
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
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']);