-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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): return handler value for event modifiers instead of un… #7704
Conversation
How will it behave with the following example? https://codepen.io/anon/pen/ddwWKW The handler code is |
src/compiler/codegen/events.js
Outdated
} | ||
return `function($event){${code}${handlerCode}}` | ||
return `function($event){${code}return ${handlerCode}}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe handlerCode
should be wrap in a IIFE
Agree with @jacekkarczmarczyk.
And the same behavior with modifiers |
What about |
Maybe we should return only when the provided expression is a function: <button @click=" e => doSomething('a parameter', e)">Click me</button> |
@posva you're totally right. But there is a problem when we use modifiers. They wraps handler and we can't get result. For now i'm stuck at parsing handler to check is multiple expressions inside of it |
thanks for your pr
IMO parse expression with regex or other string operation is not a good chooice |
I didn't dig deep into the code so I'm not sure what exactly you mean by it, but maybe there's an easy way to implement something like |
we have not instanced the Maybe we can implement it in a limited way as @posva said |
…t is a statement or expression
@posva, @jacekkarczmarczyk, @Kingwl, Morning. I've re-implemented exactly as @posva proposed before. Now we expected that
|
src/compiler/codegen/events.js
Outdated
@@ -119,7 +119,7 @@ function genHandler ( | |||
code += genModifierCode | |||
} | |||
const handlerCode = isMethodPath | |||
? handler.value + '($event)' | |||
? `return ${handler.value}($event)` | |||
: isFunctionExpression | |||
? `(${handler.value})($event)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to return here as well and adapt other test cases
@posva checked this case:
|
@posva pushed change. Now ^ example returns
|
add some other test case for method path and function expression please |
@Kingwl there are 7 function expression tests was there. I've added more cases with methods and so on. |
src/compiler/codegen/events.js
Outdated
@@ -79,6 +79,9 @@ function genHandler ( | |||
const isMethodPath = simplePathRE.test(handler.value) | |||
const isFunctionExpression = fnExpRE.test(handler.value) | |||
|
|||
const handlersArr = handler.value.split(';') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split(';')
is not a good chooice
fix(compiler): return handler value for event modifiers instead of undefined
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Without modifiers compiler return original vm function, so we can expect to handle returned value (as example - handle it in directive)
With modifier it always return "undefined" because of missing return value
This PR add correct return value if modifier wrapper is used