From da5534ac33aec9b4cbeaeee3b23657f46f481eb4 Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Tue, 14 Mar 2023 14:16:31 +0100 Subject: [PATCH] fix: defineI18nRoute not working outside setup sugar syntax pages (#1929) --- src/pages.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages.ts b/src/pages.ts index 88d6160a9..a05c7f167 100644 --- a/src/pages.ts +++ b/src/pages.ts @@ -245,16 +245,19 @@ function readComponent(target: string) { try { const content = fs.readFileSync(target, 'utf8').toString() const { descriptor } = parseSFC(content) - if (!descriptor.scriptSetup) { + + if (!content.includes('defineI18nRoute')) { return options } + const desc = compileScript(descriptor, { id: target }) - const { scriptSetupAst } = desc + const { scriptSetupAst, scriptAst } = desc let extract = '' - if (scriptSetupAst) { + const genericSetupAst = scriptSetupAst || scriptAst + if (genericSetupAst) { const s = new MagicString(desc.loc.source) - scriptSetupAst.forEach(ast => { + genericSetupAst.forEach(ast => { // eslint-disable-next-line @typescript-eslint/no-explicit-any walk(ast as any, { enter(_node) {