Skip to content

Commit 10a4299

Browse files
committed
feature: @putout/plugin-apply-destructuring: assign
1 parent c7e0ff2 commit 10a4299

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

packages/plugin-apply-destructuring/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ const [first] = array;
4747

4848
```js
4949
const name = user.name;
50+
hello = world.hello;
5051
```
5152

5253
## ✅ Example of correct code
5354

5455
```js
5556
const {name} = user;
57+
({hello} = world);
5658
```
5759

5860
## falsy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
({parent} = path);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
parent = path.parent;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
while (!(loc = path.node.loc)) {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
'use strict';
22

3+
const {types} = require('putout');
4+
const {isExpressionStatement} = types;
5+
36
module.exports.report = () => 'Use object destructuring';
47

8+
module.exports.match = () => ({
9+
'__a = __b.__a': (vars, {parentPath}) => isExpressionStatement(parentPath),
10+
});
11+
512
module.exports.replace = () => ({
613
'const __a = __b.__a': 'const {__a} = __b',
714
'let __a = __b.__a': 'let {__a} = __b',
15+
'__a = __b.__a': '({__a} = __b)',
816
});

packages/plugin-apply-destructuring/lib/apply-object-destructuring/index.spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ const applyObjectDestructuring = require('.');
55

66
const test = createTest(__dirname, {
77
plugins: [
8-
['apply-object-destructuring', applyObjectDestructuring],
8+
['apply-destructuring/object', applyObjectDestructuring],
99
],
1010
});
1111

12+
test('plugin-apply-destructuring: transform: assign', (t) => {
13+
t.transform('assign');
14+
t.end();
15+
});
16+
17+
test('plugin-apply-destructuring: no transform: while', (t) => {
18+
t.noTransform('while');
19+
t.end();
20+
});
21+
1222
test('plugin-apply-destructuring: no transform: member-expression', (t) => {
1323
t.noTransform('member-expression');
1424
t.end();

0 commit comments

Comments
 (0)