Skip to content

Commit 0be5439

Browse files
committed
feature: @putout/plugin-variables: apply-destructuring-order: exclude not ObjectPattern
1 parent 1f7efd7 commit 0be5439

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const [dirPath] = findFile(ast, '/');
2+
3+
moveFile(dirPath, dirPath);
4+
5+
const result = findFile(ast, '/');

packages/plugin-variables/lib/apply-declarations-order/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
isVariableDeclaration,
1212
isIdentifier,
1313
isCallExpression,
14+
isObjectPattern,
1415
} = types;
1516

1617
export const report = () => `Apply declarations order`;
@@ -33,11 +34,8 @@ export const traverse = ({push}) => ({
3334

3435
const prev = path.getAllPrevSiblings();
3536

36-
for (const current of prev.filter(isVariableDeclaration)) {
37-
const {__c, __d} = getTemplateValues(current, 'const __c = __d');
38-
39-
if (isIdentifier(__c))
40-
continue;
37+
for (const current of prev.filter(isObjectDestructuring)) {
38+
const {__d} = getTemplateValues(current, 'const __c = __d');
4139

4240
if (compare(__b, __d))
4341
push({
@@ -47,3 +45,10 @@ export const traverse = ({push}) => ({
4745
}
4846
},
4947
});
48+
49+
function isObjectDestructuring(path) {
50+
if (!isVariableDeclaration(path))
51+
return false;
52+
53+
return isObjectPattern(path.node.declarations[0].id);
54+
}

packages/plugin-variables/lib/apply-declarations-order/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ test('variables: apply-declarations-order: no report: literal', (t) => {
2626
t.noReport('literal');
2727
t.end();
2828
});
29+
30+
test('variables: apply-declarations-order: no report: array', (t) => {
31+
t.noReport('array');
32+
t.end();
33+
});

0 commit comments

Comments
 (0)