Skip to content

Commit

Permalink
feat: support name to no script's component
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanzmj committed Nov 3, 2022
1 parent 39ecd69 commit 14a0e30
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/resolvers/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,26 @@ async function resolveVueRoutes(ctx: PageContext, customBlockMap: Map<string, Cu
async function transform(ctx: PageContext, code: string, id: string) {
if (!/\.vue$/.test(id))
return
const name = ctx.pageRouteMap.get(id)?.routeBase?.name
if (!name)
return
const { descriptor } = parse(code)
if (!descriptor.scriptSetup)
if (descriptor.script)
return
const result = compileScript(descriptor, { id })
if (result.scriptAst?.some(i => i.type === 'ExportDefaultDeclaration'))
const name = ctx.pageRouteMap.get(id)?.routeBase?.name
if (!name)
return

const lang = descriptor.scriptSetup && compileScript(descriptor, { id }).attrs.lang
const s = new MagicString(code)
const lang = result.attrs.lang
s.appendLeft(
0,
`<script ${lang ? `lang="${lang}"` : ''}>
`<script${lang ? ` lang="${lang}"` : ''}>
import { defineComponent } from 'vue'
export default /*#__PURE__*/ defineComponent({
name: '${name}',
${name ? ` name: '${name}'` : ''}
})
</script>\n`,
)
return {
map: s.generateMap({
source: id,
includeContent: true,
hires: true,
}),
code: s.toString(),
map: s.generateMap({ source: id, includeContent: true, hires: true }),
}
}

Expand Down

0 comments on commit 14a0e30

Please sign in to comment.