Skip to content

Commit 57e196f

Browse files
committed
feature: @putout/plugin-extract-sequence-expressions: inside IfStatement (#236)
1 parent 93a2a0f commit 57e196f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

packages/plugin-extract-sequence-expressions/lib/extract-sequence-expressions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
compare,
1313
remove,
1414
insertBefore,
15+
replaceWith,
1516
} = operator;
1617

1718
export const report = () => 'Avoid sequence expressions';
@@ -51,7 +52,7 @@ export const fix = (path) => {
5152
insertBefore(path.parentPath, expressionStatement(path.node.expressions.shift()));
5253
}
5354

54-
remove(path);
55+
replaceWith(path, path.node.expressions[0]);
5556

5657
return;
5758
}

packages/plugin-extract-sequence-expressions/test/fixture/if-fix.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ for (const b of c) {
55
{
66
console.log('one');
77

8-
if () {
8+
if (a) {
99
console.log('three');
1010
}
1111
}
1212
}
13+
14+
a;
15+
b;
16+
17+
if (c)
18+
console.log('hello, world');

packages/plugin-extract-sequence-expressions/test/fixture/if.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ for (const b of c)
44
if (console.log('one'), console.log('two'), a) {
55
console.log('three')
66
}
7+
8+
if ((a, b, c))
9+
console.log("hello, world");

0 commit comments

Comments
 (0)