Skip to content

Commit

Permalink
fix(api): keep string type when boolean exist
Browse files Browse the repository at this point in the history
closes #351
  • Loading branch information
sxzz committed May 1, 2023
1 parent ea44488 commit 791b2f3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/young-owls-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@vue-macros/better-define': patch
'@vue-macros/api': patch
---

keep string type when boolean exist
6 changes: 5 additions & 1 deletion packages/api/src/vue/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export function attachNodeLoc(node: Node, newNode: Node) {

export function toRuntimeTypeString(types: string[], isProduction?: boolean) {
if (isProduction) {
types = types.filter((t) => t === 'Boolean' || t === 'Function')
const hasBoolean = types.includes('Boolean')
types = types.filter(
(t) =>
t === 'Boolean' || (hasBoolean && t === 'String') || t === 'Function'
)
}
if (types.length === 0) return undefined
return types.length > 1 ? `[${types.join(', ')}]` : types[0]
Expand Down
42 changes: 42 additions & 0 deletions packages/better-define/tests/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,48 @@ export { issue328 as default };
"
`;

exports[`fixtures > tests/fixtures/issue-351.vue > isProduction = false 1`] = `
"import { defineComponent } from 'vue';
import _export_sfc from '/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
__name: \\"issue-351\\",
props: {
\\"modelValue\\": { type: [String, Boolean], required: true }
},
setup(__props) {
return () => {
};
}
});
var issue351 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { issue351 as default };
"
`;

exports[`fixtures > tests/fixtures/issue-351.vue > isProduction = true 1`] = `
"import { defineComponent } from 'vue';
import _export_sfc from '/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
__name: \\"issue-351\\",
props: {
\\"modelValue\\": { type: [String, Boolean] }
},
setup(__props) {
return () => {
};
}
});
var issue351 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
export { issue351 as default };
"
`;

exports[`fixtures > tests/fixtures/optional-method.vue > isProduction = false 1`] = `
"import { defineComponent } from 'vue';
import _export_sfc from '/plugin-vue/export-helper';
Expand Down
5 changes: 5 additions & 0 deletions packages/better-define/tests/fixtures/issue-351.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script setup lang="ts">
defineProps<{
modelValue: string | boolean
}>()
</script>

0 comments on commit 791b2f3

Please sign in to comment.