]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): rewriteDefault support multiline (#3917)
authorygj6 <82787816@qq.com>
Wed, 9 Jun 2021 19:07:48 +0000 (03:07 +0800)
committerGitHub <noreply@github.com>
Wed, 9 Jun 2021 19:07:48 +0000 (15:07 -0400)
packages/compiler-sfc/__tests__/rewriteDefault.spec.ts
packages/compiler-sfc/src/rewriteDefault.ts

index a6b45e128ad4f722faf5dd85a9b89feeddd854b5..d44eeca0210dfce81b64e2dc689bf436927f48c6 100644 (file)
@@ -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(`
index 417c70c3aab4cd185f8c2ae7ca290c3b5ec99e7f..44a7d41ad44d5b79f7459b49ee9f6cf540861b80 100644 (file)
@@ -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$]+)/
 
 /**