Skip to content

Commit 9e83fcb

Browse files
committed
feature: variables: remove-unused: ArrayPattern inside ArrayPattern: add support
1 parent fa2b4d3 commit 9e83fcb

File tree

9 files changed

+25
-22
lines changed

9 files changed

+25
-22
lines changed

packages/engine-runner/lib/progress.spec.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ test('putout: runner: progress: start', async (t) => {
1616
]);
1717
`;
1818

19-
const [[{
20-
pluginsIndex,
21-
pluginsCount,
22-
}]] = await Promise.all([
19+
const [[{pluginsCount}]] = await Promise.all([
2320
once(progress, 'start'),
2421
putout(source, {
2522
progress,
@@ -45,10 +42,7 @@ test('putout: runner: progress: end', async (t) => {
4542
]);
4643
`;
4744

48-
const [[{
49-
pluginsIndex,
50-
pluginsCount,
51-
}]] = await Promise.all([
45+
const [[{pluginsCount}]] = await Promise.all([
5246
once(progress, 'end'),
5347
putout(source, {
5448
progress,
@@ -74,10 +68,7 @@ test('putout: runner: progress: push', async (t) => {
7468
]);
7569
`;
7670

77-
const [[{
78-
pluginsIndex,
79-
pluginsCount,
80-
}]] = await Promise.all([
71+
const [[{pluginsCount}]] = await Promise.all([
8172
once(progress, 'push'),
8273
putout(source, {
8374
runPlugins,

packages/operate/lib/properties/traverse-properties.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ test('operate: traverse-properties: filesystem', async (t) => {
203203
]);
204204
`;
205205

206-
const [[{
207-
pluginsIndex,
208-
pluginsCount,
209-
}]] = await Promise.all([
206+
const [[{pluginsIndex}]] = await Promise.all([
210207
once(progress, 'push'),
211208
putout(source, {
212209
progress,

packages/plugin-variables/lib/remove-unused/fixture/destr-nested-vars.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ const defaultProcessors = [];
1414
const [error, {
1515
processors = defaultProcessors,
1616
}] = getOptions();
17+
18+
const [[{
19+
pluginsCount,
20+
}]] = getOptions();

packages/plugin-variables/lib/remove-unused/get-vars.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ test('remove-unused-variables: get-vars: destr nested vars', (t) => {
737737
processors: d_,
738738
obj: du,
739739
world: d_,
740+
pluginsCount: d_,
740741
}];
741742

742743
t.deepEqual(result, expected);

packages/plugin-variables/lib/remove-unused/get-vars/get-vars.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default ({use, declare, addParams}) => {
4040

4141
const traverseTmpl = traverseTemplateLiteral(use);
4242
const traverseArray = traverseArrayExpression(use);
43+
const declareArray = traverseArrayExpression(declare);
4344

4445
return {
4546
'ObjectExpression'(path) {
@@ -144,6 +145,11 @@ export default ({use, declare, addParams}) => {
144145
continue;
145146
}
146147

148+
if (elPath.isArrayPattern()) {
149+
declareArray(elPath.get('elements'));
150+
continue;
151+
}
152+
147153
if (elPath.isAssignmentPattern()) {
148154
const leftPath = elPath.get('left');
149155
const rightPath = elPath.get('right');

packages/plugin-variables/lib/remove-unused/get-vars/traverse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const traverseArrayExpression = (use) => {
125125
for (const elementPath of elementsPaths) {
126126
const {node} = elementPath;
127127

128-
if (isObjectExpression(node))
128+
if (node.properties)
129129
traverseObjExpression(elementPath.get('properties'));
130130
}
131131
};

packages/plugin-variables/lib/remove-unused/putout.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from 'supertape';
22
import _putout from 'putout';
3+
import montag from 'montag';
34
import {readFixtures} from './fixture.js';
45
import * as removeUnusedVariables from './index.js';
56

@@ -110,7 +111,12 @@ test('remove-unused-variables: putout: destr vars', (t) => {
110111

111112
test('remove-unused-variables: putout: destr nested vars', (t) => {
112113
const {code} = putout(fixture.destrNestedVars);
113-
const expected = 'const [, {}] = getOptions();\n';
114+
const expected = montag`
115+
const [, {}] = getOptions();
116+
117+
const [[{}]] = getOptions();
118+
119+
`;
114120

115121
t.equal(code, expected);
116122
t.end();

packages/plugin-variables/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint-plugin-putout": "^29.0.0",
5050
"just-camel-case": "^6.2.0",
5151
"madrun": "^11.0.0",
52+
"montag": "^1.2.1",
5253
"nodemon": "^3.0.1",
5354
"supertape": "^11.3.1",
5455
"try-catch": "^3.0.1"

packages/putout/test/putout.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,7 @@ test('putout: progress', async (t) => {
829829
]);
830830
`;
831831

832-
const [[{
833-
pluginsIndex,
834-
pluginsCount,
835-
}]] = await Promise.all([
832+
const [[{pluginsCount}]] = await Promise.all([
836833
once(progress, 'push'),
837834
putout(source, {
838835
progress,

0 commit comments

Comments
 (0)