diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index e05c587805..fad73bce93 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -613,6 +613,15 @@ export default class Element extends Node { }); } } + + if (component.options.legacy && (modifier === 'once' || modifier === 'passive')) { + // TODO this could be supported, but it would need a few changes to + // how event listeners work + component.error(handler, { + code: 'invalid-event-modifier', + message: `The '${modifier}' modifier cannot be used in legacy mode` + }); + } }); }); } diff --git a/test/validator/index.js b/test/validator/index.js index 852ac4191b..0f5ad18a6e 100644 --- a/test/validator/index.js +++ b/test/validator/index.js @@ -32,6 +32,7 @@ describe("validate", () => { warnings.push({ code, message, pos, start, end }); }, dev: config.dev, + legacy: config.legacy, generate: false }); diff --git a/test/validator/samples/event-modifiers-invalid/errors.json b/test/validator/samples/event-modifiers-invalid/errors.json index 858711708c..0de4e9aacf 100644 --- a/test/validator/samples/event-modifiers-invalid/errors.json +++ b/test/validator/samples/event-modifiers-invalid/errors.json @@ -1,15 +1,15 @@ [{ - "message": "Valid event modifiers are preventDefault, stopPropagation, capture, once or passive", - "code": "invalid-event-modifier", - "start": { - "line": 1, - "column": 8, - "character": 8 - }, - "end": { - "line": 1, - "column": 36, - "character": 36 - }, - "pos": 8 -}] \ No newline at end of file + "message": "Valid event modifiers are preventDefault, stopPropagation, capture, once or passive", + "code": "invalid-event-modifier", + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 36, + "character": 36 + }, + "pos": 8 +}] diff --git a/test/validator/samples/event-modifiers-legacy/_config.js b/test/validator/samples/event-modifiers-legacy/_config.js new file mode 100644 index 0000000000..0179e05ec4 --- /dev/null +++ b/test/validator/samples/event-modifiers-legacy/_config.js @@ -0,0 +1,3 @@ +export default { + legacy: true +}; \ No newline at end of file diff --git a/test/validator/samples/event-modifiers-legacy/errors.json b/test/validator/samples/event-modifiers-legacy/errors.json new file mode 100644 index 0000000000..2e340b7b2f --- /dev/null +++ b/test/validator/samples/event-modifiers-legacy/errors.json @@ -0,0 +1,15 @@ +[{ + "message": "The 'once' modifier cannot be used in legacy mode", + "code": "invalid-event-modifier", + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 37, + "character": 37 + }, + "pos": 8 +}] diff --git a/test/validator/samples/event-modifiers-legacy/input.html b/test/validator/samples/event-modifiers-legacy/input.html new file mode 100644 index 0000000000..3ef8edeee9 --- /dev/null +++ b/test/validator/samples/event-modifiers-legacy/input.html @@ -0,0 +1 @@ + \ No newline at end of file