-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler-sfc): treat const reactive() bindings as mutable
- Loading branch information
Showing
2 changed files
with
7 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
03360ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803 Just noting there's a missed optimization opportunity by only checking
if (isCallOf(init, userImportAlias['ref'] || 'ref'))
It could include
shallowRef
andcomputed
as well.Also noting that those optimizations won't play nice with something like
auto-ref
.It will work but it won't be able to simplify access with
.value
instead ofunref()
.Although I'm gonna tweak the lib to enable
import { ref } from "vue-auto-ref"
), the called function might still beauto.ref
or an alias that won't be known here.(I also note that you're only checking names and don't worry about shadowing variables in nested scopes. I agree it's very unlikely but something tells me that with as many users as Vue has, weird things are bound to happen).
Even with 1. working, a plugin like
auto-ref
assigns tolet
as users will assign the variable as if it was a plain value. It is effectively a const, but that's special knowledge that compiler-sfc would need to have.So it looks like there might be a small optimization benefit to having "standardized" magic refs as opposed to independent loaders.
03360ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a PR to do something similar #2979 😅
It has a related issue that can be closed