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

fix(compiler-core): keep event handlers noninitial arguments #1265

Merged

Conversation

cathrinevaage
Copy link
Contributor

@cathrinevaage cathrinevaage commented May 30, 2020

When the compiler encounters a template such as this

<AComponent @an-event="anEventHandler" />

the function passed as the prop onAnEvent to <AComponent> is generated like this

$event => _ctx.anEventHandler($event)

This becomes a problem when the event is emitted with more than one argument. Only the first argument, $event, is passed to the event handler.
This is especially evident when wanting to use the transition enter/leave's resolve function.

<script>
export default {
  setup: () => ({
    onEnter (el, resolve) {
      ...
      resolve() // Uncaught TypeError: resolve is not a function
    }
  })
}
</script>

<template>
  <transition @enter="onEnter">
    <... v-if="..." />
  </transition>
</template>

This PR fixes this by replacing $event with ($event, ...args) in code generation for the vOn transform.
Resulting in functions like ($event, ...args) => _ctx.eventHandler($event, ...args).

Note

This is my first pr to vuejs, and I have limited experience in working with tests. Although the tests are passing, I'm not convinced everything is correct.
When working to resolve this issue, this line was never touched. I can also see that the coverage test doesn't touch it either. I haven't quite understood what it does, but I decided to change it anyway.

Additional note

e2e kept failing when running the tests. Sometimes they passed, other times the failed. I don't know if this is common, or if it's related to my setup somehow. I've managed to at some point get all tests to pass, while running them individually.

@yyx990803 yyx990803 merged commit 7e28173 into vuejs:master Jun 15, 2020
@cathrinevaage cathrinevaage deleted the fix/dropping-noninitial-event-arguments branch June 15, 2020 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants