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

fix: support for type alias, close #62 #66

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/core/macros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ export function applyMacros(nodes: Statement[]) {

return t.objectExpression(
Object.entries(props).map(([key, value]) => {
if (value.type === 'null')
return t.objectProperty(t.identifier(key), t.nullLiteral())

const prop = hasStaticDefaults
? (propsRuntimeDefaults as ObjectExpression).properties.find((node: any) => node.key.name === key) as ObjectProperty
: undefined
Expand Down
34 changes: 32 additions & 2 deletions test/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ __sfc_main.props = {
required: false,
type: Array
},
any: null
any: {
key: \\"any\\",
required: true,
type: null
}
};

__sfc_main.setup = (__props, __ctx) => {
Expand Down Expand Up @@ -426,6 +430,28 @@ export default __sfc_main;
"
`;

exports[`transform fixtures test/fixtures/MacrosType4.vue 1`] = `
"<script lang=\\"ts\\">
type Test = number[];
const __sfc_main = {};
__sfc_main.props = {
test: {
key: \\"test\\",
required: false,
type: null,
default: () => []
}
};

__sfc_main.setup = (__props, __ctx) => {
return {};
};

export default __sfc_main;
</script>
"
`;

exports[`transform fixtures test/fixtures/MacrosTypeAny.vue 1`] = `
"<template>
<div>
Expand All @@ -436,7 +462,11 @@ exports[`transform fixtures test/fixtures/MacrosTypeAny.vue 1`] = `
<script lang=\\"ts\\">
const __sfc_main = {};
__sfc_main.props = {
value: null
value: {
key: \\"value\\",
required: true,
type: null
}
};

__sfc_main.setup = (__props, __ctx) => {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/MacrosType4.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
type Test = number[]
withDefaults(
defineProps<{ test: Test }>(),
{ test: () => [] },
)
</script>