diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index 63e7173022..2e2a0f8008 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -77,14 +77,14 @@ export default class Element extends Node { type: 'Element'; name: string; scope: any; // TODO - attributes: Attribute[]; - actions: Action[]; - bindings: Binding[]; - classes: Class[]; - handlers: EventHandler[]; - intro?: Transition; - outro?: Transition; - animation?: Animation; + attributes: Attribute[] = []; + actions: Action[] = []; + bindings: Binding[] = []; + classes: Class[] = []; + handlers: EventHandler[] = []; + intro?: Transition = null; + outro?: Transition = null; + animation?: Animation = null; children: Node[]; 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 (info.children.length > 0) { const valueAttribute = info.attributes.find(node => node.name === 'value'); diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 028e73e7ad..a3d909f402 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -388,13 +388,14 @@ function readAttribute(parser: Parser, uniqueNames: Set) { } if (type) { - const directive_name = name.slice(colon_index + 1); + const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); const directive = { start, end, type, name: directive_name, + modifiers, expression: (value[0] && value[0].expression) || null }; diff --git a/test/js/samples/event-modifiers/expected.js b/test/js/samples/event-modifiers/expected.js index 7897a5abf0..c38d2fea71 100644 --- a/test/js/samples/event-modifiers/expected.js +++ b/test/js/samples/event-modifiers/expected.js @@ -4,6 +4,12 @@ import { SvelteComponent as SvelteComponent_1, addListener, append, createElemen function create_fragment(component, ctx) { var div, button0, text1, button1, text3, button2, current; + function click_handler(event) { + event.stopPropagation(); + event.preventDefault(); + handleClick(event); + } + return { c() { div = createElement("div"); @@ -15,9 +21,9 @@ function create_fragment(component, ctx) { text3 = createText("\n\t"); button2 = createElement("button"); button2.textContent = "or me!"; - addListener(button0, "click|stopPropagation|preventDefault", handleClick); - addListener(button1, "click|once|capture", handleClick); - addListener(button2, "click|capture", handleClick); + addListener(button0, click_handler); + addListener(button1, "click", handleClick, { once: true, capture: true }); + addListener(button2, "click", handleClick, true); addListener(div, "touchstart", handleTouchstart, { passive: true }); }, @@ -45,9 +51,9 @@ function create_fragment(component, ctx) { detachNode(div); } - removeListener(button0, "click|stopPropagation|preventDefault", handleClick); - removeListener(button1, "click|once|capture", handleClick); - removeListener(button2, "click|capture", handleClick); + removeListener(button0, click_handler); + removeListener(button1, "click", handleClick, { once: true, capture: true }); + removeListener(button2, "click", handleClick, true); removeListener(div, "touchstart", handleTouchstart, { passive: true }); } }; diff --git a/test/parser/samples/action-with-call/output.json b/test/parser/samples/action-with-call/output.json index 91f961453c..521599544b 100644 --- a/test/parser/samples/action-with-call/output.json +++ b/test/parser/samples/action-with-call/output.json @@ -15,6 +15,7 @@ "end": 39, "type": "Action", "name": "tooltip", + "modifiers": [], "expression": { "type": "CallExpression", "start": 21, diff --git a/test/parser/samples/action-with-identifier/output.json b/test/parser/samples/action-with-identifier/output.json index dda412882a..800ab800be 100644 --- a/test/parser/samples/action-with-identifier/output.json +++ b/test/parser/samples/action-with-identifier/output.json @@ -15,6 +15,7 @@ "end": 28, "type": "Action", "name": "tooltip", + "modifiers": [], "expression": { "type": "Identifier", "start": 20, diff --git a/test/parser/samples/action-with-literal/output.json b/test/parser/samples/action-with-literal/output.json index 0a4d167898..0705cd9e39 100644 --- a/test/parser/samples/action-with-literal/output.json +++ b/test/parser/samples/action-with-literal/output.json @@ -15,6 +15,7 @@ "end": 36, "type": "Action", "name": "tooltip", + "modifiers": [], "expression": { "type": "Literal", "start": 21, diff --git a/test/parser/samples/action/output.json b/test/parser/samples/action/output.json index 5b4ca10aa4..68afd79d23 100644 --- a/test/parser/samples/action/output.json +++ b/test/parser/samples/action/output.json @@ -15,6 +15,7 @@ "end": 20, "type": "Action", "name": "autofocus", + "modifiers": [], "expression": null } ], diff --git a/test/parser/samples/animation/output.json b/test/parser/samples/animation/output.json index b9013d2eba..585ab3ff1c 100644 --- a/test/parser/samples/animation/output.json +++ b/test/parser/samples/animation/output.json @@ -26,6 +26,7 @@ "end": 50, "type": "Animation", "name": "flip", + "modifiers": [], "expression": null } ], diff --git a/test/parser/samples/binding-shorthand/output.json b/test/parser/samples/binding-shorthand/output.json index 97b531ae98..c80fc5f7f2 100644 --- a/test/parser/samples/binding-shorthand/output.json +++ b/test/parser/samples/binding-shorthand/output.json @@ -15,6 +15,7 @@ "end": 16, "type": "Binding", "name": "foo", + "modifiers": [], "expression": { "start": 13, "end": 16, diff --git a/test/parser/samples/binding/output.json b/test/parser/samples/binding/output.json index 8021378b05..031d291fa7 100644 --- a/test/parser/samples/binding/output.json +++ b/test/parser/samples/binding/output.json @@ -15,6 +15,7 @@ "end": 24, "type": "Binding", "name": "value", + "modifiers": [], "expression": { "type": "Identifier", "start": 19, diff --git a/test/parser/samples/css-ref-selector/output.json b/test/parser/samples/css-ref-selector/output.json index 25864b22bd..e7c6e984c5 100644 --- a/test/parser/samples/css-ref-selector/output.json +++ b/test/parser/samples/css-ref-selector/output.json @@ -15,6 +15,7 @@ "end": 12, "type": "Ref", "name": "foo", + "modifiers": [], "expression": null } ], diff --git a/test/parser/samples/event-handler/output.json b/test/parser/samples/event-handler/output.json index 326b5a642c..740e43e48d 100644 --- a/test/parser/samples/event-handler/output.json +++ b/test/parser/samples/event-handler/output.json @@ -15,6 +15,7 @@ "end": 45, "type": "EventHandler", "name": "click", + "modifiers": [], "expression": { "type": "ArrowFunctionExpression", "start": 19, diff --git a/test/parser/samples/refs/output.json b/test/parser/samples/refs/output.json index 128ca17529..f91ada05ca 100644 --- a/test/parser/samples/refs/output.json +++ b/test/parser/samples/refs/output.json @@ -15,6 +15,7 @@ "end": 15, "type": "Ref", "name": "foo", + "modifiers": [], "expression": null } ], diff --git a/test/parser/samples/transition-intro-no-params/output.json b/test/parser/samples/transition-intro-no-params/output.json index 58e25db776..d53b4d9d88 100644 --- a/test/parser/samples/transition-intro-no-params/output.json +++ b/test/parser/samples/transition-intro-no-params/output.json @@ -15,6 +15,7 @@ "end": 12, "type": "Transition", "name": "fade", + "modifiers": [], "expression": null, "intro": true, "outro": false diff --git a/test/parser/samples/transition-intro/output.json b/test/parser/samples/transition-intro/output.json index c811e132a3..6405d0bad5 100644 --- a/test/parser/samples/transition-intro/output.json +++ b/test/parser/samples/transition-intro/output.json @@ -15,6 +15,7 @@ "end": 30, "type": "Transition", "name": "style", + "modifiers": [], "expression": { "type": "ObjectExpression", "start": 16, diff --git a/test/validator/samples/event-modifiers-redundant/warnings.json b/test/validator/samples/event-modifiers-redundant/warnings.json index 7b6cae16d4..e3b9110427 100644 --- a/test/validator/samples/event-modifiers-redundant/warnings.json +++ b/test/validator/samples/event-modifiers-redundant/warnings.json @@ -3,30 +3,30 @@ "message": "The passive modifier only works with wheel and touch events", "code": "redundant-event-modifier", "start": { - "line": 1, + "line": 11, "column": 8, - "character": 8 + "character": 110 }, "end": { - "line": 1, + "line": 11, "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", "code": "redundant-event-modifier", "start": { - "line": 2, + "line": 12, "column": 5, - "character": 56 + "character": 158 }, "end": { - "line": 2, + "line": 12, "column": 47, - "character": 98 + "character": 200 }, - "pos": 56 + "pos": 158 } ]