Skip to content

Commit b494454

Browse files
committed
feature: @putout/plugin-apply-arrow: different scopes
1 parent 719111b commit b494454

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

packages/plugin-apply-arrow/lib/apply-arrow.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ module.exports.match = () => ({
1212
const {name} = __a;
1313
const binding = path.parentPath.scope.bindings[name];
1414

15+
if (!binding.referenced)
16+
return true;
17+
1518
if (path.parentPath.isExportNamedDeclaration())
1619
return binding.references === 1;
1720

18-
return !binding.referenced;
21+
const [ref] = binding.referencePaths;
22+
23+
return ref.scope.uid !== binding.scope.uid;
1924
},
2025
});
2126

packages/plugin-apply-arrow/test/apply-arrow.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ test('putout: apply-arrow: transform', (t) => {
2222
t.end();
2323
});
2424

25+
test('putout: apply-arrow: transform: other-scope-reference', (t) => {
26+
t.transform('other-scope-reference');
27+
t.end();
28+
});
29+
2530
test('putout: apply-arrow: no report: long', (t) => {
2631
t.noReport('long');
2732
t.end();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const createPath = ({tokens, start, end}) => ({
2+
isNextPunctuator: createIsNextPunctuator({
3+
tokens,
4+
end,
5+
}),
6+
});
7+
8+
const createIsNextPunctuator = ({tokens, end}) => () => {
9+
const current = tokens[end];
10+
11+
if (!current)
12+
return false;
13+
14+
return isPunctuator(current, ';');
15+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const createPath = ({tokens, start, end}) => ({
2+
isNextPunctuator: createIsNextPunctuator({
3+
tokens,
4+
end,
5+
}),
6+
});
7+
8+
function createIsNextPunctuator({tokens, end}) {
9+
return () => {
10+
const current = tokens[end];
11+
12+
if (!current)
13+
return false;
14+
15+
return isPunctuator(current, ';');
16+
};
17+
}

0 commit comments

Comments
 (0)