Skip to content

Commit

Permalink
Deconflict unused parameters (#2972)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 29, 2019
1 parent 3ed6c52 commit 9fb1a48
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ast/scopes/ChildScope.ts
Expand Up @@ -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));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ast/scopes/ParameterScope.ts
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/ast/variables/Variable.ts
Expand Up @@ -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;
Expand Down
@@ -0,0 +1,4 @@
module.exports = {
solo: true,
description: 'does not cause conflicts when deconflicting non-included parameters'
};
@@ -0,0 +1,2 @@
export let value = 0;
export const mutate = () => value++;
@@ -0,0 +1,9 @@
import * as dep from './dep';

function test(mutate) {
dep.mutate('hello');
}

test();

assert.strictEqual(dep.value, 1);

0 comments on commit 9fb1a48

Please sign in to comment.