@odoo/owl 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/dist/owl.cjs.js CHANGED
@@ -86,67 +86,6 @@ function toggler(key, child) {
86
86
 
87
87
  // Custom error class that wraps error that happen in the owl lifecycle
88
88
  class OwlError extends Error {
89
- }
90
- // Maps fibers to thrown errors
91
- const fibersInError = new WeakMap();
92
- const nodeErrorHandlers = new WeakMap();
93
- function _handleError(node, error) {
94
- if (!node) {
95
- return false;
96
- }
97
- const fiber = node.fiber;
98
- if (fiber) {
99
- fibersInError.set(fiber, error);
100
- }
101
- const errorHandlers = nodeErrorHandlers.get(node);
102
- if (errorHandlers) {
103
- let handled = false;
104
- // execute in the opposite order
105
- for (let i = errorHandlers.length - 1; i >= 0; i--) {
106
- try {
107
- errorHandlers[i](error);
108
- handled = true;
109
- break;
110
- }
111
- catch (e) {
112
- error = e;
113
- }
114
- }
115
- if (handled) {
116
- return true;
117
- }
118
- }
119
- return _handleError(node.parent, error);
120
- }
121
- function handleError(params) {
122
- let { error } = params;
123
- // Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
124
- if (!(error instanceof OwlError)) {
125
- error = Object.assign(new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`), { cause: error });
126
- }
127
- const node = "node" in params ? params.node : params.fiber.node;
128
- const fiber = "fiber" in params ? params.fiber : node.fiber;
129
- if (fiber) {
130
- // resets the fibers on components if possible. This is important so that
131
- // new renderings can be properly included in the initial one, if any.
132
- let current = fiber;
133
- do {
134
- current.node.fiber = current;
135
- current = current.parent;
136
- } while (current);
137
- fibersInError.set(fiber.root, error);
138
- }
139
- const handled = _handleError(node, error);
140
- if (!handled) {
141
- console.warn(`[Owl] Unhandled error. Destroying the root component`);
142
- try {
143
- node.app.destroy();
144
- }
145
- catch (e) {
146
- console.error(e);
147
- }
148
- throw error;
149
- }
150
89
  }
151
90
 
152
91
  const { setAttribute: elemSetAttribute, removeAttribute } = Element.prototype;
@@ -775,12 +714,7 @@ function buildTree(node, parent = null, domParentTree = null) {
775
714
  info.push({ type: "child", idx: index });
776
715
  el = document.createTextNode("");
777
716
  }
778
- const attrs = node.attributes;
779
- const ns = attrs.getNamedItem("block-ns");
780
- if (ns) {
781
- attrs.removeNamedItem("block-ns");
782
- currentNS = ns.value;
783
- }
717
+ currentNS || (currentNS = node.namespaceURI);
784
718
  if (!el) {
785
719
  el = currentNS
786
720
  ? document.createElementNS(currentNS, tagName)
@@ -796,6 +730,7 @@ function buildTree(node, parent = null, domParentTree = null) {
796
730
  const fragment = document.createElement("template").content;
797
731
  fragment.appendChild(el);
798
732
  }
733
+ const attrs = node.attributes;
799
734
  for (let i = 0; i < attrs.length; i++) {
800
735
  const attrName = attrs[i].name;
801
736
  const attrValue = attrs[i].value;
@@ -1607,6 +1542,68 @@ function remove(vnode, withBeforeRemove = false) {
1607
1542
  vnode.remove();
1608
1543
  }
1609
1544
 
1545
+ // Maps fibers to thrown errors
1546
+ const fibersInError = new WeakMap();
1547
+ const nodeErrorHandlers = new WeakMap();
1548
+ function _handleError(node, error) {
1549
+ if (!node) {
1550
+ return false;
1551
+ }
1552
+ const fiber = node.fiber;
1553
+ if (fiber) {
1554
+ fibersInError.set(fiber, error);
1555
+ }
1556
+ const errorHandlers = nodeErrorHandlers.get(node);
1557
+ if (errorHandlers) {
1558
+ let handled = false;
1559
+ // execute in the opposite order
1560
+ for (let i = errorHandlers.length - 1; i >= 0; i--) {
1561
+ try {
1562
+ errorHandlers[i](error);
1563
+ handled = true;
1564
+ break;
1565
+ }
1566
+ catch (e) {
1567
+ error = e;
1568
+ }
1569
+ }
1570
+ if (handled) {
1571
+ return true;
1572
+ }
1573
+ }
1574
+ return _handleError(node.parent, error);
1575
+ }
1576
+ function handleError(params) {
1577
+ let { error } = params;
1578
+ // Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
1579
+ if (!(error instanceof OwlError)) {
1580
+ error = Object.assign(new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`), { cause: error });
1581
+ }
1582
+ const node = "node" in params ? params.node : params.fiber.node;
1583
+ const fiber = "fiber" in params ? params.fiber : node.fiber;
1584
+ if (fiber) {
1585
+ // resets the fibers on components if possible. This is important so that
1586
+ // new renderings can be properly included in the initial one, if any.
1587
+ let current = fiber;
1588
+ do {
1589
+ current.node.fiber = current;
1590
+ current = current.parent;
1591
+ } while (current);
1592
+ fibersInError.set(fiber.root, error);
1593
+ }
1594
+ const handled = _handleError(node, error);
1595
+ if (!handled) {
1596
+ console.warn(`[Owl] Unhandled error. Destroying the root component`);
1597
+ try {
1598
+ node.app.destroy();
1599
+ }
1600
+ catch (e) {
1601
+ console.error(e);
1602
+ }
1603
+ throw error;
1604
+ }
1605
+ }
1606
+
1610
1607
  function makeChildFiber(node, parent) {
1611
1608
  let current = node.fiber;
1612
1609
  if (current) {
@@ -3011,8 +3008,8 @@ function prepareList(collection) {
3011
3008
  values = keys;
3012
3009
  }
3013
3010
  else {
3014
- values = Object.keys(collection);
3015
- keys = Object.values(collection);
3011
+ values = Object.values(collection);
3012
+ keys = Object.keys(collection);
3016
3013
  }
3017
3014
  }
3018
3015
  else {
@@ -3857,7 +3854,7 @@ class CodeGenerator {
3857
3854
  createBlock(parentBlock, type, ctx) {
3858
3855
  const hasRoot = this.target.hasRoot;
3859
3856
  const block = new BlockDescription(this.target, type);
3860
- if (!hasRoot && !ctx.preventRoot) {
3857
+ if (!hasRoot) {
3861
3858
  this.target.hasRoot = true;
3862
3859
  block.isRoot = true;
3863
3860
  }
@@ -3880,7 +3877,7 @@ class CodeGenerator {
3880
3877
  if (ctx.tKeyExpr) {
3881
3878
  blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`;
3882
3879
  }
3883
- if (block.isRoot && !ctx.preventRoot) {
3880
+ if (block.isRoot) {
3884
3881
  if (this.target.on) {
3885
3882
  blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on);
3886
3883
  }
@@ -4056,11 +4053,6 @@ class CodeGenerator {
4056
4053
  }
4057
4054
  // attributes
4058
4055
  const attrs = {};
4059
- const nameSpace = ast.ns || ctx.nameSpace;
4060
- if (nameSpace && isNewBlock) {
4061
- // specific namespace uri
4062
- attrs["block-ns"] = nameSpace;
4063
- }
4064
4056
  for (let key in ast.attrs) {
4065
4057
  let expr, attrName;
4066
4058
  if (key.startsWith("t-attf")) {
@@ -4176,7 +4168,10 @@ class CodeGenerator {
4176
4168
  const idx = block.insertData(setRefStr, "ref");
4177
4169
  attrs["block-ref"] = String(idx);
4178
4170
  }
4179
- const dom = xmlDoc.createElement(ast.tag);
4171
+ const nameSpace = ast.ns || ctx.nameSpace;
4172
+ const dom = nameSpace
4173
+ ? xmlDoc.createElementNS(nameSpace, ast.tag)
4174
+ : xmlDoc.createElement(ast.tag);
4180
4175
  for (const [attr, val] of Object.entries(attrs)) {
4181
4176
  if (!(attr === "class" && val === "")) {
4182
4177
  dom.setAttribute(attr, val);
@@ -4218,7 +4213,7 @@ class CodeGenerator {
4218
4213
  break;
4219
4214
  }
4220
4215
  }
4221
- this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
4216
+ this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx);
4222
4217
  }
4223
4218
  }
4224
4219
  return block.varName;
@@ -4321,7 +4316,7 @@ class CodeGenerator {
4321
4316
  break;
4322
4317
  }
4323
4318
  }
4324
- this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
4319
+ this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx);
4325
4320
  }
4326
4321
  // note: this part is duplicated from end of compilemulti:
4327
4322
  const args = block.children.map((c) => c.varName).join(", ");
@@ -4350,18 +4345,18 @@ class CodeGenerator {
4350
4345
  }
4351
4346
  this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`);
4352
4347
  this.target.indentLevel++;
4353
- this.addLine(`ctx[\`${ast.elem}\`] = ${vals}[${loopVar}];`);
4348
+ this.addLine(`ctx[\`${ast.elem}\`] = ${keys}[${loopVar}];`);
4354
4349
  if (!ast.hasNoFirst) {
4355
4350
  this.addLine(`ctx[\`${ast.elem}_first\`] = ${loopVar} === 0;`);
4356
4351
  }
4357
4352
  if (!ast.hasNoLast) {
4358
- this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${vals}.length - 1;`);
4353
+ this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${keys}.length - 1;`);
4359
4354
  }
4360
4355
  if (!ast.hasNoIndex) {
4361
4356
  this.addLine(`ctx[\`${ast.elem}_index\`] = ${loopVar};`);
4362
4357
  }
4363
4358
  if (!ast.hasNoValue) {
4364
- this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
4359
+ this.addLine(`ctx[\`${ast.elem}_value\`] = ${vals}[${loopVar}];`);
4365
4360
  }
4366
4361
  this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar);
4367
4362
  if (this.dev) {
@@ -4436,7 +4431,6 @@ class CodeGenerator {
4436
4431
  block,
4437
4432
  index,
4438
4433
  forceNewBlock: !isTSet,
4439
- preventRoot: ctx.preventRoot,
4440
4434
  isLast: ctx.isLast && i === l - 1,
4441
4435
  });
4442
4436
  this.compileAST(child, subCtx);
@@ -4445,21 +4439,19 @@ class CodeGenerator {
4445
4439
  }
4446
4440
  }
4447
4441
  if (isNewBlock) {
4448
- if (block.hasDynamicChildren) {
4449
- if (block.children.length) {
4450
- const code = this.target.code;
4451
- const children = block.children.slice();
4452
- let current = children.shift();
4453
- for (let i = codeIdx; i < code.length; i++) {
4454
- if (code[i].trimStart().startsWith(`const ${current.varName} `)) {
4455
- code[i] = code[i].replace(`const ${current.varName}`, current.varName);
4456
- current = children.shift();
4457
- if (!current)
4458
- break;
4459
- }
4442
+ if (block.hasDynamicChildren && block.children.length) {
4443
+ const code = this.target.code;
4444
+ const children = block.children.slice();
4445
+ let current = children.shift();
4446
+ for (let i = codeIdx; i < code.length; i++) {
4447
+ if (code[i].trimStart().startsWith(`const ${current.varName} `)) {
4448
+ code[i] = code[i].replace(`const ${current.varName}`, current.varName);
4449
+ current = children.shift();
4450
+ if (!current)
4451
+ break;
4460
4452
  }
4461
- this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
4462
4453
  }
4454
+ this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx);
4463
4455
  }
4464
4456
  const args = block.children.map((c) => c.varName).join(", ");
4465
4457
  this.insertBlock(`multi([${args}])`, block, ctx);
@@ -4473,24 +4465,23 @@ class CodeGenerator {
4473
4465
  ctxVar = generateId("ctx");
4474
4466
  this.addLine(`let ${ctxVar} = ${compileExpr(ast.context)};`);
4475
4467
  }
4468
+ const isDynamic = INTERP_REGEXP.test(ast.name);
4469
+ const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`";
4470
+ if (block && !forceNewBlock) {
4471
+ this.insertAnchor(block);
4472
+ }
4473
+ block = this.createBlock(block, "multi", ctx);
4476
4474
  if (ast.body) {
4477
4475
  this.addLine(`${ctxVar} = Object.create(${ctxVar});`);
4478
4476
  this.addLine(`${ctxVar}[isBoundary] = 1;`);
4479
4477
  this.helpers.add("isBoundary");
4480
- const subCtx = createContext(ctx, { preventRoot: true, ctxVar });
4478
+ const subCtx = createContext(ctx, { ctxVar });
4481
4479
  const bl = this.compileMulti({ type: 3 /* Multi */, content: ast.body }, subCtx);
4482
4480
  if (bl) {
4483
4481
  this.helpers.add("zero");
4484
4482
  this.addLine(`${ctxVar}[zero] = ${bl};`);
4485
4483
  }
4486
4484
  }
4487
- const isDynamic = INTERP_REGEXP.test(ast.name);
4488
- const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`";
4489
- if (block) {
4490
- if (!forceNewBlock) {
4491
- this.insertAnchor(block);
4492
- }
4493
- }
4494
4485
  const key = `key + \`${this.generateComponentKey()}\``;
4495
4486
  if (isDynamic) {
4496
4487
  const templateVar = generateId("template");
@@ -4498,7 +4489,6 @@ class CodeGenerator {
4498
4489
  this.staticDefs.push({ id: "call", expr: `app.callTemplate.bind(app)` });
4499
4490
  }
4500
4491
  this.define(templateVar, subTemplate);
4501
- block = this.createBlock(block, "multi", ctx);
4502
4492
  this.insertBlock(`call(this, ${templateVar}, ${ctxVar}, node, ${key})`, block, {
4503
4493
  ...ctx,
4504
4494
  forceNewBlock: !block,
@@ -4507,7 +4497,6 @@ class CodeGenerator {
4507
4497
  else {
4508
4498
  const id = generateId(`callTemplate_`);
4509
4499
  this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` });
4510
- block = this.createBlock(block, "multi", ctx);
4511
4500
  this.insertBlock(`${id}.call(this, ${ctxVar}, node, ${key})`, block, {
4512
4501
  ...ctx,
4513
4502
  forceNewBlock: !block,
@@ -4829,7 +4818,7 @@ function parse(xml) {
4829
4818
  }
4830
4819
  function _parse(xml) {
4831
4820
  normalizeXML(xml);
4832
- const ctx = { inPreTag: false, inSVG: false };
4821
+ const ctx = { inPreTag: false };
4833
4822
  return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" };
4834
4823
  }
4835
4824
  function parseNode(node, ctx) {
@@ -4920,9 +4909,7 @@ function parseDOMNode(node, ctx) {
4920
4909
  if (tagName === "pre") {
4921
4910
  ctx.inPreTag = true;
4922
4911
  }
4923
- const shouldAddSVGNS = ROOT_SVG_TAGS.has(tagName) && !ctx.inSVG;
4924
- ctx.inSVG = ctx.inSVG || shouldAddSVGNS;
4925
- const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null;
4912
+ let ns = !ctx.nameSpace && ROOT_SVG_TAGS.has(tagName) ? "http://www.w3.org/2000/svg" : null;
4926
4913
  const ref = node.getAttribute("t-ref");
4927
4914
  node.removeAttribute("t-ref");
4928
4915
  const nodeAttrsNames = node.getAttributeNames();
@@ -4984,6 +4971,9 @@ function parseDOMNode(node, ctx) {
4984
4971
  else if (attr.startsWith("block-")) {
4985
4972
  throw new OwlError(`Invalid attribute: '${attr}'`);
4986
4973
  }
4974
+ else if (attr === "xmlns") {
4975
+ ns = value;
4976
+ }
4987
4977
  else if (attr !== "t-name") {
4988
4978
  if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
4989
4979
  throw new OwlError(`Unknown QWeb directive: '${attr}'`);
@@ -4996,6 +4986,9 @@ function parseDOMNode(node, ctx) {
4996
4986
  attrs[attr] = value;
4997
4987
  }
4998
4988
  }
4989
+ if (ns) {
4990
+ ctx.nameSpace = ns;
4991
+ }
4999
4992
  const children = parseChildren(node, ctx);
5000
4993
  return {
5001
4994
  type: 2 /* DomNode */,
@@ -5551,11 +5544,20 @@ function compile(template, options = {}) {
5551
5544
  const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
5552
5545
  const code = codeGenerator.generateCode();
5553
5546
  // template function
5554
- return new Function("app, bdom, helpers", code);
5547
+ try {
5548
+ return new Function("app, bdom, helpers", code);
5549
+ }
5550
+ catch (originalError) {
5551
+ const { name } = options;
5552
+ const nameStr = name ? `template "${name}"` : "anonymous template";
5553
+ const err = new OwlError(`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`);
5554
+ err.cause = originalError;
5555
+ throw err;
5556
+ }
5555
5557
  }
5556
5558
 
5557
5559
  // do not modify manually. This file is generated by the release script.
5558
- const version = "2.2.3";
5560
+ const version = "2.2.5";
5559
5561
 
5560
5562
  // -----------------------------------------------------------------------------
5561
5563
  // Scheduler
@@ -6022,6 +6024,6 @@ exports.whenReady = whenReady;
6022
6024
  exports.xml = xml;
6023
6025
 
6024
6026
 
6025
- __info__.date = '2023-07-20T06:05:29.796Z';
6026
- __info__.hash = 'b1a3b32';
6027
+ __info__.date = '2023-08-07T10:26:30.557Z';
6028
+ __info__.hash = 'b25e988';
6027
6029
  __info__.url = 'https://github.com/odoo/owl';