exports[`sfc reactive props destructure > default values w/ type declaration & key is string 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
+import { toDisplayString as _toDisplayString } from "vue"
+
export default /*@__PURE__*/_defineComponent({
props: {
-return () => {}
+return (_ctx: any,_cache: any) => {
+ return _toDisplayString(__props.foo)
+}
}
})"
"onUpdate:modelValue": (val: number) => void // double-quoted string containing symbols
}>()
</script>
+ <template>{{ foo }}</template>
`)
expect(bindings).toStrictEqual({
__propsAliases: {
"foo:bar": { type: String, required: true, default: 'foo-bar' },
"onUpdate:modelValue": { type: Function, required: true }
},`)
+ expect(content).toMatch(`__props.foo`)
assertCode(content)
})
)
}
ctx.propsTypeDecl = node.typeParameters.params[0]
+ // register bindings
+ const { props } = resolveTypeElements(ctx, ctx.propsTypeDecl)
+ if (props) {
+ for (const key in props) {
+ if (!(key in ctx.bindingMetadata)) {
+ ctx.bindingMetadata[key] = BindingTypes.PROPS
+ }
+ }
+ }
}
// handle props destructure
for (const prop of props) {
propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults))
- // register bindings
- if ('bindingMetadata' in ctx && !(prop.key in ctx.bindingMetadata)) {
- ctx.bindingMetadata[prop.key] = BindingTypes.PROPS
- }
}
let propsDecls = `{
-import { isGloballyAllowed } from '@vue/shared'
+import { genPropsAccessExp, isGloballyAllowed } from '@vue/shared'
import {
BindingTypes,
NewlineType,
? `${helper('isRef')}(${raw}) ? (${raw}.value = ${assignment}) : null`
: unref()
break
+ case BindingTypes.PROPS:
+ raw = genPropsAccessExp(raw)
+ break
+ case BindingTypes.PROPS_ALIASED:
+ raw = genPropsAccessExp(bindingMetadata.__propsAliases![raw])
+ break
default:
raw = withAssignment(raw)
}