Reactivity Transform should respect `const` keyword
Vue version
3.2.41
Link to minimal reproduction
Steps to reproduce
Open the reproduction
What is expected?
Throw an error about const
keyword.
What is actually happening?
No errors.
System Info
No response
Any additional comments?
Relate issue #6989
WIP: I'll make a PR later.
I can't believe people didn't see this as a problem thank goodness. Programming mechanics are important.
const msg = $ref('Hello World!')
=== const msg ={ value : 'Hello World!' }
so...msg = '10' === msg.value = '10' // msg = { value : '10' }
is allowed
but... const msg = $ref( '10' )
is not allowed.
It's legal in transformed code, but illegal in the source code at the JavaScript syntax level.
I think there is no solution,unless use let
.😥
This may be a break change. @sxzz
If 👇 is not allowed then there will be a lot of compatibility issues for projects prior to version < 3.2.41.This can cause problems for many users. ` const msg = $ref('Hello World!')
// should emit an error here, since msg is a constant variable. msg = "10" `
@bbcvc It's not a valid syntax so the IDE or VSCode will emit an error. Example
Even if it's a breaking change, considering that Reactivity Transform is an experimental feature, I think this breaking change is reasonable.
@sxzz I think the developer should understand that this is a compiler macros. 👉RFC. If such a change is to be made, a broader discussion should be obtained in the community.Or modify rfc: https://github.com/vuejs/rfcs
As RFC mentioned
$() can only be used with let because it would be pointless to declare a constant ref.