From 569fca5d1ae82c29f31af0801cb8d2638adb0870 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 22 Aug 2021 21:13:13 +0800 Subject: [PATCH] fix: macros without variables --- src/core/macros.ts | 8 ++++++-- test/__snapshots__/transform.test.ts.snap | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/core/macros.ts b/src/core/macros.ts index f2e9b60..4c13003 100644 --- a/src/core/macros.ts +++ b/src/core/macros.ts @@ -241,7 +241,11 @@ export function applyMacros(nodes: Statement[]) { } nodes = nodes - .map((node) => { + .map((raw: Node) => { + let node = raw + if (raw.type === 'ExpressionStatement') + node = raw.expression + if (node.type === 'VariableDeclaration' && !node.declare) { const total = node.declarations.length for (let i = 0; i < total; i++) { @@ -258,7 +262,7 @@ export function applyMacros(nodes: Statement[]) { if (processDefineEmits(node) || processDefineProps(node) || processDefineExpose(node)) return null - return node + return raw }) .filter(Boolean) as Statement[] diff --git a/test/__snapshots__/transform.test.ts.snap b/test/__snapshots__/transform.test.ts.snap index 96a941b..1dbf419 100644 --- a/test/__snapshots__/transform.test.ts.snap +++ b/test/__snapshots__/transform.test.ts.snap @@ -47,6 +47,26 @@ export default __sfc_main; " `; +exports[`transform fixture MacrosPure.vue 1`] = ` +" + + +" +`; + exports[`transform fixture MacrosType.vue 1`] = ` "