Skip to content

Commit c08ec49

Browse files
committed
feature(@putout/plugin-simplify-ternary) add support of duplicates
1 parent c88a040 commit c08ec49

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

packages/plugin-simplify-ternary/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ npm i @putout/plugin-simplify-ternary -D
2727

2828
```js
2929
module.exports = fs.copyFileSync ? fs.copyFileSync : copyFileSync;
30+
31+
const nodeTypes = Array.isArray(matcher.nodeType) ? matcher.nodeType : matcher.nodeType;
3032
```
3133

3234
## ✅ Correct code Example
3335

3436
```js
3537
module.exports = fs.copyFileSync || copyFileSync;
38+
39+
const nodeTypes = matcher.nodeType;
3640
```
3741

3842
## License

packages/plugin-simplify-ternary/lib/simplify-ternary.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module.exports.report = () => 'Unnecessary use of conditional expression for def
44

55
module.exports.replace = () => ({
66
'__a ? __a : __b': '__a || __b',
7+
'__a ? __b : __b ? __c : __d': '__b ? __c : __d',
78
});
89

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const nodeTypes = matcher.nodeType ? [matcher.nodeType] : ['Node']
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const nodeTypes = Array.isArray(matcher.nodeType)
2+
? matcher.nodeType
3+
: matcher.nodeType
4+
? [matcher.nodeType]
5+
: ['Node']

packages/plugin-simplify-ternary/test/simplify-ternary.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ test('plugin-simplify-ternary: transform', (t) => {
1919
t.end();
2020
});
2121

22+
test('plugin-simplify-ternary: transform: duplicate', (t) => {
23+
t.transform('duplicate');
24+
t.end();
25+
});
26+
2227
test('plugin-simplify-ternary: no: transform: different test and consequent', (t) => {
2328
t.noTransform('diff');
2429
t.end();

0 commit comments

Comments
 (0)