Skip to content

Commit 47a5ba0

Browse files
committed
feature: @putout/plugin-convert-assignment-to-declaration: exclude keywords
1 parent 7fd209c commit 47a5ba0

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

packages/plugin-convert-assignment-to-declaration/.putout.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/plugin-convert-assignment-to-declaration/lib/convert-assignment-to-declaration.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const {
77
VariableDeclaration,
88
} = types;
99

10-
const {replaceWith, getBinding} = operator;
10+
const {
11+
replaceWith,
12+
getBinding,
13+
isKeyword,
14+
} = operator;
1115

1216
module.exports.report = (path) => {
1317
const {name} = path.node.left;
@@ -25,6 +29,15 @@ module.exports.fix = (path) => {
2529

2630
module.exports.traverse = ({push}) => ({
2731
AssignmentExpression(path) {
32+
const prevPath = path.parentPath.getPrevSibling();
33+
34+
if (prevPath.isVariableDeclaration()) {
35+
const {name} = prevPath.node.declarations.at(-1).id;
36+
37+
if (isKeyword(name))
38+
return;
39+
}
40+
2841
const {left} = path.node;
2942

3043
if (!isIdentifier(left))

packages/plugin-convert-assignment-to-declaration/test/convert-assignment-to-declaration.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ test('putout: convert-assignment-to-declaration: no report: nested', (t) => {
1919
t.end();
2020
});
2121

22+
test('putout: convert-assignment-to-declaration: no report: keyword', (t) => {
23+
t.noReport('keyword');
24+
t.end();
25+
});
26+
2227
test('putout: convert-assignment-to-declaration: transform', (t) => {
2328
t.transform('convert-assignment-to-declaration');
2429
t.end();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const a = 3,
2+
const b = 4;

0 commit comments

Comments
 (0)