foo: Foo
}>()
</script>`,
+ {
+ propsDestructure: false,
+ },
)
expect(content).toMatch(`const { foo } = __props`)
assertCode(content)
})
+ test('prohibiting reactive destructure', () => {
+ expect(() =>
+ compile(
+ `<script setup lang="ts">
+ const { foo } = defineProps<{
+ foo: Foo
+ }>()
+ </script>`,
+ {
+ propsDestructure: 'error',
+ },
+ ),
+ ).toThrow()
+ })
+
describe('errors', () => {
test('w/ both type and non-type args', () => {
expect(() => {
*/
hoistStatic?: boolean
/**
- * (**Experimental**) Enable reactive destructure for `defineProps`
- * @default false
+ * Set to `false` to disable reactive destructure for `defineProps` (pre-3.5
+ * behavior), or set to `'error'` to throw hard error on props destructures.
+ * @default true
*/
- propsDestructure?: boolean
+ propsDestructure?: boolean | 'error'
/**
* File system access methods to be used when resolving types
* imported in SFC macros. Defaults to ts.sys in Node.js, can be overwritten
import { isCallOf, resolveObjectKey } from './utils'
import type { ScriptCompileContext } from './context'
import { DEFINE_PROPS } from './defineProps'
-import { warnOnce } from '../warn'
export function processPropsDestructure(
ctx: ScriptCompileContext,
declId: ObjectPattern,
) {
- if (!ctx.options.propsDestructure) {
+ if (ctx.options.propsDestructure === 'error') {
+ ctx.error(`Props destructure is explicitly prohibited via config.`, declId)
+ } else if (ctx.options.propsDestructure === false) {
return
}
- warnOnce(
- `This project is using reactive props destructure, which is an experimental ` +
- `feature. It may receive breaking changes or be removed in the future, so ` +
- `use at your own risk.\n` +
- `To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/502.`,
- )
-
ctx.propsDestructureDecl = declId
const registerBinding = (
ctx: ScriptCompileContext,
vueImportAliases: Record<string, string>,
) {
- if (!ctx.options.propsDestructure) {
+ if (ctx.options.propsDestructure === false) {
return
}