Skip to content

Commit

Permalink
Merge pull request #374 from Galooshi/bug-373
Browse files Browse the repository at this point in the history
Prevent findExports from blowing up on object spread syntax
  • Loading branch information
lencioni authored Feb 16, 2017
2 parents b4640ce + 9f55363 commit 0d76ccf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/__tests__/findExports-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};
Expand Down
6 changes: 4 additions & 2 deletions lib/findExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0d76ccf

Please sign in to comment.