fix(compiler-sfc): treat const reactive() bindings as mutable

This commit is contained in:
Evan You
2021-02-10 11:38:19 -05:00
parent cf67306032
commit 03360cefa1
2 changed files with 7 additions and 4 deletions

View File

@@ -1036,12 +1036,15 @@ function walkDeclaration(
)
if (id.type === 'Identifier') {
let bindingType
if (
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
} 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!, userImportAlias['reactive'] || 'reactive'))
(isConst && canNeverBeRef(init!, userReactiveBinding))
) {
bindingType = BindingTypes.SETUP_CONST
} else if (isConst) {