Skip to content

Commit 4186953

Browse files
snags88gregberge
authored andcommitted
fix(babel-plugin): fix usage of spread attribute(#231)
1 parent 56241b3 commit 4186953

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

packages/babel-plugin-remove-jsx-attribute/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const removeJSXAttribute = (api, opts) => ({
44
if (!opts.elements.includes(path.node.name.name)) return
55

66
path.get('attributes').forEach(attribute => {
7-
if (opts.attributes.includes(attribute.node.name.name)) {
7+
const nodeName = attribute.node.name;
8+
if (nodeName && opts.attributes.includes(nodeName.name)) {
89
attribute.remove()
910
}
1011
})

packages/babel-plugin-remove-jsx-attribute/src/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ describe('plugin', () => {
1919
}),
2020
).toMatchInlineSnapshot(`"<div foo><span /></div>;"`)
2121
})
22+
23+
it('should not throw error when spread operator is used', () => {
24+
expect(
25+
testPlugin('<div foo><span foo {...props} /></div>', {
26+
elements: ['span'],
27+
attributes: ['foo'],
28+
}),
29+
).toMatchInlineSnapshot(`"<div foo><span {...props} /></div>;"`)
30+
})
2231
})

0 commit comments

Comments
 (0)