Skip to content

Commit

Permalink
Do not create invalid code if a function argument is an empty object …
Browse files Browse the repository at this point in the history
…pattern (#3998)
  • Loading branch information
lukastaegert committed Mar 16, 2021
1 parent 770da18 commit 9cae40d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/ast/scopes/ParameterScope.ts
Expand Up @@ -64,12 +64,17 @@ export default class ParameterScope extends ChildScope {
const arg = args[index];
if (paramVars) {
calledFromTryStatement = false;
for (const variable of paramVars) {
if (variable.included) {
argIncluded = true;
}
if (variable.calledFromTryStatement) {
calledFromTryStatement = true;
if (paramVars.length === 0) {
// handle empty destructuring
argIncluded = true;
} else {
for (const variable of paramVars) {
if (variable.included) {
argIncluded = true;
}
if (variable.calledFromTryStatement) {
calledFromTryStatement = true;
}
}
}
}
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
description: 'does not tree-shake arguments where the corresponding parameters have side-effects'
};
9 changes: 9 additions & 0 deletions test/function/samples/unused-parameter-side-effects/main.js
@@ -0,0 +1,9 @@
let sideEffects = 0;

function destructured({}) {
sideEffects++;
}

destructured({});

assert.strictEqual(sideEffects, 1);

0 comments on commit 9cae40d

Please sign in to comment.