Skip to content

Commit b228abb

Browse files
author
ygj6
authoredJun 9, 2021
fix(compiler-sfc): rewriteDefault support multiline (#3917)
1 parent db1dc1c commit b228abb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
 

‎packages/compiler-sfc/__tests__/rewriteDefault.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,36 @@ describe('compiler sfc: rewriteDefault', () => {
3535
`)
3636
})
3737

38+
test('export named default multiline', () => {
39+
expect(
40+
rewriteDefault(`let App = {}\n export {\nApp as default\n}`, '_sfc_main')
41+
).toMatchInlineSnapshot(`
42+
"let App = {}
43+
export {
44+
45+
}
46+
const _sfc_main = App"
47+
`)
48+
})
49+
50+
test('export named default multiline /w comments', () => {
51+
expect(
52+
rewriteDefault(
53+
`const a = 1 \n export {\n a as b,\n a as default,\n a as c}\n` +
54+
`// export { myFunction as default }`,
55+
'script'
56+
)
57+
).toMatchInlineSnapshot(`
58+
"const a = 1
59+
export {
60+
a as b,
61+
62+
a as c}
63+
// export { myFunction as default }
64+
const script = a"
65+
`)
66+
})
67+
3868
test('export default class', async () => {
3969
expect(rewriteDefault(`export default class Foo {}`, 'script'))
4070
.toMatchInlineSnapshot(`

‎packages/compiler-sfc/src/rewriteDefault.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse, ParserPlugin } from '@babel/parser'
22
import MagicString from 'magic-string'
33

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

88
/**

0 commit comments

Comments
 (0)
Please sign in to comment.