diff --git a/lib/__tests__/findExports-test.js b/lib/__tests__/findExports-test.js index cee27546..ccc71f06 100644 --- a/lib/__tests__/findExports-test.js +++ b/lib/__tests__/findExports-test.js @@ -61,6 +61,15 @@ it('finds es6 exports', () => { }); }); +it('does not blow up on object spreads', () => { + expect(findExports(` + const foo = { ...bar, baz: true }; + `)).toEqual({ + named: [], + hasDefault: false, + }); +}); + it('finds CommonJS exports', () => { expect(findExports(` const bar = function() {}; diff --git a/lib/findExports.js b/lib/findExports.js index cfbdad2d..f0564db2 100644 --- a/lib/findExports.js +++ b/lib/findExports.js @@ -116,8 +116,10 @@ function findDefinedNames(node, definedNames) { return; } if (init.type === 'ObjectExpression') { - definedNames[id.name] = // eslint-disable-line no-param-reassign - init.properties.map(({ key }) => key.name).filter(Boolean); + // eslint-disable-next-line no-param-reassign + definedNames[id.name] = init.properties + .map(({ key }) => key && key.name) + .filter(Boolean); } else if (init.type === 'FunctionExpression') { definedNames[id.name] = []; // eslint-disable-line no-param-reassign }