Skip to content

Commit

Permalink
fix(reactivity-transform): don't wrap empty defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jul 15, 2023
1 parent 71660f0 commit 4df51da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-pumpkins-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-macros/reactivity-transform': patch
---

don't wrap empty defaults
26 changes: 15 additions & 11 deletions packages/reactivity-transform/src/core/sfc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,21 @@ const ${
{ offset }
)
} else if (defineDecl.arguments[0]) {
s.overwriteNode(
node,
`defineProps(${importHelperFn(
s,
offset,
'mergeDefaults'
)}(${s.sliceNode(defineDecl.arguments[0], {
offset,
})}, { ${defaultStr} }))`,
{ offset }
)
if (defaultStr) {
s.overwriteNode(
node,
`defineProps(${importHelperFn(
s,
offset,
'mergeDefaults'
)}(${s.sliceNode(defineDecl.arguments[0], {
offset,
})}, { ${defaultStr} }))`,
{ offset }
)
} else {
s.overwriteNode(node, s.sliceNode(defineDecl, { offset }), { offset })
}
} else
throw new SyntaxError(
`${DEFINE_PROPS}() must have at least one argument or type argument.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ export { scriptAndSetup as default };
`;

exports[`fixtures > tests/fixtures/vue3/alias.vue 1`] = `
"import { mergeDefaults, toRef, toDisplayString } from 'vue';
"import { toRef, toDisplayString } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
const _sfc_main = {
__name: 'alias',
props: mergeDefaults({
props: {
foo: String,
baz: Number,
}, { }),
},
setup(__props) {
const propAlias2 = toRef(__props, \\"baz\\");
const propAlias = toRef(__props, \\"foo\\");
Expand Down

0 comments on commit 4df51da

Please sign in to comment.