From 4186953511cee6b2e02b045edfad97545bfaf139 Mon Sep 17 00:00:00 2001 From: Seiji Naganuma Date: Tue, 13 Nov 2018 01:25:04 -0800 Subject: [PATCH] fix(babel-plugin): fix usage of spread attribute(#231) --- packages/babel-plugin-remove-jsx-attribute/src/index.js | 3 ++- .../babel-plugin-remove-jsx-attribute/src/index.test.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/babel-plugin-remove-jsx-attribute/src/index.js b/packages/babel-plugin-remove-jsx-attribute/src/index.js index c2c07330..95d783d7 100644 --- a/packages/babel-plugin-remove-jsx-attribute/src/index.js +++ b/packages/babel-plugin-remove-jsx-attribute/src/index.js @@ -4,7 +4,8 @@ const removeJSXAttribute = (api, opts) => ({ if (!opts.elements.includes(path.node.name.name)) return path.get('attributes').forEach(attribute => { - if (opts.attributes.includes(attribute.node.name.name)) { + const nodeName = attribute.node.name; + if (nodeName && opts.attributes.includes(nodeName.name)) { attribute.remove() } }) diff --git a/packages/babel-plugin-remove-jsx-attribute/src/index.test.js b/packages/babel-plugin-remove-jsx-attribute/src/index.test.js index f88e23f2..426a99cf 100644 --- a/packages/babel-plugin-remove-jsx-attribute/src/index.test.js +++ b/packages/babel-plugin-remove-jsx-attribute/src/index.test.js @@ -19,4 +19,13 @@ describe('plugin', () => { }), ).toMatchInlineSnapshot(`"
;"`) }) + + it('should not throw error when spread operator is used', () => { + expect( + testPlugin('
', { + elements: ['span'], + attributes: ['foo'], + }), + ).toMatchInlineSnapshot(`"
;"`) + }) })