Skip to content

Commit

Permalink
fix(findExports): export with trailing comma (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
westhide authored Jul 20, 2022
1 parent b5d0a3f commit 51c81b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function findExports (code: string): ESMExport[] {
// Find named exports
const namedExports = matchAll(EXPORT_NAMED_RE, code, { type: 'named' })
for (const namedExport of namedExports) {
namedExport.names = namedExport.exports.split(/\s*,\s*/g).map(name => name.replace(/^.*?\sas\s/, '').trim())
namedExport.names = namedExport.exports.split(/\s*,\s*/g).map(name => name.replace(/^.*?\sas\s/, '').trim()).filter(name => !!name)
}

// Find export default
Expand Down
1 change: 1 addition & 0 deletions test/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('findExports', () => {
'export { useB, _useC as useC }': { names: ['useB', 'useC'], type: 'named' },
'export default foo': { type: 'default', name: 'default', names: ['default'] },
'export { default } from "./other"': { type: 'default', name: 'default', names: ['default'], specifier: './other' },
'export { default , } from "./other"': { type: 'default', name: 'default', names: ['default'], specifier: './other' },
'export async function foo ()': { type: 'declaration', names: ['foo'] },
'export const $foo = () => {}': { type: 'declaration', names: ['$foo'] },
'export { foo as default }': { type: 'default', name: 'default', names: ['default'] },
Expand Down

0 comments on commit 51c81b8

Please sign in to comment.