Adds invalid test for event-modifiers.

pull/1641/head
Admin 6 years ago
parent 26360d4ced
commit adfc0e3e45

@ -6,6 +6,8 @@ import { Node } from '../../interfaces';
const validBuiltins = new Set(['set', 'fire', 'destroy']);
const validModifiers = new Set(['stop', 'prevent', 'capture', 'once', 'passive']);
export default function validateEventHandlerCallee(
validator: Validator,
attribute: Node,
@ -22,6 +24,17 @@ export default function validateEventHandlerCallee(
});
}
const modifiers = attribute.name.split('|').slice(1);
if (
modifiers.length > 0 &&
modifiers.filter(m => !validModifiers.has(m)).length > 0
) {
validator.error(attribute, {
code: 'invalid-event-modifiers',
message: `Valid event modifiers are ${[...validModifiers].join(', ')}.`
});
}
const { name } = flattenReference(callee);
if (validCalleeObjects.has(name) || name === 'options') return;

@ -0,0 +1,15 @@
[{
"message": "Valid event modifiers are stop, prevent, capture, once, passive.",
"code": "invalid-event-modifiers",
"start": {
"line": 1,
"column": 8,
"character": 8
},
"end": {
"line": 1,
"column": 36,
"character": 36
},
"pos": 8
}]

@ -0,0 +1 @@
<button on:click|stop|bad="doThat()"></button>
Loading…
Cancel
Save