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

template | local variable reference in a function is prefixed with _ctx #4514

Closed
lidlanca opened this issue Sep 3, 2021 · 0 comments · Fixed by #4520
Closed

template | local variable reference in a function is prefixed with _ctx #4514

lidlanca opened this issue Sep 3, 2021 · 0 comments · Fixed by #4520

Comments

@lidlanca
Copy link
Contributor

lidlanca commented Sep 3, 2021

Version

3.2.8

Reproduction link

sfc playground

Steps to reproduce

see bad case in repro link

What is expected?

locally defined variables in a function scope should not be prefixed with _ctx
when referenced inside the scope.

What is actually happening?

a reference to a local variable declared in the function scope is prefixed with _ctx


variables defined in the function scope should be treated the same like named arguments

for reference

code is compiled from

  bad <button @click="(msg)=>{
    let a = 'the type is ' + msg.type            
    output = a
    }">
  click
  </button>

to

 _createElementVNode("button", {
      onClick: _cache[1] || (_cache[1] = (msg)=>{
    let a = 'the type is ' + msg.type            
    _isRef(output) ? output.value = _ctx.a : output = a
    })
    }, " click "),

inconsistent prefix usage

_isRef(output) ? output.value = _ctx.a : output = a
there is currently some inconsistency for using a
the usage of a should probably be consistent for both branches of the condition

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants