Skip to content

Commit 1c5d548

Browse files
committed
refactor: @putout/plugin-esm: sort-imports-by-specifiers
1 parent 225eddc commit 1c5d548

File tree

1 file changed

+7
-4
lines changed
  • packages/plugin-esm/lib/sort-imports-by-specifiers

1 file changed

+7
-4
lines changed

packages/plugin-esm/lib/sort-imports-by-specifiers/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ module.exports.traverse = ({push}) => ({
2929
if (nextPath.node.specifiers.length !== 1)
3030
return;
3131

32-
const is = isExcluded(source, nextPath, {
32+
const first = source.value;
33+
const second = nextPath.node.source.value;
34+
35+
const is = isExcluded(first, second, {
3336
direct: [
3437
['node:', 'node:'],
3538
['#', '#'],
@@ -50,14 +53,14 @@ module.exports.traverse = ({push}) => ({
5053
},
5154
});
5255

53-
function isExcluded(source, nextPath, {direct, reversed}) {
56+
function isExcluded(first, second, {direct, reversed}) {
5457
for (const [current, next] of direct) {
55-
if (source.value.startsWith(current) && !nextPath.node.source.value.startsWith(next))
58+
if (first.startsWith(current) && !second.startsWith(next))
5659
return true;
5760
}
5861

5962
for (const [current, next] of reversed) {
60-
if (!source.value.startsWith(current) && nextPath.node.source.value.startsWith(next))
63+
if (!first.startsWith(current) && second.startsWith(next))
6164
return true;
6265
}
6366

0 commit comments

Comments
 (0)