test(runtime-dom): add test coverage for v-on runtime guards, fix "exact" guard (#298)
This commit is contained in:
@@ -90,4 +90,17 @@ describe('compiler-dom: transform v-on', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should not wrap keys guard if no key modifier is present', () => {
|
||||
const [prop] = parseVOnProperties(`<div @keyup.exact="test"/>`, {
|
||||
prefixIdentifiers: true
|
||||
})
|
||||
expect(prop).toMatchObject({
|
||||
type: NodeTypes.JS_PROPERTY,
|
||||
value: {
|
||||
callee: V_ON_MODIFIERS_GUARD,
|
||||
arguments: [{ content: '_ctx.test' }, '["exact"]']
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -41,15 +41,17 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
||||
value,
|
||||
JSON.stringify(runtimeModifiers.filter(m => m in NOT_KEY_MODIFIERS))
|
||||
])
|
||||
const keyModifiers = runtimeModifiers.filter(m => !(m in NOT_KEY_MODIFIERS))
|
||||
if (
|
||||
keyModifiers.length &&
|
||||
// if event name is dynamic, always wrap with keys guard
|
||||
key.type === NodeTypes.COMPOUND_EXPRESSION ||
|
||||
!key.isStatic ||
|
||||
key.content.toLowerCase() in KEYBOARD_EVENTS
|
||||
(key.type === NodeTypes.COMPOUND_EXPRESSION ||
|
||||
!key.isStatic ||
|
||||
key.content.toLowerCase() in KEYBOARD_EVENTS)
|
||||
) {
|
||||
handler = createCallExpression(context.helper(V_ON_KEYS_GUARD), [
|
||||
handler,
|
||||
JSON.stringify(runtimeModifiers.filter(m => !(m in NOT_KEY_MODIFIERS)))
|
||||
JSON.stringify(keyModifiers)
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user