Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit a35d895

Browse files
authored
fix: add support for withDefaults call without VariableDeclaration (#64)
1 parent 41b3d36 commit a35d895

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/core/macros.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function applyMacros(nodes: Statement[]) {
282282
}
283283
}
284284

285-
if (processDefineEmits(node) || processDefineProps(node) || processDefineExpose(node))
285+
if (processWithDefaults(node) || processDefineEmits(node) || processDefineProps(node) || processDefineExpose(node))
286286
return null
287287

288288
throwIfAwait(node)

test/__snapshots__/transform.test.ts.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,46 @@ export default __sfc_main;
386386
"
387387
`;
388388
389+
exports[`transform fixtures test/fixtures/MacrosType3.vue 1`] = `
390+
"<template>
391+
<div @click=\\"emit('update', msg)\\">
392+
{{ msg }}
393+
</div>
394+
</template>
395+
396+
<script lang=\\"ts\\">
397+
const __sfc_main = {};
398+
__sfc_main.props = {
399+
msg: {
400+
key: \\"msg\\",
401+
required: false,
402+
type: String,
403+
default: 'Hello'
404+
},
405+
value: {
406+
key: \\"value\\",
407+
required: true,
408+
type: [Number, String]
409+
},
410+
data: {
411+
key: \\"data\\",
412+
required: false,
413+
type: Object
414+
}
415+
};
416+
417+
__sfc_main.setup = (__props, __ctx) => {
418+
const emit = __ctx.emit;
419+
return {
420+
emit
421+
};
422+
};
423+
424+
export default __sfc_main;
425+
</script>
426+
"
427+
`;
428+
389429
exports[`transform fixtures test/fixtures/MacrosTypeAny.vue 1`] = `
390430
"<template>
391431
<div>

test/fixtures/MacrosType3.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div @click="emit('update', msg)">
3+
{{ msg }}
4+
</div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
withDefaults(
9+
defineProps<{ msg: string; value: number | string; data?: { value: boolean } }>(),
10+
{ msg: 'Hello' },
11+
)
12+
13+
const emit = defineEmits(['update'])
14+
</script>

0 commit comments

Comments
 (0)