diff --git a/src/ast/scopes/ChildScope.ts b/src/ast/scopes/ChildScope.ts index fe96b8d4e2c..03531b1ba45 100644 --- a/src/ast/scopes/ChildScope.ts +++ b/src/ast/scopes/ChildScope.ts @@ -67,7 +67,7 @@ export default class ChildScope extends Scope { } } for (const [name, variable] of this.variables) { - if (variable.included) { + if (variable.included || variable.alwaysRendered) { variable.setSafeName(getSafeName(name, usedNames)); } } diff --git a/src/ast/scopes/ParameterScope.ts b/src/ast/scopes/ParameterScope.ts index c5823008da7..316129816a1 100644 --- a/src/ast/scopes/ParameterScope.ts +++ b/src/ast/scopes/ParameterScope.ts @@ -38,6 +38,11 @@ export default class ParameterScope extends ChildScope { addParameterVariables(parameters: LocalVariable[][], hasRest: boolean) { this.parameters = parameters; + for (const parameterList of parameters) { + for (const parameter of parameterList) { + parameter.alwaysRendered = true; + } + } this.hasRest = hasRest; } diff --git a/src/ast/variables/Variable.ts b/src/ast/variables/Variable.ts index a6dc7b74695..d8d61042286 100644 --- a/src/ast/variables/Variable.ts +++ b/src/ast/variables/Variable.ts @@ -11,6 +11,7 @@ import { ImmutableEntityPathTracker } from '../utils/ImmutableEntityPathTracker' import { LiteralValueOrUnknown, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_VALUE } from '../values'; export default class Variable implements ExpressionEntity { + alwaysRendered = false; exportName: string | null = null; included = false; isId = false; diff --git a/test/function/samples/argument-treeshaking-parameter-conflict/_config.js b/test/function/samples/argument-treeshaking-parameter-conflict/_config.js new file mode 100644 index 00000000000..4c000c2a02b --- /dev/null +++ b/test/function/samples/argument-treeshaking-parameter-conflict/_config.js @@ -0,0 +1,4 @@ +module.exports = { + solo: true, + description: 'does not cause conflicts when deconflicting non-included parameters' +}; diff --git a/test/function/samples/argument-treeshaking-parameter-conflict/dep.js b/test/function/samples/argument-treeshaking-parameter-conflict/dep.js new file mode 100644 index 00000000000..37b88118823 --- /dev/null +++ b/test/function/samples/argument-treeshaking-parameter-conflict/dep.js @@ -0,0 +1,2 @@ +export let value = 0; +export const mutate = () => value++; diff --git a/test/function/samples/argument-treeshaking-parameter-conflict/main.js b/test/function/samples/argument-treeshaking-parameter-conflict/main.js new file mode 100644 index 00000000000..3b6e7314f17 --- /dev/null +++ b/test/function/samples/argument-treeshaking-parameter-conflict/main.js @@ -0,0 +1,9 @@ +import * as dep from './dep'; + +function test(mutate) { + dep.mutate('hello'); +} + +test(); + +assert.strictEqual(dep.value, 1);