Skip to content

Commit

Permalink
fix: sfc parsing update
Browse files Browse the repository at this point in the history
Fix #116
  • Loading branch information
posva committed Jan 9, 2023
1 parent 23dc0b6 commit e75d678
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -90,7 +90,7 @@
"dependencies": {
"@babel/types": "^7.20.7",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "^0.13.5",
"@vue-macros/common": "^0.13.6",
"ast-walker-scope": "^0.3.1",
"chokidar": "^3.5.3",
"fast-glob": "^3.2.12",
Expand All @@ -111,7 +111,7 @@
}
},
"devDependencies": {
"@volar/vue-language-core": "^1.0.22",
"@volar/vue-language-core": "^1.0.24",
"c8": "^7.12.0",
"chalk": "^5.2.0",
"conventional-changelog-cli": "^2.2.2",
Expand Down
54 changes: 26 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions src/core/definePage.ts
Expand Up @@ -38,9 +38,9 @@ export function definePageTransform({
// are we extracting only the definePage object
const isExtractingDefinePage = MACRO_DEFINE_PAGE_QUERY.test(id)

const { script, scriptSetup, scriptCompiled } = sfc
const { script, scriptSetup, setupAst } = sfc

const definePageNodes = (scriptCompiled?.scriptSetupAst || ([] as Node[]))
const definePageNodes = (setupAst?.body || ([] as Node[]))
.map((node) => {
if (node.type === 'ExpressionStatement') node = node.expression
return isCallOf(node, MACRO_DEFINE_PAGE) ? node : null
Expand All @@ -67,9 +67,7 @@ export function definePageTransform({

const routeRecord = definePageNode.arguments[0]

const scriptBindings = sfc.scriptCompiled.scriptSetupAst
? getIdentifiers(sfc.scriptCompiled.scriptSetupAst as any)
: []
const scriptBindings = setupAst?.body ? getIdentifiers(setupAst.body) : []

checkInvalidScopeReference(routeRecord, MACRO_DEFINE_PAGE, scriptBindings)

Expand Down Expand Up @@ -112,9 +110,9 @@ export function extractDefinePageNameAndPath(

if (!sfc.scriptSetup) return

const { script, scriptSetup, scriptCompiled } = sfc
const { setupAst } = sfc

const definePageNodes = (scriptCompiled?.scriptSetupAst ?? ([] as Node[]))
const definePageNodes = (setupAst?.body ?? ([] as Node[]))
.map((node) => {
if (node.type === 'ExpressionStatement') node = node.expression
return isCallOf(node, MACRO_DEFINE_PAGE) ? node : null
Expand Down

0 comments on commit e75d678

Please sign in to comment.