Skip to content

Commit

Permalink
[REL] v2.2.8
Browse files Browse the repository at this point in the history
# v2.2.8

 - [IMP] template set config: getTemplate function
 - [IMP] parser: .trim modifier implies .lazy modifier
 - [REF] parser, template_set: factor out parseXML function
  • Loading branch information
sdegueldre committed Jan 12, 2024
1 parent 7b454da commit 61fc3f4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 48 deletions.
65 changes: 20 additions & 45 deletions docs/owl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3159,8 +3159,14 @@ const helpers = {
makeRefWrapper,
};

const bdom = { text, createBlock, list, multi, html, toggler, comment };
function parseXML$1(xml) {
/**
* Parses an XML string into an XML document, throwing errors on parser errors
* instead of returning an XML document containing the parseerror.
*
* @param xml the string to parse
* @returns an XML document corresponding to the content of the string
*/
function parseXML(xml) {
const parser = new DOMParser();
const doc = parser.parseFromString(xml, "text/xml");
if (doc.getElementsByTagName("parsererror").length) {
Expand All @@ -3187,7 +3193,9 @@ function parseXML$1(xml) {
throw new OwlError(msg);
}
return doc;
}
}

const bdom = { text, createBlock, list, multi, html, toggler, comment };
class TemplateSet {
constructor(config = {}) {
this.rawTemplates = Object.create(globalTemplates);
Expand All @@ -3206,6 +3214,7 @@ class TemplateSet {
}
}
}
this.getRawTemplate = config.getTemplate;
}
static registerTemplate(name, fn) {
globalTemplates[name] = fn;
Expand Down Expand Up @@ -3235,15 +3244,16 @@ class TemplateSet {
// empty string
return;
}
xml = xml instanceof Document ? xml : parseXML$1(xml);
xml = xml instanceof Document ? xml : parseXML(xml);
for (const template of xml.querySelectorAll("[t-name]")) {
const name = template.getAttribute("t-name");
this.addTemplate(name, template);
}
}
getTemplate(name) {
var _a;
if (!(name in this.templates)) {
const rawTemplate = this.rawTemplates[name];
const rawTemplate = ((_a = this.getRawTemplate) === null || _a === void 0 ? void 0 : _a.call(this, name)) || this.rawTemplates[name];
if (rawTemplate === undefined) {
let extraInfo = "";
try {
Expand Down Expand Up @@ -4953,9 +4963,9 @@ function parseDOMNode(node, ctx) {
const isSelect = tagName === "select";
const isCheckboxInput = isInput && typeAttr === "checkbox";
const isRadioInput = isInput && typeAttr === "radio";
const hasLazyMod = attr.includes(".lazy");
const hasNumberMod = attr.includes(".number");
const hasTrimMod = attr.includes(".trim");
const hasLazyMod = hasTrimMod || attr.includes(".lazy");
const hasNumberMod = attr.includes(".number");
const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input";
model = {
baseExpr,
Expand Down Expand Up @@ -5501,41 +5511,6 @@ function normalizeTEscTOut(el) {
function normalizeXML(el) {
normalizeTIf(el);
normalizeTEscTOut(el);
}
/**
* Parses an XML string into an XML document, throwing errors on parser errors
* instead of returning an XML document containing the parseerror.
*
* @param xml the string to parse
* @returns an XML document corresponding to the content of the string
*/
function parseXML(xml) {
const parser = new DOMParser();
const doc = parser.parseFromString(xml, "text/xml");
if (doc.getElementsByTagName("parsererror").length) {
let msg = "Invalid XML in template.";
const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent;
if (parsererrorText) {
msg += "\nThe parser has produced the following error message:\n" + parsererrorText;
const re = /\d+/g;
const firstMatch = re.exec(parsererrorText);
if (firstMatch) {
const lineNumber = Number(firstMatch[0]);
const line = xml.split("\n")[lineNumber - 1];
const secondMatch = re.exec(parsererrorText);
if (line && secondMatch) {
const columnIndex = Number(secondMatch[0]) - 1;
if (line[columnIndex]) {
msg +=
`\nThe error might be located at xml line ${lineNumber} column ${columnIndex}\n` +
`${line}\n${"-".repeat(columnIndex - 1)}^`;
}
}
}
}
throw new OwlError(msg);
}
return doc;
}

function compile(template, options = {}) {
Expand All @@ -5562,7 +5537,7 @@ function compile(template, options = {}) {
}

// do not modify manually. This file is generated by the release script.
const version = "2.2.7";
const version = "2.2.8";

// -----------------------------------------------------------------------------
// Scheduler
Expand Down Expand Up @@ -5991,6 +5966,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 };


__info__.date = '2023-12-06T13:56:01.636Z';
__info__.hash = 'e94428a';
__info__.date = '2024-01-12T10:02:46.131Z';
__info__.hash = '7b454da';
__info__.url = 'https://github.com/odoo/owl';
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@odoo/owl",
"version": "2.2.7",
"version": "2.2.8",
"description": "Odoo Web Library (OWL)",
"main": "dist/owl.cjs.js",
"module": "dist/owl.es.js",
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// do not modify manually. This file is generated by the release script.
export const version = "2.2.7";
export const version = "2.2.8";

0 comments on commit 61fc3f4

Please sign in to comment.