Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactivity Transform should respect const keyword #6992

Closed
sxzz opened this issue Oct 30, 2022 · 10 comments · Fixed by #6993
Closed

Reactivity Transform should respect const keyword #6992

sxzz opened this issue Oct 30, 2022 · 10 comments · Fixed by #6993
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. scope: reactivityTransform

Comments

@sxzz
Copy link
Member

sxzz commented Oct 30, 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.

@sxzz sxzz added 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. scope: reactivityTransform labels Oct 30, 2022
@louiss0
Copy link

louiss0 commented Oct 31, 2022

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

@shendiid
Copy link

shendiid commented Oct 31, 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.

@sxzz
Copy link
Member Author

sxzz commented Oct 31, 2022

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

@shendiid
Copy link

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

@bbcvc
Copy link

bbcvc commented Nov 1, 2022

This may be a break change. @sxzz

@bbcvc
Copy link

bbcvc commented Nov 1, 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"
`

@sxzz
Copy link
Member Author

sxzz commented Nov 1, 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.

@bbcvc
Copy link

bbcvc commented Nov 1, 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

@sxzz
Copy link
Member Author

sxzz commented Nov 1, 2022

As RFC mentioned

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

@bbcvc
Copy link

bbcvc commented Nov 1, 2022

Answered my doubts. 🫡

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. scope: reactivityTransform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants