Skip to content

Commit 77e470f

Browse files
committed
fix: resolve review comments
1 parent c960b78 commit 77e470f

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,43 +165,55 @@ describe('compiler sfc: rewriteDefault', () => {
165165
'script'
166166
)
167167
).toMatchInlineSnapshot(`
168-
"import { foo } from './index.js'
169-
export { bar } from './index.js'
170-
const script = foo"
171-
`)
168+
"import { foo as __VUE_DEFAULT__ } from './index.js'
169+
export { bar } from './index.js'
170+
const script = __VUE_DEFAULT__"
171+
`)
172172

173173
expect(
174174
compileRewriteDefault(
175175
`export { foo as default , bar } from './index.js'`,
176176
'script'
177177
)
178178
).toMatchInlineSnapshot(`
179-
"import { foo } from './index.js'
180-
export { bar } from './index.js'
181-
const script = foo"
182-
`)
179+
"import { foo as __VUE_DEFAULT__ } from './index.js'
180+
export { bar } from './index.js'
181+
const script = __VUE_DEFAULT__"
182+
`)
183183

184184
expect(
185185
compileRewriteDefault(
186186
`export { bar, foo as default } from './index.js'`,
187187
'script'
188188
)
189189
).toMatchInlineSnapshot(`
190-
"import { foo } from './index.js'
191-
export { bar, } from './index.js'
192-
const script = foo"
193-
`)
190+
"import { foo as __VUE_DEFAULT__ } from './index.js'
191+
export { bar, } from './index.js'
192+
const script = __VUE_DEFAULT__"
193+
`)
194194

195195
expect(
196196
compileRewriteDefault(
197197
`export { foo as default } from './index.js' \n const foo = 1`,
198198
'script'
199199
)
200200
).toMatchInlineSnapshot(`
201-
"import { foo } from './index.js'
201+
"import { foo as __VUE_DEFAULT__ } from './index.js'
202202
export { } from './index.js'
203203
const foo = 1
204-
const script = foo"
204+
const script = __VUE_DEFAULT__"
205+
`)
206+
207+
expect(
208+
compileRewriteDefault(
209+
`const a = 1 \nexport { a as default } from 'xxx'`,
210+
'script'
211+
)
212+
).toMatchInlineSnapshot(`
213+
"import { a as __VUE_DEFAULT__ } from 'xxx'
214+
const a = 1
215+
export { } from 'xxx'
216+
const script = __VUE_DEFAULT__"
205217
`)
206218
})
207219

packages/compiler-sfc/src/rewriteDefault.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export function rewriteDefault(
2525
} else {
2626
s.overwrite(node.start!, node.declaration.start!, `const ${as} = `)
2727
}
28-
}
29-
if (node.type === 'ExportNamedDeclaration') {
28+
} else if (node.type === 'ExportNamedDeclaration') {
3029
for (const specifier of node.specifiers) {
3130
if (
3231
specifier.type === 'ExportSpecifier' &&
@@ -39,7 +38,7 @@ export function rewriteDefault(
3938
s.prepend(
4039
`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`
4140
)
42-
s.overwrite(specifier.start!, end, ``)
41+
s.remove(specifier.start!, end)
4342
s.append(`\nconst ${as} = __VUE_DEFAULT__`)
4443
continue
4544
} else {
@@ -48,10 +47,10 @@ export function rewriteDefault(
4847
`import { ${input.slice(
4948
specifier.local.start!,
5049
specifier.local.end!
51-
)} } from '${node.source.value}'\n`
50+
)} as __VUE_DEFAULT__ } from '${node.source.value}'\n`
5251
)
53-
s.overwrite(specifier.start!, end, ``)
54-
s.append(`\nconst ${as} = ${specifier.local.name}`)
52+
s.remove(specifier.start!, end)
53+
s.append(`\nconst ${as} = __VUE_DEFAULT__`)
5554
continue
5655
}
5756
}

0 commit comments

Comments
 (0)