* template expressions.
*/
SETUP_CONST = 'setup-const',
+ /**
+ * a const binding that does not need `unref()`, but may be mutated.
+ */
+ SETUP_REACTIVE_CONST = 'setup-reactive-const',
/**
* a const binding that may be a ref.
*/
const isDestructureAssignment =
parent && isInDestructureAssignment(parent, parentStack)
- if (type === BindingTypes.SETUP_CONST || localVars[raw]) {
+ if (
+ type === BindingTypes.SETUP_CONST ||
+ type === BindingTypes.SETUP_REACTIVE_CONST ||
+ localVars[raw]
+ ) {
return raw
} else if (type === BindingTypes.SETUP_REF) {
return `${raw}.value`
expect(bindings).toStrictEqual({
foo: BindingTypes.PROPS,
bar: BindingTypes.SETUP_CONST,
- props: BindingTypes.SETUP_CONST
+ props: BindingTypes.SETUP_REACTIVE_CONST
})
// should remove defineOptions import and call
// props aliases
if (propsDestructureDecl) {
if (propsDestructureRestId) {
- bindingMetadata[propsDestructureRestId] = BindingTypes.SETUP_CONST
+ bindingMetadata[propsDestructureRestId] =
+ BindingTypes.SETUP_REACTIVE_CONST
}
for (const key in propsDestructuredBindings) {
const { local } = propsDestructuredBindings[key]
const userReactiveBinding = userImportAlias['reactive'] || 'reactive'
if (isCallOf(init, userReactiveBinding)) {
// treat reactive() calls as let since it's meant to be mutable
- bindingType = BindingTypes.SETUP_LET
+ bindingType = isConst
+ ? BindingTypes.SETUP_REACTIVE_CONST
+ : BindingTypes.SETUP_LET
} else if (
// if a declaration is a const literal, we can mark it so that
// the generated render fn code doesn't need to unref() it
isDefineCall ||
(isConst && canNeverBeRef(init!, userReactiveBinding))
) {
- bindingType = BindingTypes.SETUP_CONST
+ bindingType = isCallOf(init, DEFINE_PROPS)
+ ? BindingTypes.SETUP_REACTIVE_CONST
+ : BindingTypes.SETUP_CONST
} else if (isConst) {
if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
bindingType = BindingTypes.SETUP_REF