Skip to content

Commit

Permalink
fix: avoid invalid modules with definePage query
Browse files Browse the repository at this point in the history
Fix #338
  • Loading branch information
posva committed Mar 14, 2024
1 parent 69ea4f8 commit 25bbec3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions playground/src/pages/index.vue
@@ -1,3 +1,11 @@
<script lang="ts" setup>
definePage({
meta: {
title: 'hello',
},
})
</script>

<template>
<main>
<h1>Home</h1>
Expand Down
10 changes: 6 additions & 4 deletions src/core/definePage.ts
Expand Up @@ -31,16 +31,18 @@ export function definePageTransform({
code: string
id: string
}): Thenable<TransformResult> {
if (!code.includes(MACRO_DEFINE_PAGE)) return
// are we extracting only the definePage object
const isExtractingDefinePage = MACRO_DEFINE_PAGE_QUERY.test(id)

if (!code.includes(MACRO_DEFINE_PAGE)) {
return isExtractingDefinePage ? 'export default {}' : undefined
}

// TODO: handle also non SFC

const sfc = parseSFC(code, id)
if (!sfc.scriptSetup) return

// are we extracting only the definePage object
const isExtractingDefinePage = MACRO_DEFINE_PAGE_QUERY.test(id)

const { script, scriptSetup, getSetupAst } = sfc
const setupAst = getSetupAst()

Expand Down

0 comments on commit 25bbec3

Please sign in to comment.