Subscribe on changes!

Reactivity Transform should respect `const` keyword

avatar
Oct 30th 2022

Vue version

3.2.41

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9kE1qw0AMha+iDgW3EHuabXAC3fUG3cxmYivxhPlDGqcL47tXtkspLXSn9/T0IWlSrzk39xHVQbXckcsFGMuYTya6kBMVmIDwAjNcKAWoJFqZaGKXIhcIfIUjPErgqXpD7xO8J/L9Q/W8ZLQGHtLoe8DgCtgISJQIBiTcAbvY4UpwDBZWoI0F7pacPXtsTNzwRu1fjDKx1duCspqIgiF7W1AUQDvsT9O0wua51aJW18U8CrAOqUd/NEr6Rkmr1d/Taqe2O+tgc3PjFOUT0zJtvhps1AFWZ/Hk/kUbNZSS+aA1X7rlfzduEl21VA2NsbiADXKoz5Q+GEnARu1+MLSYd6SaMPbyDfqP+Sv6h7tgZxNnNX8CV7ifXg==

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.

avatar
Oct 31st 2022

I can't believe people didn't see this as a problem thank goodness. Programming mechanics are important.

avatar
Oct 31st 2022

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.

avatar
Oct 31st 2022

It's legal in transformed code, but illegal in the source code at the JavaScript syntax level.

avatar
Oct 31st 2022

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.😥

avatar
Nov 1st 2022

This may be a break change. @sxzz

avatar
Nov 1st 2022

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" `

avatar
Nov 1st 2022

@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.

avatar
Nov 1st 2022

@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

avatar
Nov 1st 2022

As RFC mentioned

$() can only be used with let because it would be pointless to declare a constant ref.

avatar
Nov 1st 2022

Answered my doubts. 🫡