Skip to content

Commit 9b1f6a0

Browse files
committed
feature: @putout/plugin-extract-keywords-from-variables: switch places of paths
1 parent 29aed32 commit 9b1f6a0

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"extract-keywords-from-variables": "on"
4+
}
5+
}

packages/plugin-extract-keywords-from-variables/lib/extract-keywords-from-variables.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ const keywords = [
1515

1616
module.exports.report = () => `Extract 'export' from variable`;
1717

18-
module.exports.fix = ({path, keywordPath}) => {
19-
if (keywordPath.node.id.name === 'export')
20-
replaceWith(path, ExportNamedDeclaration(path.node));
18+
module.exports.fix = ({path, nextPath}) => {
19+
if (path.node.id.name === 'export')
20+
replaceWith(nextPath, ExportNamedDeclaration(nextPath.node));
2121

22-
if (keywordPath.node.id.name === 'const')
23-
replaceWith(path, VariableDeclaration('const', [VariableDeclarator(path.node.expression.left, path.node.expression.right)]));
22+
if (path.node.id.name === 'const')
23+
replaceWith(nextPath, VariableDeclaration('const', [VariableDeclarator(nextPath.node.expression.left, nextPath.node.expression.right)]));
2424

25-
remove(keywordPath);
25+
remove(path);
2626
};
2727

2828
module.exports.traverse = ({push}) => ({
@@ -35,14 +35,14 @@ module.exports.traverse = ({push}) => ({
3535

3636
if (nextPath.isVariableDeclaration())
3737
return push({
38-
path: nextPath,
39-
keywordPath: path,
38+
path,
39+
nextPath,
4040
});
4141

4242
if (nextPath.isExpressionStatement() && nextPath.get('expression').isAssignmentExpression())
4343
return push({
44-
path: nextPath,
45-
keywordPath: path,
44+
path,
45+
nextPath,
4646
});
4747
},
4848
});

0 commit comments

Comments
 (0)