From 627259e0da16cc14f01f3e92fc3c30741806dbc4 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Mon, 7 Aug 2023 10:31:29 +0000 Subject: [PATCH] [IMP] web: update owl from 2.2.4 to 2.2.5 Release notes: https://github.com/odoo/owl/releases Commits: [FIX] compiler: fix xmlns attribute not being set correctly in firefox [FIX] compiler: fix t-call at root of template causing crashes [REF] compiler: minor cleanup [FIX] devtools: fix inspected path closes odoo/odoo#131082 X-original-commit: ad9db912c45ebd49d9df87fbaee1f8b49421b081 Signed-off-by: Jorge Pinna Puissant (jpp) Signed-off-by: Samuel Degueldre (sad) --- addons/web/static/lib/owl/owl.js | 86 +++++++++++++++----------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/addons/web/static/lib/owl/owl.js b/addons/web/static/lib/owl/owl.js index de17a3b2e50..23e67694fba 100644 --- a/addons/web/static/lib/owl/owl.js +++ b/addons/web/static/lib/owl/owl.js @@ -713,12 +713,7 @@ info.push({ type: "child", idx: index }); el = document.createTextNode(""); } - const attrs = node.attributes; - const ns = attrs.getNamedItem("block-ns"); - if (ns) { - attrs.removeNamedItem("block-ns"); - currentNS = ns.value; - } + currentNS || (currentNS = node.namespaceURI); if (!el) { el = currentNS ? document.createElementNS(currentNS, tagName) @@ -734,6 +729,7 @@ const fragment = document.createElement("template").content; fragment.appendChild(el); } + const attrs = node.attributes; for (let i = 0; i < attrs.length; i++) { const attrName = attrs[i].name; const attrValue = attrs[i].value; @@ -3857,7 +3853,7 @@ createBlock(parentBlock, type, ctx) { const hasRoot = this.target.hasRoot; const block = new BlockDescription(this.target, type); - if (!hasRoot && !ctx.preventRoot) { + if (!hasRoot) { this.target.hasRoot = true; block.isRoot = true; } @@ -3880,7 +3876,7 @@ if (ctx.tKeyExpr) { blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`; } - if (block.isRoot && !ctx.preventRoot) { + if (block.isRoot) { if (this.target.on) { blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on); } @@ -4056,11 +4052,6 @@ } // attributes const attrs = {}; - const nameSpace = ast.ns || ctx.nameSpace; - if (nameSpace && isNewBlock) { - // specific namespace uri - attrs["block-ns"] = nameSpace; - } for (let key in ast.attrs) { let expr, attrName; if (key.startsWith("t-attf")) { @@ -4176,7 +4167,10 @@ const idx = block.insertData(setRefStr, "ref"); attrs["block-ref"] = String(idx); } - const dom = xmlDoc.createElement(ast.tag); + const nameSpace = ast.ns || ctx.nameSpace; + const dom = nameSpace + ? xmlDoc.createElementNS(nameSpace, ast.tag) + : xmlDoc.createElement(ast.tag); for (const [attr, val] of Object.entries(attrs)) { if (!(attr === "class" && val === "")) { dom.setAttribute(attr, val); @@ -4218,7 +4212,7 @@ break; } } - this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx); + this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx); } } return block.varName; @@ -4321,7 +4315,7 @@ break; } } - this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx); + this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx); } // note: this part is duplicated from end of compilemulti: const args = block.children.map((c) => c.varName).join(", "); @@ -4436,7 +4430,6 @@ block, index, forceNewBlock: !isTSet, - preventRoot: ctx.preventRoot, isLast: ctx.isLast && i === l - 1, }); this.compileAST(child, subCtx); @@ -4445,21 +4438,19 @@ } } if (isNewBlock) { - if (block.hasDynamicChildren) { - if (block.children.length) { - const code = this.target.code; - const children = block.children.slice(); - let current = children.shift(); - for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`const ${current.varName} `)) { - code[i] = code[i].replace(`const ${current.varName}`, current.varName); - current = children.shift(); - if (!current) - break; - } + if (block.hasDynamicChildren && block.children.length) { + const code = this.target.code; + const children = block.children.slice(); + let current = children.shift(); + for (let i = codeIdx; i < code.length; i++) { + if (code[i].trimStart().startsWith(`const ${current.varName} `)) { + code[i] = code[i].replace(`const ${current.varName}`, current.varName); + current = children.shift(); + if (!current) + break; } - this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx); } + this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx); } const args = block.children.map((c) => c.varName).join(", "); this.insertBlock(`multi([${args}])`, block, ctx); @@ -4473,24 +4464,23 @@ ctxVar = generateId("ctx"); this.addLine(`let ${ctxVar} = ${compileExpr(ast.context)};`); } + const isDynamic = INTERP_REGEXP.test(ast.name); + const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`"; + if (block && !forceNewBlock) { + this.insertAnchor(block); + } + block = this.createBlock(block, "multi", ctx); if (ast.body) { this.addLine(`${ctxVar} = Object.create(${ctxVar});`); this.addLine(`${ctxVar}[isBoundary] = 1;`); this.helpers.add("isBoundary"); - const subCtx = createContext(ctx, { preventRoot: true, ctxVar }); + const subCtx = createContext(ctx, { ctxVar }); const bl = this.compileMulti({ type: 3 /* Multi */, content: ast.body }, subCtx); if (bl) { this.helpers.add("zero"); this.addLine(`${ctxVar}[zero] = ${bl};`); } } - const isDynamic = INTERP_REGEXP.test(ast.name); - const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`"; - if (block) { - if (!forceNewBlock) { - this.insertAnchor(block); - } - } const key = `key + \`${this.generateComponentKey()}\``; if (isDynamic) { const templateVar = generateId("template"); @@ -4498,7 +4488,6 @@ this.staticDefs.push({ id: "call", expr: `app.callTemplate.bind(app)` }); } this.define(templateVar, subTemplate); - block = this.createBlock(block, "multi", ctx); this.insertBlock(`call(this, ${templateVar}, ${ctxVar}, node, ${key})`, block, { ...ctx, forceNewBlock: !block, @@ -4507,7 +4496,6 @@ else { const id = generateId(`callTemplate_`); this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` }); - block = this.createBlock(block, "multi", ctx); this.insertBlock(`${id}.call(this, ${ctxVar}, node, ${key})`, block, { ...ctx, forceNewBlock: !block, @@ -4829,7 +4817,7 @@ } function _parse(xml) { normalizeXML(xml); - const ctx = { inPreTag: false, inSVG: false }; + const ctx = { inPreTag: false }; return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" }; } function parseNode(node, ctx) { @@ -4920,9 +4908,7 @@ if (tagName === "pre") { ctx.inPreTag = true; } - const shouldAddSVGNS = ROOT_SVG_TAGS.has(tagName) && !ctx.inSVG; - ctx.inSVG = ctx.inSVG || shouldAddSVGNS; - const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null; + let ns = !ctx.nameSpace && ROOT_SVG_TAGS.has(tagName) ? "http://www.w3.org/2000/svg" : null; const ref = node.getAttribute("t-ref"); node.removeAttribute("t-ref"); const nodeAttrsNames = node.getAttributeNames(); @@ -4984,6 +4970,9 @@ else if (attr.startsWith("block-")) { throw new OwlError(`Invalid attribute: '${attr}'`); } + else if (attr === "xmlns") { + ns = value; + } else if (attr !== "t-name") { if (attr.startsWith("t-") && !attr.startsWith("t-att")) { throw new OwlError(`Unknown QWeb directive: '${attr}'`); @@ -4996,6 +4985,9 @@ attrs[attr] = value; } } + if (ns) { + ctx.nameSpace = ns; + } const children = parseChildren(node, ctx); return { type: 2 /* DomNode */, @@ -5564,7 +5556,7 @@ } // do not modify manually. This file is generated by the release script. - const version = "2.2.4"; + const version = "2.2.5"; // ----------------------------------------------------------------------------- // Scheduler @@ -6033,8 +6025,8 @@ See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration Object.defineProperty(exports, '__esModule', { value: true }); - __info__.date = '2023-08-02T06:20:03.634Z'; - __info__.hash = '8f9ad98'; + __info__.date = '2023-08-07T10:26:30.557Z'; + __info__.hash = 'b25e988'; __info__.url = 'https://github.com/odoo/owl';