|
|
@@ -1121,6 +1121,36 @@ const emit = defineEmits(['a', 'b'])
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ // #7111
|
|
|
+ test('withDefaults (static) w/ production mode', () => {
|
|
|
+ const { content } = compile(
|
|
|
+ `
|
|
|
+ <script setup lang="ts">
|
|
|
+ const props = withDefaults(defineProps<{
|
|
|
+ foo: () => void
|
|
|
+ bar: boolean
|
|
|
+ baz: boolean | (() => void)
|
|
|
+ qux: string | number
|
|
|
+ }>(), {
|
|
|
+ baz: true,
|
|
|
+ qux: 'hi'
|
|
|
+ })
|
|
|
+ </script>
|
|
|
+ `,
|
|
|
+ { isProd: true }
|
|
|
+ )
|
|
|
+ assertCode(content)
|
|
|
+ expect(content).toMatch(`const props = __props`)
|
|
|
+
|
|
|
+ // foo has no default value, the Function can be dropped
|
|
|
+ expect(content).toMatch(`foo: null`)
|
|
|
+ expect(content).toMatch(`bar: { type: Boolean }`)
|
|
|
+ expect(content).toMatch(
|
|
|
+ `baz: { type: [Boolean, Function], default: true }`
|
|
|
+ )
|
|
|
+ expect(content).toMatch(`qux: { default: 'hi' }`)
|
|
|
+ })
|
|
|
+
|
|
|
test('withDefaults (dynamic)', () => {
|
|
|
const { content } = compile(`
|
|
|
<script setup lang="ts">
|