[IMP] owl: update to a3317ab997

This commit is contained in:
Pierre Rousseau
2019-10-24 09:34:48 +02:00
parent d6e0a9dcba
commit 79a6891679
+41 -43
View File
@@ -407,7 +407,7 @@
this.shouldDefineResult = true; this.shouldDefineResult = true;
this.shouldProtectContext = false; this.shouldProtectContext = false;
this.shouldTrackScope = false; this.shouldTrackScope = false;
this.inLoop = false; this.loopNumber = 0;
this.inPreTag = false; this.inPreTag = false;
this.allowMultipleRoots = false; this.allowMultipleRoots = false;
this.hasParentWidget = false; this.hasParentWidget = false;
@@ -1288,6 +1288,7 @@
} }
var _utils = /*#__PURE__*/Object.freeze({ var _utils = /*#__PURE__*/Object.freeze({
__proto__: null,
whenReady: whenReady, whenReady: whenReady,
loadJS: loadJS, loadJS: loadJS,
loadFile: loadFile, loadFile: loadFile,
@@ -1628,6 +1629,7 @@
} }
const attributes = node.attributes; const attributes = node.attributes;
const validDirectives = []; const validDirectives = [];
const finalizers = [];
// maybe this is not optimal: we iterate on all attributes here, and again // maybe this is not optimal: we iterate on all attributes here, and again
// just after for each directive. // just after for each directive.
for (let i = 0; i < attributes.length; i++) { for (let i = 0; i < attributes.length; i++) {
@@ -1670,6 +1672,9 @@
} }
} }
for (let { directive, value, fullName } of validDirectives) { for (let { directive, value, fullName } of validDirectives) {
if (directive.finalize) {
finalizers.push({ directive, value, fullName });
}
if (directive.atNodeEncounter) { if (directive.atNodeEncounter) {
const isDone = directive.atNodeEncounter({ const isDone = directive.atNodeEncounter({
node, node,
@@ -1679,6 +1684,9 @@
value value
}); });
if (isDone) { if (isDone) {
for (let { directive, value, fullName } of finalizers) {
directive.finalize({ node, qweb: this, ctx, fullName, value });
}
return; return;
} }
} }
@@ -1731,10 +1739,8 @@
ctx.rootContext.shouldDefineUtils = true; ctx.rootContext.shouldDefineUtils = true;
ctx.addLine(`utils.addNameSpace(vn${ctx.parentNode});`); ctx.addLine(`utils.addNameSpace(vn${ctx.parentNode});`);
} }
for (let { directive, value, fullName } of validDirectives) { for (let { directive, value, fullName } of finalizers) {
if (directive.finalize) { directive.finalize({ node, qweb: this, ctx, fullName, value });
directive.finalize({ node, qweb: this, ctx, fullName, value });
}
} }
} }
_compileGenericNode(node, ctx, withHandlers = true) { _compileGenericNode(node, ctx, withHandlers = true) {
@@ -1797,7 +1803,7 @@
if (name.startsWith("t-att-")) { if (name.startsWith("t-att-")) {
let attName = name.slice(6); let attName = name.slice(6);
const v = ctx.getValue(value); const v = ctx.getValue(value);
let formattedValue = v.id || ctx.formatExpression(v); let formattedValue = typeof v === 'string' ? ctx.formatExpression(v) : v.id;
if (attName === "class") { if (attName === "class") {
ctx.rootContext.shouldDefineUtils = true; ctx.rootContext.shouldDefineUtils = true;
formattedValue = `utils.toObj(${formattedValue})`; formattedValue = `utils.toObj(${formattedValue})`;
@@ -2074,7 +2080,7 @@
priority: 20, priority: 20,
atNodeEncounter({ node, ctx }) { atNodeEncounter({ node, ctx }) {
let cond = ctx.getValue(node.getAttribute("t-if")); let cond = ctx.getValue(node.getAttribute("t-if"));
ctx.addIf(`${ctx.formatExpression(cond)}`); ctx.addIf(`${ctx.formatExpression(typeof cond === 'string' ? cond : cond.expr)}`);
return false; return false;
}, },
finalize({ ctx }) { finalize({ ctx }) {
@@ -2086,7 +2092,7 @@
priority: 30, priority: 30,
atNodeEncounter({ node, ctx }) { atNodeEncounter({ node, ctx }) {
let cond = ctx.getValue(node.getAttribute("t-elif")); let cond = ctx.getValue(node.getAttribute("t-elif"));
ctx.addLine(`else if (${ctx.formatExpression(cond)}) {`); ctx.addLine(`else if (${ctx.formatExpression(typeof cond === 'string' ? cond : cond.expr)}) {`);
ctx.indent(); ctx.indent();
return false; return false;
}, },
@@ -2188,9 +2194,6 @@
ctx.dedent(); ctx.dedent();
ctx.addLine("}"); ctx.addLine("}");
} }
if (node.hasAttribute("t-if") || node.hasAttribute("t-else") || node.hasAttribute("t-elif")) {
ctx.closeIf();
}
return true; return true;
} }
}); });
@@ -2203,7 +2206,7 @@
priority: 10, priority: 10,
atNodeEncounter({ node, qweb, ctx }) { atNodeEncounter({ node, qweb, ctx }) {
ctx.rootContext.shouldProtectContext = true; ctx.rootContext.shouldProtectContext = true;
ctx = ctx.subContext("inLoop", true); ctx = ctx.subContext("loopNumber", ctx.loopNumber + 1);
const elems = node.getAttribute("t-foreach"); const elems = node.getAttribute("t-foreach");
const name = node.getAttribute("t-as"); const name = node.getAttribute("t-as");
let arrayID = ctx.generateID(); let arrayID = ctx.generateID();
@@ -2217,13 +2220,14 @@
ctx.addLine(`_${valuesID} = Object.values(_${arrayID});`); ctx.addLine(`_${valuesID} = Object.values(_${arrayID});`);
ctx.closeIf(); ctx.closeIf();
ctx.addLine(`var _length${keysID} = _${keysID}.length;`); ctx.addLine(`var _length${keysID} = _${keysID}.length;`);
ctx.addLine(`for (let i = 0; i < _length${keysID}; i++) {`); const loopVar = `i${ctx.loopNumber}`;
ctx.addLine(`for (let ${loopVar} = 0; ${loopVar} < _length${keysID}; ${loopVar}++) {`);
ctx.indent(); ctx.indent();
ctx.addToScope(name + "_first", "i === 0"); ctx.addToScope(name + "_first", `${loopVar} === 0`);
ctx.addToScope(name + "_last", `i === _length${keysID} - 1`); ctx.addToScope(name + "_last", `${loopVar} === _length${keysID} - 1`);
ctx.addToScope(name + "_index", "i"); ctx.addToScope(name + "_index", loopVar);
ctx.addToScope(name, `_${keysID}[i]`); ctx.addToScope(name, `_${keysID}[${loopVar}]`);
ctx.addToScope(name + "_value", `_${valuesID}[i]`); ctx.addToScope(name + "_value", `_${valuesID}[${loopVar}]`);
const nodeCopy = node.cloneNode(true); const nodeCopy = node.cloneNode(true);
let shouldWarn = nodeCopy.tagName !== "t" && !nodeCopy.hasAttribute("t-key"); let shouldWarn = nodeCopy.tagName !== "t" && !nodeCopy.hasAttribute("t-key");
if (!shouldWarn && node.tagName === "t") { if (!shouldWarn && node.tagName === "t") {
@@ -2749,21 +2753,19 @@
ctx.addLine(`let key${keyID} = 'key' + ${key};`); ctx.addLine(`let key${keyID} = 'key' + ${key};`);
} }
ctx.addLine(`let def${defID};`); ctx.addLine(`let def${defID};`);
let templateID = key let locationExpr = `\`__${ctx.generateID()}__`;
? `key${keyID}` for (let i = 0; i < ctx.loopNumber - 1; i++) {
: ctx.inLoop locationExpr += `\${i${i + 1}}__`;
? ctx.currentKey
? `String(${ctx.currentKey} + '_k_' + i + '_c_' + ${componentID} )`
: `String(-${componentID} - i)`
: String(componentID);
if (ctx.allowMultipleRoots) {
templateID = `"_slot_${templateID}"`;
} }
if (key || ctx.inLoop) { if (key || ctx.currentKey) {
let id = ctx.generateID(); const k = key ? `key${keyID}` : ctx.currentKey;
ctx.addLine(`let templateId${id} = ${templateID};`); ctx.addLine(`let templateId${componentID} = ${locationExpr}\` + ${k};`);
templateID = `templateId${id}`;
} }
else {
locationExpr += ctx.loopNumber ? `\${i${ctx.loopNumber}}__\`` : "`";
ctx.addLine(`let templateId${componentID} = ${locationExpr};`);
}
const templateId = `templateId${componentID}`;
let ref = node.getAttribute("t-ref"); let ref = node.getAttribute("t-ref");
let refExpr = ""; let refExpr = "";
let refKey = ""; let refKey = "";
@@ -2825,7 +2827,7 @@
.map(function ([eventName, mods, handlerName, extraArgs]) { .map(function ([eventName, mods, handlerName, extraArgs]) {
let params = "owner"; let params = "owner";
if (extraArgs) { if (extraArgs) {
if (ctx.inLoop) { if (ctx.loopNumber) {
let argId = ctx.generateID(); let argId = ctx.generateID();
// we need to evaluate the arguments now, because the handler will // we need to evaluate the arguments now, because the handler will
// be set asynchronously later when the widget is ready, and the // be set asynchronously later when the widget is ready, and the
@@ -2857,7 +2859,7 @@
const styleCode = styleExpr ? `vn.elm.style = ${styleExpr};` : ""; const styleCode = styleExpr ? `vn.elm.style = ${styleExpr};` : "";
createHook = `vnode.data.hook = {create(_, vn){${styleCode}${eventsCode}}};`; createHook = `vnode.data.hook = {create(_, vn){${styleCode}${eventsCode}}};`;
} }
ctx.addLine(`let w${componentID} = ${templateID} in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap[${templateID}]] : false;`); ctx.addLine(`let w${componentID} = ${templateId} in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap[${templateId}]] : false;`);
if (ctx.parentNode) { if (ctx.parentNode) {
ctx.addLine(`let _${dummyID}_index = c${ctx.parentNode}.length;`); ctx.addLine(`let _${dummyID}_index = c${ctx.parentNode}.length;`);
} }
@@ -2907,11 +2909,8 @@
ctx.addLine(`let W${componentID} = context.constructor.components[componentKey${componentID}] || QWeb.components[componentKey${componentID}]${dynamicFallback};`); ctx.addLine(`let W${componentID} = context.constructor.components[componentKey${componentID}] || QWeb.components[componentKey${componentID}]${dynamicFallback};`);
// maybe only do this in dev mode... // maybe only do this in dev mode...
ctx.addLine(`if (!W${componentID}) {throw new Error('Cannot find the definition of component "' + componentKey${componentID} + '"')}`); ctx.addLine(`if (!W${componentID}) {throw new Error('Cannot find the definition of component "' + componentKey${componentID} + '"')}`);
if (QWeb.dev) {
ctx.addLine(`utils.validateProps(W${componentID}, props${componentID})`);
}
ctx.addLine(`w${componentID} = new W${componentID}(parent, props${componentID});`); ctx.addLine(`w${componentID} = new W${componentID}(parent, props${componentID});`);
ctx.addLine(`parent.__owl__.cmap[${templateID}] = w${componentID}.__owl__.id;`); ctx.addLine(`parent.__owl__.cmap[${templateId}] = w${componentID}.__owl__.id;`);
// SLOTS // SLOTS
const varDefs = []; const varDefs = [];
const hasSlots = node.childNodes.length; const hasSlots = node.childNodes.length;
@@ -2960,7 +2959,7 @@
if (shouldProxy) { if (shouldProxy) {
registerCode = `utils.defineProxy(vn${ctx.rootNode}, pvnode);`; registerCode = `utils.defineProxy(vn${ctx.rootNode}, pvnode);`;
} }
ctx.addLine(`def${defID} = def${defID}.then(vnode=>{if (w${componentID}.__owl__.isDestroyed){return}${createHook}let pvnode=h(vnode.sel, {key: ${templateID}, hook: {insert(vn) {let nvn=w${componentID}.__mount(vnode, pvnode.elm);pvnode.elm=nvn.elm;${refExpr}${transitionsInsertCode}},remove() {},destroy(vn) {${finalizeComponentCode}}}});${registerCode}w${componentID}.__owl__.pvnode = pvnode;});`); ctx.addLine(`def${defID} = def${defID}.then(vnode=>{if (w${componentID}.__owl__.isDestroyed){return}${createHook}let pvnode=h(vnode.sel, {key: ${templateId}, hook: {insert(vn) {let nvn=w${componentID}.__mount(vnode, pvnode.elm);pvnode.elm=nvn.elm;${refExpr}${transitionsInsertCode}},remove() {},destroy(vn) {${finalizeComponentCode}}}});${registerCode}w${componentID}.__owl__.pvnode = pvnode;});`);
ctx.addElse(); ctx.addElse();
// need to update component // need to update component
let patchQueueCode = async || keepAlive ? `fiber${componentID}` : "extra.fiber"; let patchQueueCode = async || keepAlive ? `fiber${componentID}` : "extra.fiber";
@@ -2991,9 +2990,6 @@
else { else {
ctx.addLine(`extra.promises.push(def${defID});`); ctx.addLine(`extra.promises.push(def${defID});`);
} }
if (node.hasAttribute("t-if") || node.hasAttribute("t-else") || node.hasAttribute("t-elif")) {
ctx.closeIf();
}
return true; return true;
} }
}); });
@@ -3799,6 +3795,7 @@
} }
var _hooks = /*#__PURE__*/Object.freeze({ var _hooks = /*#__PURE__*/Object.freeze({
__proto__: null,
useState: useState, useState: useState,
onMounted: onMounted, onMounted: onMounted,
onWillUnmount: onWillUnmount, onWillUnmount: onWillUnmount,
@@ -4007,6 +4004,7 @@
} }
var _tags = /*#__PURE__*/Object.freeze({ var _tags = /*#__PURE__*/Object.freeze({
__proto__: null,
xml: xml xml: xml
}); });
@@ -4319,8 +4317,8 @@
exports.utils = utils; exports.utils = utils;
exports.__info__.version = '0.23.0'; exports.__info__.version = '0.23.0';
exports.__info__.date = '2019-10-18T14:02:51.841Z'; exports.__info__.date = '2019-10-24T07:34:00.585Z';
exports.__info__.hash = '1bb4577'; exports.__info__.hash = 'a3317ab';
exports.__info__.url = 'https://github.com/odoo/owl'; exports.__info__.url = 'https://github.com/odoo/owl';
}(this.owl = this.owl || {})); }(this.owl = this.owl || {}));