diff --git a/src/blockdom/config.ts b/src/blockdom/config.ts index 9e918f70..96490e8c 100644 --- a/src/blockdom/config.ts +++ b/src/blockdom/config.ts @@ -1,4 +1,4 @@ -export function filterOutModifiersFromData(dataList: any[]): { modifiers: string[], data: any[]} { +export function filterOutModifiersFromData(dataList: any[]): { modifiers: string[]; data: any[] } { dataList = dataList.slice(); const modifiers = []; let elm; diff --git a/src/blockdom/events.ts b/src/blockdom/events.ts index a3eb5043..d2488bc0 100644 --- a/src/blockdom/events.ts +++ b/src/blockdom/events.ts @@ -76,6 +76,8 @@ function setupSyntheticEvent(evName: string, eventKey: string, capture: boolean if (CONFIGURED_SYNTHETIC_EVENTS[eventKey]) { return; } - document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), { capture }); + document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), { + capture, + }); CONFIGURED_SYNTHETIC_EVENTS[eventKey] = true; } diff --git a/src/component/handler.ts b/src/component/handler.ts index c6acf616..fd05320f 100644 --- a/src/component/handler.ts +++ b/src/component/handler.ts @@ -1,6 +1,6 @@ import { filterOutModifiersFromData } from "../blockdom/config"; -export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget|null) => { +export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => { const { data: _data, modifiers } = filterOutModifiersFromData(data); data = _data; let stopped = false; @@ -9,9 +9,20 @@ export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarg const isSelf = ev.target === currentTarget; for (const mod of modifiers) { switch (mod) { - case "self": selfMode = true; if (isSelf) { continue; } else { return stopped; }; - case "prevent": if ((selfMode && isSelf) || (!selfMode)) ev.preventDefault(); continue; - case "stop": if ((selfMode && isSelf) || (!selfMode)) ev.stopPropagation() ; stopped = true; continue; + case "self": + selfMode = true; + if (isSelf) { + continue; + } else { + return stopped; + } + case "prevent": + if ((selfMode && isSelf) || !selfMode) ev.preventDefault(); + continue; + case "stop": + if ((selfMode && isSelf) || !selfMode) ev.stopPropagation(); + stopped = true; + continue; } } } @@ -23,4 +34,4 @@ export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarg data[0].__owl__.component[method](...args, ev); } return stopped; -} +}; diff --git a/src/qweb/compiler.ts b/src/qweb/compiler.ts index 5c456b8c..d3aaa539 100644 --- a/src/qweb/compiler.ts +++ b/src/qweb/compiler.ts @@ -474,7 +474,10 @@ export class QWebCompiler { args = _args.slice(1, -1); return ""; }); - const modifiers = rawEvent.split(".").slice(1).map(m => `"${m}"`); + const modifiers = rawEvent + .split(".") + .slice(1) + .map((m) => `"${m}"`); let modifiersCode = ""; if (modifiers.length) { modifiersCode = `${modifiers.join(",")}, `; diff --git a/tests/blockdom/block_event_handling.test.ts b/tests/blockdom/block_event_handling.test.ts index d95a8d42..a791c7a8 100644 --- a/tests/blockdom/block_event_handling.test.ts +++ b/tests/blockdom/block_event_handling.test.ts @@ -124,9 +124,11 @@ test("two same block nodes with different handlers (synthetic)", async () => { }); test("synthetic and native handlers can cohabitate", async () => { - const block = createBlock('
'); + const block = createBlock( + '
' + ); let steps: string[] = []; - let handler1 = () => steps.push("1");; + let handler1 = () => steps.push("1"); let handler2 = () => steps.push("2"); const tree = block([handler1, handler2]); @@ -140,9 +142,11 @@ test("synthetic and native handlers can cohabitate", async () => { }); test("synthetic and native handlers can cohabitate (2)", async () => { - const block = createBlock('
'); + const block = createBlock( + '
' + ); let steps: string[] = []; - let handler1 = () => steps.push("1");; + let handler1 = () => steps.push("1"); let handler2 = () => steps.push("2"); const tree = block([handler1, handler2]); @@ -156,12 +160,12 @@ test("synthetic and native handlers can cohabitate (2)", async () => { }); test("synthetic and native handlers can cohabitate (3)", async () => { - const parent = createBlock(`
`) + const parent = createBlock(`
`); const block = createBlock('
'); const blockSynth = createBlock('
'); let steps: string[] = []; - const handler0 = () => steps.push("0");; - let handler1 = () => steps.push("1");; + const handler0 = () => steps.push("0"); + let handler1 = () => steps.push("1"); let handler2 = () => steps.push("2"); const tree = parent([handler0], [block([handler1]), blockSynth([handler2])]); @@ -177,12 +181,15 @@ test("synthetic and native handlers can cohabitate (3)", async () => { }); test("synthetic and native handlers can cohabitate (5)", async () => { - const parent = createBlock(`
`) + const parent = createBlock(`
`); const block = createBlock('
'); const blockSynth = createBlock('
'); let steps: string[] = []; - const handler0 = (ev: Event) => { steps.push("0"); ev.stopPropagation();}; - let handler1 = () => steps.push("1");; + const handler0 = (ev: Event) => { + steps.push("0"); + ev.stopPropagation(); + }; + let handler1 = () => steps.push("1"); let handler2 = () => steps.push("2"); const tree = parent([handler0], [block([handler1]), blockSynth([handler2])]); diff --git a/tests/qweb/event_handling.test.ts b/tests/qweb/event_handling.test.ts index 5546bb62..78f83ee5 100644 --- a/tests/qweb/event_handling.test.ts +++ b/tests/qweb/event_handling.test.ts @@ -327,7 +327,7 @@ describe("t-on", () => { expect(steps).toEqual(["btnClicked", "divClicked"]); }); - test("t-on with prevent and/or stop modifiers", async () => { + test("t-on with prevent and/or stop modifiers", async () => { expect.assertions(7); const template = `
diff --git a/tests/qweb/parser.test.ts b/tests/qweb/parser.test.ts index f7e437f4..0557b120 100644 --- a/tests/qweb/parser.test.ts +++ b/tests/qweb/parser.test.ts @@ -465,12 +465,15 @@ describe("qweb parser", () => { // --------------------------------------------------------------------------- test("simple t-foreach expression, t-key mandatory", async () => { - expect(() => parse(``)).toThrowErrorMatchingSnapshot(); - - }) + expect(() => + parse(``) + ).toThrowErrorMatchingSnapshot(); + }); test("simple t-foreach expression", async () => { - expect(parse(``)).toEqual({ + expect( + parse(``) + ).toEqual({ type: ASTType.TForEach, collection: "list", elem: "item", @@ -545,7 +548,9 @@ describe("qweb parser", () => { }); test("t-foreach expression on a span", async () => { - expect(parse(``)).toEqual({ + expect( + parse(``) + ).toEqual({ type: ASTType.TForEach, collection: "list", elem: "item", @@ -570,7 +575,9 @@ describe("qweb parser", () => { test("t-foreach expression on a span", async () => { expect( - parse(``) + parse( + `` + ) ).toEqual({ type: ASTType.TForEach, collection: "list", @@ -632,7 +639,9 @@ describe("qweb parser", () => { }); test("t-foreach in a div", async () => { - expect(parse(`
`)).toEqual({ + expect( + parse(`
`) + ).toEqual({ type: ASTType.DomNode, attrs: {}, on: {}, @@ -716,7 +725,9 @@ describe("qweb parser", () => { }); test("t-foreach expression with a t-call inside", async () => { - expect(parse(``)).toEqual({ + expect( + parse(``) + ).toEqual({ type: ASTType.TForEach, collection: "list", elem: "item", @@ -737,22 +748,24 @@ describe("qweb parser", () => { }); test("t-foreach expression with t-memo", async () => { - expect(parse(``)).toEqual( - { - type: ASTType.TForEach, - collection: "list", - elem: "item", - key: "item_index", - hasNoComponent: true, - isOnlyChild: false, - body: { type: ASTType.TEsc, expr: "item", defaultValue: "" }, - memo: "[row.x]", - hasNoFirst: true, - hasNoIndex: false, - hasNoLast: true, - hasNoValue: true, - } - ); + expect( + parse( + `` + ) + ).toEqual({ + type: ASTType.TForEach, + collection: "list", + elem: "item", + key: "item_index", + hasNoComponent: true, + isOnlyChild: false, + body: { type: ASTType.TEsc, expr: "item", defaultValue: "" }, + memo: "[row.x]", + hasNoFirst: true, + hasNoIndex: false, + hasNoLast: true, + hasNoValue: true, + }); }); // --------------------------------------------------------------------------- @@ -1161,7 +1174,9 @@ describe("qweb parser", () => { }, }); - expect(parse(`
word
`)).toEqual({ + expect( + parse(`
word
`) + ).toEqual({ body: { content: { attrs: {},