Skip to content

Commit 31fb18a

Browse files
committed
feature: @putout/plugin-declare-before-reference: variables/apply-declarations-order
1 parent 0be5439 commit 31fb18a

File tree

7 files changed

+21
-4
lines changed

7 files changed

+21
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export const traverse = ({push}) => ({
9494
if (compareAny(getName(referenceParentPath), getKeys(path)))
9595
break;
9696

97+
if (path.key < referencePath.parentPath.parentPath.key)
98+
break;
99+
97100
const [own, pathLoc] = getLoc(path);
98101
const [referenceOwn, referenceLoc] = getLoc(referencePath);
99102

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import * as args from '@putout/plugin-arguments';
1212
import * as destructuring from '@putout/plugin-destructuring';
1313
import * as declare from '../lib/declare-before-reference.js';
1414

15-
const mergeDestructuringProperties = destructuring.rules['merge-properties'];
15+
const mergeProperties = destructuring.rules['merge-properties'];
16+
const applyDeclarationsOrder = variables.rules['apply-declarations-order'];
1617
const removeUselessVariables = variables.rules['remove-useless'];
1718
const reuseDuplicateInit = variables.rules['reuse-duplicate-init'];
1819

@@ -188,7 +189,15 @@ test('plugin-merge-destructuring-properties: transform: merge-destructuring-prop
188189
t.transform('merge-destructuring-properties', {
189190
'printer/declare': printer.rules.declare,
190191
'nodejs/declare-after-require': nodejs.rules['declare-after-require'],
191-
'merge-destructuring-properties': mergeDestructuringProperties,
192+
'destructuring/merge-properties': mergeProperties,
193+
});
194+
t.end();
195+
});
196+
197+
test('plugin-merge-destructuring-properties: no report after transform: apply-declarations-order', (t) => {
198+
t.noReportAfterTransform('apply-declarations-order', {
199+
'variables/apply-declarations-order': applyDeclarationsOrder,
200+
'variables/reuse-duplicate-init': reuseDuplicateInit,
192201
});
193202
t.end();
194203
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const process = require('node:process');
2+
const {env} = require('node:process');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const {env} = require('node:process');
2+
const process = require('node:process');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports.fix = ({path, lefts, right, merged}) => {
22
if (merged) {
33
const rightPath = path.get('right');
4-
const {right, left} = rightPath.node;
54
const {object, property} = left;
5+
const {right, left} = rightPath.node;
66
}
77
};

packages/plugin-declare-before-reference/test/fixture/merge-destructuring-properties-fix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3+
const {types} = require('@putout/babel');
34
const {
45
isForOf,
56
isCoupleLines,
67
exists,
78
} = require('../../is');
89

9-
const {types} = require('@putout/babel');
1010
const {
1111
isObjectExpression,
1212
isIdentifier,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
const {types, operator} = require('putout');
2+
23
const {remove} = operator;
34
remove(path);

0 commit comments

Comments
 (0)