]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): treat const reactive() bindings as mutable
authorEvan You <yyx990803@gmail.com>
Wed, 10 Feb 2021 16:38:19 +0000 (11:38 -0500)
committerEvan You <yyx990803@gmail.com>
Wed, 10 Feb 2021 16:39:07 +0000 (11:39 -0500)
packages/compiler-core/src/transforms/vFor.ts
packages/compiler-sfc/src/compileScript.ts

index 5cff0eaea46849d278f3c496b6081dae2dcd945c..e42cfc7797e391471574177b28d9fe768891fbf2 100644 (file)
@@ -79,7 +79,7 @@ export const transformFor = createStructuralDirectiveTransform(
 
       const isStableFragment =
         forNode.source.type === NodeTypes.SIMPLE_EXPRESSION &&
-        forNode.source.constType > ConstantTypes.CAN_SKIP_PATCH
+        forNode.source.constType > ConstantTypes.NOT_CONSTANT
       const fragmentFlag = isStableFragment
         ? PatchFlags.STABLE_FRAGMENT
         : keyProp
index d0a08a8a5c0eb2db64b93dc77e4a299fd3bc7469..7b2a869c758bc32a0b2f59d04540a9a9a76913b8 100644 (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) {