Skip to content

Commit

Permalink
fix: macros without variables
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 22, 2021
1 parent df12acc commit 569fca5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/macros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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[]

Expand Down
20 changes: 20 additions & 0 deletions test/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ export default __sfc_main;
"
`;

exports[`transform fixture MacrosPure.vue 1`] = `
"<template>
<div>{{ msg }}</div>
</template>
<script >
const __sfc_main = {};
__sfc_main.props = {
msg: String
};
__sfc_main.setup = (__props, __ctx) => {
return {};
};
export default __sfc_main;
</script>
"
`;

exports[`transform fixture MacrosType.vue 1`] = `
"<template>
<div @click=\\"emit(props.msg)\\">{{ msg }}</div>
Expand Down

0 comments on commit 569fca5

Please sign in to comment.