mirror of https://github.com/sveltejs/svelte
commit
769e03296f
@ -0,0 +1,36 @@
|
|||||||
|
import EventHandler from '../compile/nodes/EventHandler';
|
||||||
|
import deindent from '../utils/deindent';
|
||||||
|
|
||||||
|
export default function getEventModifiers(handlerName: String) {
|
||||||
|
// Ignore first element because it's the event name, i.e. click
|
||||||
|
let modifiers = handlerName.split('|').slice(1);
|
||||||
|
|
||||||
|
let eventModifiers = modifiers.reduce((acc, m) => {
|
||||||
|
if (m === 'stopPropagation')
|
||||||
|
acc.bodyModifiers += 'event.stopPropagation();\n';
|
||||||
|
else if (m === 'preventDefault')
|
||||||
|
acc.bodyModifiers += 'event.preventDefault();\n';
|
||||||
|
else if (m === 'capture')
|
||||||
|
acc.optionModifiers[m] = true;
|
||||||
|
else if (m === 'once')
|
||||||
|
acc.optionModifiers[m] = true;
|
||||||
|
else if (m === 'passive')
|
||||||
|
acc.optionModifiers[m] = true;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {
|
||||||
|
bodyModifiers: '',
|
||||||
|
optionModifiers: {
|
||||||
|
capture: false,
|
||||||
|
once: false,
|
||||||
|
passive: false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (eventModifiers.bodyModifiers !== '')
|
||||||
|
eventModifiers.bodyModifiers = deindent`
|
||||||
|
${eventModifiers.bodyModifiers}
|
||||||
|
`;
|
||||||
|
|
||||||
|
return eventModifiers;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
[{
|
||||||
|
"message": "Valid event modifiers are stopPropagation, preventDefault, 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…
Reference in new issue