Skip to content

Commit

Permalink
fix(findExports): extract multi line named exports (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyang0826 committed Sep 19, 2022
1 parent 554f927 commit e22ead6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/analyze.ts
Expand Up @@ -102,7 +102,7 @@ export function findExports (code: string): ESMExport[] {
// Find named exports
const namedExports: NamedExport[] = 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.replace(/^\r?\n?/, '').split(/\s*,\s*/g).map(name => name.replace(/^.*?\sas\s/, '').trim())
}

// Find export default
Expand Down
11 changes: 11 additions & 0 deletions test/exports.test.ts
Expand Up @@ -119,6 +119,17 @@ describe('findExports', () => {
const matches = findExports(code)
expect(matches).to.have.lengthOf(2)
})

it('works with line feed named exports', () => {
const code = `
export {
_foo as foo,
bar,
};
`
const matches = findExports(code)
expect(matches[0].names).toEqual(['foo', 'bar'])
})
})

describe('fineExportNames', () => {
Expand Down

0 comments on commit e22ead6

Please sign in to comment.