[REL] v2.2.5

# v2.2.5

 - [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
This commit is contained in:
Samuel Degueldre
2023-08-07 12:26:46 +02:00
parent b25e988628
commit 4b23f51974
4 changed files with 42 additions and 50 deletions
+30 -38
View File
@@ -710,12 +710,7 @@ function buildTree(node, parent = null, domParentTree = null) {
info.push({ type: "child", idx: index }); info.push({ type: "child", idx: index });
el = document.createTextNode(""); el = document.createTextNode("");
} }
const attrs = node.attributes; currentNS || (currentNS = node.namespaceURI);
const ns = attrs.getNamedItem("block-ns");
if (ns) {
attrs.removeNamedItem("block-ns");
currentNS = ns.value;
}
if (!el) { if (!el) {
el = currentNS el = currentNS
? document.createElementNS(currentNS, tagName) ? document.createElementNS(currentNS, tagName)
@@ -731,6 +726,7 @@ function buildTree(node, parent = null, domParentTree = null) {
const fragment = document.createElement("template").content; const fragment = document.createElement("template").content;
fragment.appendChild(el); fragment.appendChild(el);
} }
const attrs = node.attributes;
for (let i = 0; i < attrs.length; i++) { for (let i = 0; i < attrs.length; i++) {
const attrName = attrs[i].name; const attrName = attrs[i].name;
const attrValue = attrs[i].value; const attrValue = attrs[i].value;
@@ -3854,7 +3850,7 @@ class CodeGenerator {
createBlock(parentBlock, type, ctx) { createBlock(parentBlock, type, ctx) {
const hasRoot = this.target.hasRoot; const hasRoot = this.target.hasRoot;
const block = new BlockDescription(this.target, type); const block = new BlockDescription(this.target, type);
if (!hasRoot && !ctx.preventRoot) { if (!hasRoot) {
this.target.hasRoot = true; this.target.hasRoot = true;
block.isRoot = true; block.isRoot = true;
} }
@@ -3877,7 +3873,7 @@ class CodeGenerator {
if (ctx.tKeyExpr) { if (ctx.tKeyExpr) {
blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`; blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`;
} }
if (block.isRoot && !ctx.preventRoot) { if (block.isRoot) {
if (this.target.on) { if (this.target.on) {
blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on); blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on);
} }
@@ -4053,11 +4049,6 @@ class CodeGenerator {
} }
// attributes // attributes
const attrs = {}; const attrs = {};
const nameSpace = ast.ns || ctx.nameSpace;
if (nameSpace && isNewBlock) {
// specific namespace uri
attrs["block-ns"] = nameSpace;
}
for (let key in ast.attrs) { for (let key in ast.attrs) {
let expr, attrName; let expr, attrName;
if (key.startsWith("t-attf")) { if (key.startsWith("t-attf")) {
@@ -4173,7 +4164,10 @@ class CodeGenerator {
const idx = block.insertData(setRefStr, "ref"); const idx = block.insertData(setRefStr, "ref");
attrs["block-ref"] = String(idx); 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)) { for (const [attr, val] of Object.entries(attrs)) {
if (!(attr === "class" && val === "")) { if (!(attr === "class" && val === "")) {
dom.setAttribute(attr, val); dom.setAttribute(attr, val);
@@ -4215,7 +4209,7 @@ class CodeGenerator {
break; 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; return block.varName;
@@ -4318,7 +4312,7 @@ class CodeGenerator {
break; 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: // note: this part is duplicated from end of compilemulti:
const args = block.children.map((c) => c.varName).join(", "); const args = block.children.map((c) => c.varName).join(", ");
@@ -4433,7 +4427,6 @@ class CodeGenerator {
block, block,
index, index,
forceNewBlock: !isTSet, forceNewBlock: !isTSet,
preventRoot: ctx.preventRoot,
isLast: ctx.isLast && i === l - 1, isLast: ctx.isLast && i === l - 1,
}); });
this.compileAST(child, subCtx); this.compileAST(child, subCtx);
@@ -4442,8 +4435,7 @@ class CodeGenerator {
} }
} }
if (isNewBlock) { if (isNewBlock) {
if (block.hasDynamicChildren) { if (block.hasDynamicChildren && block.children.length) {
if (block.children.length) {
const code = this.target.code; const code = this.target.code;
const children = block.children.slice(); const children = block.children.slice();
let current = children.shift(); let current = children.shift();
@@ -4455,8 +4447,7 @@ class CodeGenerator {
break; 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(", "); const args = block.children.map((c) => c.varName).join(", ");
this.insertBlock(`multi([${args}])`, block, ctx); this.insertBlock(`multi([${args}])`, block, ctx);
@@ -4470,24 +4461,23 @@ class CodeGenerator {
ctxVar = generateId("ctx"); ctxVar = generateId("ctx");
this.addLine(`let ${ctxVar} = ${compileExpr(ast.context)};`); 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) { if (ast.body) {
this.addLine(`${ctxVar} = Object.create(${ctxVar});`); this.addLine(`${ctxVar} = Object.create(${ctxVar});`);
this.addLine(`${ctxVar}[isBoundary] = 1;`); this.addLine(`${ctxVar}[isBoundary] = 1;`);
this.helpers.add("isBoundary"); 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); const bl = this.compileMulti({ type: 3 /* Multi */, content: ast.body }, subCtx);
if (bl) { if (bl) {
this.helpers.add("zero"); this.helpers.add("zero");
this.addLine(`${ctxVar}[zero] = ${bl};`); 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()}\``; const key = `key + \`${this.generateComponentKey()}\``;
if (isDynamic) { if (isDynamic) {
const templateVar = generateId("template"); const templateVar = generateId("template");
@@ -4495,7 +4485,6 @@ class CodeGenerator {
this.staticDefs.push({ id: "call", expr: `app.callTemplate.bind(app)` }); this.staticDefs.push({ id: "call", expr: `app.callTemplate.bind(app)` });
} }
this.define(templateVar, subTemplate); this.define(templateVar, subTemplate);
block = this.createBlock(block, "multi", ctx);
this.insertBlock(`call(this, ${templateVar}, ${ctxVar}, node, ${key})`, block, { this.insertBlock(`call(this, ${templateVar}, ${ctxVar}, node, ${key})`, block, {
...ctx, ...ctx,
forceNewBlock: !block, forceNewBlock: !block,
@@ -4504,7 +4493,6 @@ class CodeGenerator {
else { else {
const id = generateId(`callTemplate_`); const id = generateId(`callTemplate_`);
this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` }); this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` });
block = this.createBlock(block, "multi", ctx);
this.insertBlock(`${id}.call(this, ${ctxVar}, node, ${key})`, block, { this.insertBlock(`${id}.call(this, ${ctxVar}, node, ${key})`, block, {
...ctx, ...ctx,
forceNewBlock: !block, forceNewBlock: !block,
@@ -4826,7 +4814,7 @@ function parse(xml) {
} }
function _parse(xml) { function _parse(xml) {
normalizeXML(xml); normalizeXML(xml);
const ctx = { inPreTag: false, inSVG: false }; const ctx = { inPreTag: false };
return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" }; return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" };
} }
function parseNode(node, ctx) { function parseNode(node, ctx) {
@@ -4917,9 +4905,7 @@ function parseDOMNode(node, ctx) {
if (tagName === "pre") { if (tagName === "pre") {
ctx.inPreTag = true; ctx.inPreTag = true;
} }
const shouldAddSVGNS = ROOT_SVG_TAGS.has(tagName) && !ctx.inSVG; let ns = !ctx.nameSpace && ROOT_SVG_TAGS.has(tagName) ? "http://www.w3.org/2000/svg" : null;
ctx.inSVG = ctx.inSVG || shouldAddSVGNS;
const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null;
const ref = node.getAttribute("t-ref"); const ref = node.getAttribute("t-ref");
node.removeAttribute("t-ref"); node.removeAttribute("t-ref");
const nodeAttrsNames = node.getAttributeNames(); const nodeAttrsNames = node.getAttributeNames();
@@ -4981,6 +4967,9 @@ function parseDOMNode(node, ctx) {
else if (attr.startsWith("block-")) { else if (attr.startsWith("block-")) {
throw new OwlError(`Invalid attribute: '${attr}'`); throw new OwlError(`Invalid attribute: '${attr}'`);
} }
else if (attr === "xmlns") {
ns = value;
}
else if (attr !== "t-name") { else if (attr !== "t-name") {
if (attr.startsWith("t-") && !attr.startsWith("t-att")) { if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
throw new OwlError(`Unknown QWeb directive: '${attr}'`); throw new OwlError(`Unknown QWeb directive: '${attr}'`);
@@ -4993,6 +4982,9 @@ function parseDOMNode(node, ctx) {
attrs[attr] = value; attrs[attr] = value;
} }
} }
if (ns) {
ctx.nameSpace = ns;
}
const children = parseChildren(node, ctx); const children = parseChildren(node, ctx);
return { return {
type: 2 /* DomNode */, type: 2 /* DomNode */,
@@ -5561,7 +5553,7 @@ function compile(template, options = {}) {
} }
// do not modify manually. This file is generated by the release script. // do not modify manually. This file is generated by the release script.
const version = "2.2.4"; const version = "2.2.5";
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Scheduler // Scheduler
@@ -5994,6 +5986,6 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(name, templat
export { App, Component, EventBus, OwlError, __info__, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml }; export { App, Component, EventBus, OwlError, __info__, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml };
__info__.date = '2023-08-02T06:20:03.634Z'; __info__.date = '2023-08-07T10:26:30.557Z';
__info__.hash = '8f9ad98'; __info__.hash = 'b25e988';
__info__.url = 'https://github.com/odoo/owl'; __info__.url = 'https://github.com/odoo/owl';
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@odoo/owl", "name": "@odoo/owl",
"version": "2.2.4", "version": "2.2.5",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@odoo/owl", "name": "@odoo/owl",
"version": "2.2.4", "version": "2.2.5",
"description": "Odoo Web Library (OWL)", "description": "Odoo Web Library (OWL)",
"main": "dist/owl.cjs.js", "main": "dist/owl.cjs.js",
"module": "dist/owl.es.js", "module": "dist/owl.es.js",
+1 -1
View File
@@ -1,2 +1,2 @@
// do not modify manually. This file is generated by the release script. // do not modify manually. This file is generated by the release script.
export const version = "2.2.4"; export const version = "2.2.5";