Skip to content

fix(compiler): skip if guard when condition is empty after modifiers #12321

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/compiler/codegen/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ function genHandler (handler: ASTElementHandler | Array<ASTElementHandler>): str
}
} else if (key === 'exact') {
const modifiers: ASTModifiers = (handler.modifiers: any)
genModifierCode += genGuard(
['ctrl', 'shift', 'alt', 'meta']
const condition = ['ctrl', 'shift', 'alt', 'meta']
.filter(keyModifier => !modifiers[keyModifier])
.map(keyModifier => `$event.${keyModifier}Key`)
.join('||')
)
if (condition) genModifierCode += genGuard(condition)
} else {
keys.push(key)
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ describe('codegen', () => {
)
})

// GitHub Issues #12319
it('generate events with ctrl shift alt meta exact modifiers are applied together', () => {
assertCodegen(
'<button @keydown.ctrl.shift.alt.meta.exact="onClick">Click</button>',
`with(this){return _c('button',{on:{"keydown":function($event){if(!$event.ctrlKey)return null;if(!$event.shiftKey)return null;if(!$event.altKey)return null;if(!$event.metaKey)return null;return onClick.apply(null, arguments)}}},[_v("Click")])}`
)
})

it('generate events with mouse event modifiers', () => {
assertCodegen(
'<input @click.ctrl="onClick">',
Expand Down