Skip to content

Commit b16f610

Browse files
committed
feature: @putout/plugin-declare-before-reference: remove-useless-arguments
1 parent 79a2076 commit b16f610

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

packages/plugin-declare-before-reference/lib/declare-before-reference.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ function getName(path) {
145145
} while (path = path.get('object'));
146146
}
147147

148-
function getKeys(path) {
149-
const {id} = path.node;
148+
function getKeys({node}) {
149+
if (!node)
150+
return [];
151+
152+
const {id} = node;
150153

151154
if (!id)
152155
return [];

packages/plugin-declare-before-reference/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"@putout/plugin-promises": "*",
3939
"@putout/plugin-putout": "*",
4040
"@putout/plugin-remove-nested-blocks": "*",
41+
"@putout/plugin-remove-useless-arguments": "*",
42+
"@putout/plugin-remove-useless-variables": "*",
4143
"@putout/plugin-reuse-duplicate-init": "*",
4244
"@putout/plugin-tape": "*",
4345
"@putout/plugin-try-catch": "*",

packages/plugin-declare-before-reference/test/declare-before-reference.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as removeNestedBlocks from '@putout/plugin-remove-nested-blocks';
77
import * as nodejs from '@putout/plugin-nodejs';
88
import * as reuseDuplicateInit from '@putout/plugin-reuse-duplicate-init';
99
import * as tape from '@putout/plugin-tape';
10+
import * as removeUselessVariables from '@putout/plugin-remove-useless-variables';
11+
import * as removeUselessArguments from '@putout/plugin-remove-useless-arguments';
1012
import * as declare from '../lib/declare-before-reference.js';
1113

1214
const addTEnd = tape.rules['add-t-end'];
@@ -143,3 +145,11 @@ test('plugin-declare-before-reference: no report: cross-reference', (t) => {
143145
t.noReport('cross-reference');
144146
t.end();
145147
});
148+
149+
test('plugin-declare-before-reference: transform: remove-useless-variables', (t) => {
150+
t.transform('remove-useless-variables', {
151+
'remove': removeUselessVariables.rules.remove,
152+
'remove-useless-arguments': removeUselessArguments,
153+
});
154+
t.end();
155+
});

packages/plugin-declare-before-reference/test/fixture/cross-reference-fix.js

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const log = () => {};
2+
3+
const x = {
4+
#default_stateChangeHandler(state, oldState) {
5+
log();
6+
},
7+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const noop = () => {};
2+
const log = noop;
3+
4+
const x = {
5+
#default_stateChangeHandler(state, oldState) {
6+
log(`state change: ${oldState} -> ${state}`);
7+
}
8+
};

0 commit comments

Comments
 (0)