From b3b95d4ee612c92ac53292c1594adf1c0d1f9c98 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 28 Oct 2018 13:58:43 -0400 Subject: [PATCH] disallow passive|preventDefault combo --- src/compile/nodes/Element.ts | 9 ++++++++- .../event-modifiers-invalid-passive/errors.json | 15 +++++++++++++++ .../event-modifiers-invalid-passive/input.html | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/validator/samples/event-modifiers-invalid-passive/errors.json create mode 100644 test/validator/samples/event-modifiers-invalid-passive/input.html 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 @@ +
+ oops +
\ No newline at end of file