From 9d84656f121acd59c606b7cee21811eab5dea3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Tue, 28 Mar 2023 12:02:34 +0800 Subject: [PATCH] refactor: reuse script ast for rewriting default (#136) --- packages/plugin-vue/src/main.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 708fa7de..724a5a66 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -321,11 +321,16 @@ async function genScriptCode( ? (['typescript'] as const) : (['typescript', 'decorators-legacy'] as const) : [] - scriptCode = options.compiler.rewriteDefault( - script.content, - '_sfc_main', - [...defaultPlugins, ...userPlugins], - ) + const as = '_sfc_main' + if (options.compiler.rewriteDefaultAST && script.scriptAst) { + options.compiler.rewriteDefaultAST(script.scriptAst, script.s, as) + } else { + scriptCode = options.compiler.rewriteDefault( + script.content, + '_sfc_main', + [...defaultPlugins, ...userPlugins], + ) + } map = script.map } else { if (script.src) {