Skip to content

Commit 208422a

Browse files
committed
feature: @putout/operate: traverseProperties: ObjectPattern: exclude RestElement
1 parent 6df4c3c commit 208422a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/operate/lib/properties/traverse-properties.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const collect = ({name, collector}) => (path) => {
5050
if (propertyPath.isSpreadElement())
5151
continue;
5252

53+
if (propertyPath.isRestElement())
54+
continue;
55+
5356
const keyPath = propertyPath.get('key');
5457

5558
if (keyPath.isConditionalExpression())

packages/operate/lib/properties/traverse-properties.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ test('operate: traverse-properties: traverse', (t) => {
3535
t.end();
3636
});
3737

38+
test('operate: traverse-properties: traverse: ObjectPattern', (t) => {
39+
const source = 'const a = ({b, ...c}) => {}';
40+
let propertyPath;
41+
42+
traverse(parse(source), {
43+
ObjectPattern(path) {
44+
[propertyPath] = traverseProperties(path, 'b', {
45+
firstLevel: true,
46+
});
47+
},
48+
});
49+
50+
t.equal(propertyPath.node.key.name, 'b');
51+
t.end();
52+
});
53+
3854
test('operate: traverse-properties: traverse: ObjectExpression: path', (t) => {
3955
const source = '({"a": "b"})';
4056
let propertyPath;

0 commit comments

Comments
 (0)