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 compiler 2.x incompatibility: multiple statements inside event handler has invalid generated code #572

Closed
decademoon opened this issue Jan 3, 2020 · 3 comments
Labels
🐞 bug Something isn't working

Comments

@decademoon
Copy link

Version

3.0.0-alpha.1

Reproduction link

(None)

Steps to reproduce

Attempt to compile this template:

<button @click="foo(); bar()">Click</button>

What is expected?

It should compile without any errors or warnings and when the button is clicked it should call the foo and bar functions sequentially.

What is actually happening?

The generated code is invalid.


The following template fragment works in 2.x:

<button @click="foo(); bar()">Click</button>

The click event handler gets compiled into something like this:

click: $event => { foo(); bar() }

But in 3.0.0-alpha.1 the compiled code is this:

click: _cache[0] || (_cache[0] = $event => (foo(); bar()))

which is invalid JS syntax.

It can be fixed on the user's end by:

  • Not having code like that in the template and if you need to execute multiple statements it should be extracted into a method.
  • Using a comma instead of a semicolon.
@decademoon
Copy link
Author

Also I want to mention that the issue helper website doesn't let you pick any version for vue-next which blocks creating any issues using the form.

underfin added a commit to underfin/vue-next that referenced this issue Jan 3, 2020
@ThaDaVos
Copy link

ThaDaVos commented Jan 3, 2020

@decademoon -> this link?
https://new-issue.vuejs.org/?repo=vuejs/vue-next
You'll have to fill in the version yourself as far as I can see

@decademoon
Copy link
Author

@ThaDaVos It's working now.

@yyx990803 yyx990803 added the 🐞 bug Something isn't working label Jan 6, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants