-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
experimental "ref sugar": local variables sharing a name with a top-level ref are overwritten #3445
Comments
reproduction missing, also don't use |
so, how reproduction vue setup with jsfiddle |
Read https://new-issue.vuejs.org/?repo=vuejs/vue-next#why-repro. There are links too |
<template>
<button @click="test">...</button>
</template>
<script setup>
ref: x = 1
function test() {
const x = { value: 2 }
console.log(x) //will show 1, should show 2
}
</script> that is all |
You are misunderstanding how
|
@LinusBorg you're using the "outside" const x = 1
function test() {
const x = 2
console.log(x) // 2
} but ref: x = 1
function test() {
const x = 2
console.log(x) // 1
} |
你应该没明白我的意思 简单说 |
Not exactly correct ref: x = 1
function test() {
const x = 2
console.log(x) // not show 1, will show undefiend, because the compiler will convert to console.log(x.value)
} What's worse ref: Variables_with_the_same_name_in_two_scopes = 1
function test() {
let Variables_with_the_same_name_in_two_scopes
console.log(Variables_with_the_same_name_in_two_scopes) // will ERROR, console.log(Variables_with_the_same_name_in_two_scopes.value) , Cannot read property 'value' of undefined
} |
@jacekkarczmarczyk Thanks. totally missed the point of the example. Looks like a bug in the compiler for that experimental syntax, indeed. @zhangenming Sorry for misunderstanding. |
@edison1105 ref: x
function f(){
let $x
console.log($x) // It compiles to x, which should be $x
} |
@zhangenming yes, see test case in the PR. |
Version
3.0.7
Reproduction link
https://codesandbox.io/s/eloquent-antonelli-xr3fb?file=/src/App.vue
Steps to reproduce
What is expected?
show 2
What is actually happening?
show 1
The text was updated successfully, but these errors were encountered: