diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index 890b384f83..cf3a1323f2 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -585,6 +585,13 @@ export default class Element extends Node { ]); this.handlers.forEach(handler => { + if (handler.modifiers.has('passive') && handler.modifiers.has('preventDefault')) { + component.error(handler, { + code: 'invalid-event-modifier', + message: `The 'passive' and 'preventDefault' modifiers cannot be used together` + }); + } + handler.modifiers.forEach(modifier => { if (!validModifiers.has(modifier)) { component.error(handler, { @@ -619,7 +626,7 @@ export default class Element extends Node { } }); - if (passiveEvents.has(handler.name) && !handler.usesEventObject) { + if (passiveEvents.has(handler.name) && !handler.usesEventObject && !handler.modifiers.has('preventDefault')) { // touch/wheel events should be passive by default handler.modifiers.add('passive'); } diff --git a/test/validator/samples/event-modifiers-invalid-passive/errors.json b/test/validator/samples/event-modifiers-invalid-passive/errors.json new file mode 100644 index 0000000000..90fce9eb44 --- /dev/null +++ b/test/validator/samples/event-modifiers-invalid-passive/errors.json @@ -0,0 +1,15 @@ +[{ + "message": "The 'passive' and 'preventDefault' modifiers cannot be used together", + "code": "invalid-event-modifier", + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 52, + "character": 52 + }, + "pos": 5 +}] diff --git a/test/validator/samples/event-modifiers-invalid-passive/input.html b/test/validator/samples/event-modifiers-invalid-passive/input.html new file mode 100644 index 0000000000..e51cd57ae7 --- /dev/null +++ b/test/validator/samples/event-modifiers-invalid-passive/input.html @@ -0,0 +1,3 @@ +