Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): allow export default substring #7041

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/compiler-sfc/__tests__/rewriteDefault.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ describe('compiler sfc: rewriteDefault', () => {
).toMatchInlineSnapshot(`"const script = {}"`)
})

test('rewrite variable value default', () => {
expect(rewriteDefault(`export const foo = 'default'`, 'script'))
.toMatchInlineSnapshot(`
"export const foo = 'default'
const script = {}"
`)
})

test('rewrite export named default', () => {
expect(
rewriteDefault(
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/s
const namedDefaultExportRE = /((?:^|\n|;)\s*)export([^'"]+)(?:as)?(\s*)default/s
const exportDefaultClassRE =
/((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/

Expand Down