partial fix for event modifier stuff

pull/1839/head
Rich Harris 7 years ago
parent c7d4372f26
commit f452de4a6b

@ -77,14 +77,14 @@ export default class Element extends Node {
type: 'Element'; type: 'Element';
name: string; name: string;
scope: any; // TODO scope: any; // TODO
attributes: Attribute[]; attributes: Attribute[] = [];
actions: Action[]; actions: Action[] = [];
bindings: Binding[]; bindings: Binding[] = [];
classes: Class[]; classes: Class[] = [];
handlers: EventHandler[]; handlers: EventHandler[] = [];
intro?: Transition; intro?: Transition = null;
outro?: Transition; outro?: Transition = null;
animation?: Animation; animation?: Animation = null;
children: Node[]; children: Node[];
ref: Ref; ref: Ref;
@ -107,16 +107,6 @@ export default class Element extends Node {
}); });
} }
this.attributes = [];
this.actions = [];
this.bindings = [];
this.classes = [];
this.handlers = [];
this.intro = null;
this.outro = null;
this.animation = null;
if (this.name === 'textarea') { if (this.name === 'textarea') {
if (info.children.length > 0) { if (info.children.length > 0) {
const valueAttribute = info.attributes.find(node => node.name === 'value'); const valueAttribute = info.attributes.find(node => node.name === 'value');

@ -388,13 +388,14 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
} }
if (type) { if (type) {
const directive_name = name.slice(colon_index + 1); const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
const directive = { const directive = {
start, start,
end, end,
type, type,
name: directive_name, name: directive_name,
modifiers,
expression: (value[0] && value[0].expression) || null expression: (value[0] && value[0].expression) || null
}; };

@ -4,6 +4,12 @@ import { SvelteComponent as SvelteComponent_1, addListener, append, createElemen
function create_fragment(component, ctx) { function create_fragment(component, ctx) {
var div, button0, text1, button1, text3, button2, current; var div, button0, text1, button1, text3, button2, current;
function click_handler(event) {
event.stopPropagation();
event.preventDefault();
handleClick(event);
}
return { return {
c() { c() {
div = createElement("div"); div = createElement("div");
@ -15,9 +21,9 @@ function create_fragment(component, ctx) {
text3 = createText("\n\t"); text3 = createText("\n\t");
button2 = createElement("button"); button2 = createElement("button");
button2.textContent = "or me!"; button2.textContent = "or me!";
addListener(button0, "click|stopPropagation|preventDefault", handleClick); addListener(button0, click_handler);
addListener(button1, "click|once|capture", handleClick); addListener(button1, "click", handleClick, { once: true, capture: true });
addListener(button2, "click|capture", handleClick); addListener(button2, "click", handleClick, true);
addListener(div, "touchstart", handleTouchstart, { passive: true }); addListener(div, "touchstart", handleTouchstart, { passive: true });
}, },
@ -45,9 +51,9 @@ function create_fragment(component, ctx) {
detachNode(div); detachNode(div);
} }
removeListener(button0, "click|stopPropagation|preventDefault", handleClick); removeListener(button0, click_handler);
removeListener(button1, "click|once|capture", handleClick); removeListener(button1, "click", handleClick, { once: true, capture: true });
removeListener(button2, "click|capture", handleClick); removeListener(button2, "click", handleClick, true);
removeListener(div, "touchstart", handleTouchstart, { passive: true }); removeListener(div, "touchstart", handleTouchstart, { passive: true });
} }
}; };

@ -15,6 +15,7 @@
"end": 39, "end": 39,
"type": "Action", "type": "Action",
"name": "tooltip", "name": "tooltip",
"modifiers": [],
"expression": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 21, "start": 21,

@ -15,6 +15,7 @@
"end": 28, "end": 28,
"type": "Action", "type": "Action",
"name": "tooltip", "name": "tooltip",
"modifiers": [],
"expression": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 20, "start": 20,

@ -15,6 +15,7 @@
"end": 36, "end": 36,
"type": "Action", "type": "Action",
"name": "tooltip", "name": "tooltip",
"modifiers": [],
"expression": { "expression": {
"type": "Literal", "type": "Literal",
"start": 21, "start": 21,

@ -15,6 +15,7 @@
"end": 20, "end": 20,
"type": "Action", "type": "Action",
"name": "autofocus", "name": "autofocus",
"modifiers": [],
"expression": null "expression": null
} }
], ],

@ -26,6 +26,7 @@
"end": 50, "end": 50,
"type": "Animation", "type": "Animation",
"name": "flip", "name": "flip",
"modifiers": [],
"expression": null "expression": null
} }
], ],

@ -15,6 +15,7 @@
"end": 16, "end": 16,
"type": "Binding", "type": "Binding",
"name": "foo", "name": "foo",
"modifiers": [],
"expression": { "expression": {
"start": 13, "start": 13,
"end": 16, "end": 16,

@ -15,6 +15,7 @@
"end": 24, "end": 24,
"type": "Binding", "type": "Binding",
"name": "value", "name": "value",
"modifiers": [],
"expression": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 19, "start": 19,

@ -15,6 +15,7 @@
"end": 12, "end": 12,
"type": "Ref", "type": "Ref",
"name": "foo", "name": "foo",
"modifiers": [],
"expression": null "expression": null
} }
], ],

@ -15,6 +15,7 @@
"end": 45, "end": 45,
"type": "EventHandler", "type": "EventHandler",
"name": "click", "name": "click",
"modifiers": [],
"expression": { "expression": {
"type": "ArrowFunctionExpression", "type": "ArrowFunctionExpression",
"start": 19, "start": 19,

@ -15,6 +15,7 @@
"end": 15, "end": 15,
"type": "Ref", "type": "Ref",
"name": "foo", "name": "foo",
"modifiers": [],
"expression": null "expression": null
} }
], ],

@ -15,6 +15,7 @@
"end": 12, "end": 12,
"type": "Transition", "type": "Transition",
"name": "fade", "name": "fade",
"modifiers": [],
"expression": null, "expression": null,
"intro": true, "intro": true,
"outro": false "outro": false

@ -15,6 +15,7 @@
"end": 30, "end": 30,
"type": "Transition", "type": "Transition",
"name": "style", "name": "style",
"modifiers": [],
"expression": { "expression": {
"type": "ObjectExpression", "type": "ObjectExpression",
"start": 16, "start": 16,

@ -3,30 +3,30 @@
"message": "The passive modifier only works with wheel and touch events", "message": "The passive modifier only works with wheel and touch events",
"code": "redundant-event-modifier", "code": "redundant-event-modifier",
"start": { "start": {
"line": 1, "line": 11,
"column": 8, "column": 8,
"character": 8 "character": 110
}, },
"end": { "end": {
"line": 1, "line": 11,
"column": 40, "column": 40,
"character": 40 "character": 142
}, },
"pos": 8 "pos": 110
}, },
{ {
"message": "Touch event handlers that don't use the 'event' object are passive by default", "message": "Touch event handlers that don't use the 'event' object are passive by default",
"code": "redundant-event-modifier", "code": "redundant-event-modifier",
"start": { "start": {
"line": 2, "line": 12,
"column": 5, "column": 5,
"character": 56 "character": 158
}, },
"end": { "end": {
"line": 2, "line": 12,
"column": 47, "column": 47,
"character": 98 "character": 200
}, },
"pos": 56 "pos": 158
} }
] ]

Loading…
Cancel
Save