diff --git a/src/ast/scopes/ParameterScope.ts b/src/ast/scopes/ParameterScope.ts index 1faecfddef7..fe3b56904c8 100644 --- a/src/ast/scopes/ParameterScope.ts +++ b/src/ast/scopes/ParameterScope.ts @@ -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]; diff --git a/test/function/samples/spread-arguments-unused/_config.js b/test/function/samples/spread-arguments-unused/_config.js new file mode 100644 index 00000000000..4ad21b60eac --- /dev/null +++ b/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)' +}; diff --git a/test/function/samples/spread-arguments-unused/main.js b/test/function/samples/spread-arguments-unused/main.js new file mode 100644 index 00000000000..b56d630d119 --- /dev/null +++ b/test/function/samples/spread-arguments-unused/main.js @@ -0,0 +1,5 @@ +function test(unused, used) { + assert.strictEqual(used, 'used'); +} + +test(...['unused', 'used']);