Skip to content

Commit

Permalink
feature: @putout/plugin-remove-useless-variables: declaration: re-ass…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Sep 26, 2024
1 parent 05a2b37 commit 559fcd1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let newVal, oldAddr = oldState.config.address[id];

if (oldAddr != null) {
newVal = getter(state);
}

state.values[idx] = newVal;
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ module.exports.match = ({options}) => ({
if (binding.referencePaths.length !== 1)
return false;

if (binding.constantViolations.length)
return false;

if (!binding.path.isVariableDeclarator())
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ test('remove usless variables: declaration: no transform: other-scope', (t) => {
t.noTransform('other-scope');
t.end();
});

test('remove usless variables: declaration: no transform: re-assigned', (t) => {
t.noTransform('re-assign');
t.end();
});

0 comments on commit 559fcd1

Please sign in to comment.