Skip to content

Commit

Permalink
fix(compiler-sfc): rewriteDefault support multiline (#3917)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 authored Jun 9, 2021
1 parent db1dc1c commit b228abb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/compiler-sfc/__tests__/rewriteDefault.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ describe('compiler sfc: rewriteDefault', () => {
`)
})

test('export named default multiline', () => {
expect(
rewriteDefault(`let App = {}\n export {\nApp as default\n}`, '_sfc_main')
).toMatchInlineSnapshot(`
"let App = {}
export {
}
const _sfc_main = App"
`)
})

test('export named default multiline /w comments', () => {
expect(
rewriteDefault(
`const a = 1 \n export {\n a as b,\n a as default,\n a as c}\n` +
`// export { myFunction as default }`,
'script'
)
).toMatchInlineSnapshot(`
"const a = 1
export {
a as b,
a as c}
// export { myFunction as default }
const script = a"
`)
})

test('export default class', async () => {
expect(rewriteDefault(`export default class Foo {}`, 'script'))
.toMatchInlineSnapshot(`
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/rewriteDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parse, ParserPlugin } from '@babel/parser'
import MagicString from 'magic-string'

const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/

/**
Expand Down

0 comments on commit b228abb

Please sign in to comment.