Skip to content

Commit 430290e

Browse files
committed
Optimized canReorderItems
1 parent 0e0d34a commit 430290e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/rules/order-imports.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ function canCrossNodeWhileReorder(node: NodeOrToken): boolean {
191191
function canReorderItems(firstNode: NodeOrToken, secondNode: NodeOrToken): boolean {
192192
const parent = firstNode.parent;
193193
const firstIndex = parent.body.indexOf(firstNode);
194-
const secondIndex = parent.body.indexOf(secondNode);
195-
const nodesBetween = parent.body.slice(firstIndex, secondIndex + 1);
196-
for (const nodeBetween of nodesBetween) {
197-
if (!canCrossNodeWhileReorder(nodeBetween)) {
194+
const secondIndex = parent.body.indexOf(secondNode, firstIndex);
195+
if (firstIndex === -1 || secondIndex === -1) return false;
196+
for (let i = firstIndex; i <= secondIndex; i++) {
197+
if (!canCrossNodeWhileReorder(parent.body[i])) {
198198
return false;
199199
}
200200
}

0 commit comments

Comments
 (0)