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

Commit 502b7ea

Browse files
authored
fix: support for type alias, close #62 (#66)
1 parent bef519a commit 502b7ea

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/core/macros.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ export function applyMacros(nodes: Statement[]) {
220220

221221
return t.objectExpression(
222222
Object.entries(props).map(([key, value]) => {
223-
if (value.type === 'null')
224-
return t.objectProperty(t.identifier(key), t.nullLiteral())
225-
226223
const prop = hasStaticDefaults
227224
? (propsRuntimeDefaults as ObjectExpression).properties.find((node: any) => node.key.name === key) as ObjectProperty
228225
: undefined

test/__snapshots__/transform.test.ts.snap

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ __sfc_main.props = {
369369
required: false,
370370
type: Array
371371
},
372-
any: null
372+
any: {
373+
key: \\"any\\",
374+
required: true,
375+
type: null
376+
}
373377
};
374378
375379
__sfc_main.setup = (__props, __ctx) => {
@@ -426,6 +430,28 @@ export default __sfc_main;
426430
"
427431
`;
428432
433+
exports[`transform fixtures test/fixtures/MacrosType4.vue 1`] = `
434+
"<script lang=\\"ts\\">
435+
type Test = number[];
436+
const __sfc_main = {};
437+
__sfc_main.props = {
438+
test: {
439+
key: \\"test\\",
440+
required: false,
441+
type: null,
442+
default: () => []
443+
}
444+
};
445+
446+
__sfc_main.setup = (__props, __ctx) => {
447+
return {};
448+
};
449+
450+
export default __sfc_main;
451+
</script>
452+
"
453+
`;
454+
429455
exports[`transform fixtures test/fixtures/MacrosTypeAny.vue 1`] = `
430456
"<template>
431457
<div>
@@ -436,7 +462,11 @@ exports[`transform fixtures test/fixtures/MacrosTypeAny.vue 1`] = `
436462
<script lang=\\"ts\\">
437463
const __sfc_main = {};
438464
__sfc_main.props = {
439-
value: null
465+
value: {
466+
key: \\"value\\",
467+
required: true,
468+
type: null
469+
}
440470
};
441471
442472
__sfc_main.setup = (__props, __ctx) => {

test/fixtures/MacrosType4.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup lang="ts">
2+
type Test = number[]
3+
withDefaults(
4+
defineProps<{ test: Test }>(),
5+
{ test: () => [] },
6+
)
7+
</script>

0 commit comments

Comments
 (0)