Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] 8aabd68eb5 Bump word-wrap from 1.2.3 to 1.2.4
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 13:23:16 +00:00
147 changed files with 3324 additions and 13185 deletions
+1 -8
View File
@@ -15,7 +15,7 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
#ide's #ide's
**/.vscode/* .vscode
.idea .idea
node_modules node_modules
@@ -26,10 +26,3 @@ release-notes.md
# useful in some cases # useful in some cases
/temp /temp
# owl-vision
*/owl-vision/out/
*/owl-vision/.vs/
**/*.vsix
!*/owl-vision/.vscode/launch.json
!*/owl-vision/.vscode/tasks.json
-2
View File
@@ -61,8 +61,6 @@ The `config` object is an object with some of the following keys:
templates (see [translations](translations.md)) templates (see [translations](translations.md))
- **`templates (string | xml document)`**: all the templates that will be used by - **`templates (string | xml document)`**: all the templates that will be used by
the components created by the application. the components created by the application.
- **`getTemplate ((s: string) => Element | Function | string | void)`**: a function that will be called by owl when it
needs a template. If undefined is returned, owl looks into the app templates.
- **`warnIfNoStaticProps (boolean, default=false)`**: if true, Owl will log a warning - **`warnIfNoStaticProps (boolean, default=false)`**: if true, Owl will log a warning
whenever it encounters a component that does not provide a [static props description](props.md#props-validation). whenever it encounters a component that does not provide a [static props description](props.md#props-validation).
+1 -1
View File
@@ -357,7 +357,7 @@ cleaning operation, since the component may be destroyed before it has even been
mounted. The `willDestroy` hook is useful in that situation, since it is always mounted. The `willDestroy` hook is useful in that situation, since it is always
called. called.
The `onWillDestroy` hook is used to register a function that will be executed at The `onWillUnmount` hook is used to register a function that will be executed at
this moment: this moment:
```javascript ```javascript
+2 -2
View File
@@ -51,8 +51,8 @@ that render its content, and a fallback if an error happened.
```js ```js
class ErrorBoundary extends Component { class ErrorBoundary extends Component {
static template = xml` static template = xml`
<t t-if="state.error" t-slot="fallback">An error occurred</t> <t t-if="error" t-slot="fallback">An error occurred</t>
<t t-else="" t-slot="default"/>`; <t t-else="" t-slot="content"`;
setup() { setup() {
this.state = useState({ error: false }); this.state = useState({ error: false });
+2 -3
View File
@@ -190,13 +190,12 @@ will then be updated accordingly.
### `useExternalListener` ### `useExternalListener`
The `useExternalListener` hook helps solve a very common problem: adding and removing The `useExternalListener` hook helps solve a very common problem: adding and removing
a listener on some target whenever a component is mounted/unmounted. It takes a target a listener on some target whenever a component is mounted/unmounted. For example,
as its first argument, forwards the other arguments to `addEventListener`. For example,
a dropdown menu (or its parent) may need to listen to a `click` event on `window` a dropdown menu (or its parent) may need to listen to a `click` event on `window`
to be closed: to be closed:
```js ```js
useExternalListener(window, "click", this.closeMenu, { capture: true }); useExternalListener(window, "click", this.closeMenu);
``` ```
### `useComponent` ### `useComponent`
+1 -1
View File
@@ -152,7 +152,7 @@ This may seem counter-intuitive, but it makes perfect sense in the context of co
```js ```js
class DoubleCounter extends Component { class DoubleCounter extends Component {
static template = xml` static template = xml`
<t t-esc="'selected: ' + state.selected + ', value: ' + state[state.selected]"/> <t t-esc="state.selected + ': ' + state[state.selected].value"/>
<button t-on-click="() => this.state.count1++">increment count 1</button> <button t-on-click="() => this.state.count1++">increment count 1</button>
<button t-on-click="() => this.state.count2++">increment count 2</button> <button t-on-click="() => this.state.count2++">increment count 2</button>
<button t-on-click="changeCounter">Switch counter</button> <button t-on-click="changeCounter">Switch counter</button>
+25 -30
View File
@@ -35,13 +35,13 @@ The components tab is separated into two sub windows: the components tree in the
the component details in the right. The components tree will display all the different the component details in the right. The components tree will display all the different
components that are present in the tab in the form of a tree. The root of this tree is components that are present in the tab in the form of a tree. The root of this tree is
actually the app which is not a component but can still be inspected by the devtools like actually the app which is not a component but can still be inspected by the devtools like
one. There can also be multiple apps loaded in the page like in website: one. There can also be multiple apps loaded in the page like in the following:
<img src="screenshots/multi_apps.png"/> <img src="screenshots/multi_apps.png"/>
There is a convenient search bar at the top of the components tree which will help finding There is a convenient search bar at the top of the components tree which will help finding
the components tou want in the tree and also, an element picker can be used to directly select the components tou want in the tree and also, an element picker can be used to directly select
the component you want to focus on in the page which is especially useful when 1trying to find the component you want to focus on in the page which is especially useful when trying to find
what you want. Just click on the elements picker icon and click on the element you want to focus what you want. Just click on the elements picker icon and click on the element you want to focus
on in the page and it will be selected in the devtools accordingly. Hovering any element in the on in the page and it will be selected in the devtools accordingly. Hovering any element in the
page in this mode will highlight it and the same happens anytime in the components tree. page in this mode will highlight it and the same happens anytime in the components tree.
@@ -64,18 +64,25 @@ as its env, props, observed states and all the other variables that are present
While the props and the env are already present on the actual instance of the component and are While the props and the env are already present on the actual instance of the component and are
pretty explicit by themselves, the observed state value is a bit more complicated to grasp. pretty explicit by themselves, the observed state value is a bit more complicated to grasp.
The observed state is actually information about which variables are being observed by the component: The observed state is actually information about which variables are observed by the component
when any property of a reactive object is being read by the component, the component will subscribe which will trigger a rerender of the component when it is modified. The keys represent which part of the
to this property which means it will listen to any change that can occur on the property and render variable is actually observed and the target is the actual variable. For simplicity, the properties
when such a change occurs. This can be visualized easily within the devtools inside of the observed that are not observed by the component are greyed out while the others are in bold. This means that
state section: observed properties of the reactive object(s) are displayed in bold while the others editing bold ones will trigger a rerender while the greyed out ones will not.
are greyed out. Do keep in mind that a greyed out property in the observed state of one component
may be observed by another and the other way around is also possible. Here is an example for some
user Field component:
<img src="screenshots/states.png"/> <img src="screenshots/states.png"/>
Navigation inside the properties is also similar to the one in console variables: properties have In the given example, we have two keys/target pairs for two different variables. The first one indicates
that adding or removing an element to the array will trigger a rerender since the length will have changed.
Replacing the element at index 0, 1 or 2 will also have the same effect as implied by the keys. It doesn't
mean that editing the properties of element at index 0, 1 or 2 will rerender the component though. It may
be the case for some but this will be described in another keys/target pair. The second keys/target pair
is actually the element at index 0 of the first pair. It only has id in the keys meaning that only the
id property will actually trigger a rerender the component when modified. Be aware however that the other
properties may be in the observed state of another component like a child one in this case. A greyed out
property only implies it is not reactive for the selected component and not for the others.
The navigation inside the properties is also similar to the one in console variables: properties have
their prototype displayed and getters will get their value when clicked on (...). It is also possible to their prototype displayed and getters will get their value when clicked on (...). It is also possible to
send any property to the console using the right-click context menu on it and functions can be inspected send any property to the console using the right-click context menu on it and functions can be inspected
in the sources tab as well. in the sources tab as well.
@@ -89,10 +96,8 @@ component's name. Using the left click on the component's name will focus it in
It is also possible to edit any of the leaf node properties. To do so, you must double click on the It is also possible to edit any of the leaf node properties. To do so, you must double click on the
property's value and modify it using the freshly created input then press enter to apply the changes. property's value and modify it using the freshly created input then press enter to apply the changes.
Do note that the modified values should be written in JSON format in order to be valid (examples: Do note that the modified values should be written in JSON format in order to be valid (examples:
89, "yes", undefined, null, \["hello", 15\], {"a": 1}, true, ...). Editing any value will produce a 89, "yes", undefined, null, \["hello", 15\], {"a": 1}, true, ...). Whether it has an impact on the
manual render of the component (or the root component of the application in the case of env values). component or not and whether it produces an error is the responsability of the user.
Whether the edition has an impact on the component or not and whether it produces an error is the
responsability of the user.
<img src="screenshots/edit.png"/> <img src="screenshots/edit.png"/>
@@ -112,8 +117,7 @@ are intercepted by the devtools using the record button.
The second button is used to clear all the events that have been recorded. The select can be used to The second button is used to clear all the events that have been recorded. The select can be used to
switch between the tree view (which shows the causality between renders) and the events log view which switch between the tree view (which shows the causality between renders) and the events log view which
simply displays the events in the exact order they were triggered. In this view, you can expand the create, simply displays the events in the exact order they were triggered. In this view, you can expand the create,
update and destroy events which reveals the component that initiated the event. Also, a transition line will update and destroy events which reveals the component that initiated the event.
appear each time a new animation frame has been loaded between events.
<img src="screenshots/events_log.png"/> <img src="screenshots/events_log.png"/>
@@ -127,29 +131,20 @@ There is also the Trace Renderings and Trace Subscriptions features. These featu
recording of events and have no effect on the profiler tab. The Trace Renderings option is used to log in recording of events and have no effect on the profiler tab. The Trace Renderings option is used to log in
the console all the render events and allows to show their traceback information. Similarly, the Trace the console all the render events and allows to show their traceback information. Similarly, the Trace
Subscriptions option logs all the properties that caused a render event and also allows to see the traceback Subscriptions option logs all the properties that caused a render event and also allows to see the traceback
of the modification. of the modification
<img src="screenshots/trace_rendering.png"/> <img src="screenshots/trace_rendering.png"/>
<img src="screenshots/trace_subscriptions.png"/> <img src="screenshots/trace_subscriptions.png"/>
The Owl Devtools also allow to inspect iframes coded in Owl: when an Owl iframe is detected in the page,
the iframe selector will appear next to the tabs. This allows to switch from an iframe to another easily.
Be aware that switching iframes will clear all record events from the profiler tab. Iframes detection is
currently not working in the firefox version, we are aware of this issue and will try to address it in the
future.
<img src="screenshots/iframes.png"/>
## Options ## Options
The owl devtools extension has a dark mode feature which defaults to your general devtools settings and can The owl devtools extension has a dark mode feature which defaults to your general devtools settings and can
be toggled using the sun/moon icon at the top-right corner of the tab. There is also a refresh button to be toggled using the sun/moon icon at the top-right corner of the tab. All the examples above were created
completely reset the owl devtools. with the dark mode enabled. There is also a refresh button to completely reset the owl devtools.
<img src="screenshots/darkmode.png"/> <img src="screenshots/darkmode.png"/>
## Troubleshooting ## Troubleshooting
If the feedback from the page to the devtools seems to be cut, you can first try to use the refresh If the feedback from the page to the devtools seems to be cut, just close the devtools and refresh the page.
button mentioned above but if it still doesn't seem to work, just close the devtools and refresh the page.
This will eventually happen any time a tab stays opened for too long without being refreshed. This will eventually happen any time a tab stays opened for too long without being refreshed.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 545 KiB

After

Width:  |  Height:  |  Size: 333 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 387 KiB

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 KiB

After

Width:  |  Height:  |  Size: 197 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 536 KiB

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 488 KiB

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 146 KiB

+182 -165
View File
@@ -82,6 +82,67 @@ function toggler(key, child) {
// Custom error class that wraps error that happen in the owl lifecycle // Custom error class that wraps error that happen in the owl lifecycle
class OwlError extends Error { class OwlError extends Error {
}
// Maps fibers to thrown errors
const fibersInError = new WeakMap();
const nodeErrorHandlers = new WeakMap();
function _handleError(node, error) {
if (!node) {
return false;
}
const fiber = node.fiber;
if (fiber) {
fibersInError.set(fiber, error);
}
const errorHandlers = nodeErrorHandlers.get(node);
if (errorHandlers) {
let handled = false;
// execute in the opposite order
for (let i = errorHandlers.length - 1; i >= 0; i--) {
try {
errorHandlers[i](error);
handled = true;
break;
}
catch (e) {
error = e;
}
}
if (handled) {
return true;
}
}
return _handleError(node.parent, error);
}
function handleError(params) {
let { error } = params;
// Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
if (!(error instanceof OwlError)) {
error = Object.assign(new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`), { cause: error });
}
const node = "node" in params ? params.node : params.fiber.node;
const fiber = "fiber" in params ? params.fiber : node.fiber;
if (fiber) {
// resets the fibers on components if possible. This is important so that
// new renderings can be properly included in the initial one, if any.
let current = fiber;
do {
current.node.fiber = current;
current = current.parent;
} while (current);
fibersInError.set(fiber.root, error);
}
const handled = _handleError(node, error);
if (!handled) {
console.warn(`[Owl] Unhandled error. Destroying the root component`);
try {
node.app.destroy();
}
catch (e) {
console.error(e);
}
throw error;
}
} }
const { setAttribute: elemSetAttribute, removeAttribute } = Element.prototype; const { setAttribute: elemSetAttribute, removeAttribute } = Element.prototype;
@@ -710,7 +771,12 @@ 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("");
} }
currentNS || (currentNS = node.namespaceURI); const attrs = node.attributes;
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)
@@ -726,7 +792,6 @@ 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;
@@ -1538,68 +1603,6 @@ function remove(vnode, withBeforeRemove = false) {
vnode.remove(); vnode.remove();
} }
// Maps fibers to thrown errors
const fibersInError = new WeakMap();
const nodeErrorHandlers = new WeakMap();
function _handleError(node, error) {
if (!node) {
return false;
}
const fiber = node.fiber;
if (fiber) {
fibersInError.set(fiber, error);
}
const errorHandlers = nodeErrorHandlers.get(node);
if (errorHandlers) {
let handled = false;
// execute in the opposite order
for (let i = errorHandlers.length - 1; i >= 0; i--) {
try {
errorHandlers[i](error);
handled = true;
break;
}
catch (e) {
error = e;
}
}
if (handled) {
return true;
}
}
return _handleError(node.parent, error);
}
function handleError(params) {
let { error } = params;
// Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
if (!(error instanceof OwlError)) {
error = Object.assign(new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`), { cause: error });
}
const node = "node" in params ? params.node : params.fiber.node;
const fiber = "fiber" in params ? params.fiber : node.fiber;
if (fiber) {
// resets the fibers on components if possible. This is important so that
// new renderings can be properly included in the initial one, if any.
let current = fiber;
do {
current.node.fiber = current;
current = current.parent;
} while (current);
fibersInError.set(fiber.root, error);
}
const handled = _handleError(node, error);
if (!handled) {
console.warn(`[Owl] Unhandled error. Destroying the root component`);
try {
node.app.destroy();
}
catch (e) {
console.error(e);
}
throw error;
}
}
function makeChildFiber(node, parent) { function makeChildFiber(node, parent) {
let current = node.fiber; let current = node.fiber;
if (current) { if (current) {
@@ -1850,9 +1853,8 @@ const NO_CALLBACK = () => {
}; };
const objectToString = Object.prototype.toString; const objectToString = Object.prototype.toString;
const objectHasOwnProperty = Object.prototype.hasOwnProperty; const objectHasOwnProperty = Object.prototype.hasOwnProperty;
// Use arrays because Array.includes is faster than Set.has for small arrays const SUPPORTED_RAW_TYPES = new Set(["Object", "Array", "Set", "Map", "WeakMap"]);
const SUPPORTED_RAW_TYPES = ["Object", "Array", "Set", "Map", "WeakMap"]; const COLLECTION_RAWTYPES = new Set(["Set", "Map", "WeakMap"]);
const COLLECTION_RAW_TYPES = ["Set", "Map", "WeakMap"];
/** /**
* extract "RawType" from strings like "[object RawType]" => this lets us ignore * extract "RawType" from strings like "[object RawType]" => this lets us ignore
* many native objects such as Promise (whose toString is [object Promise]) * many native objects such as Promise (whose toString is [object Promise])
@@ -1875,7 +1877,7 @@ function canBeMadeReactive(value) {
if (typeof value !== "object") { if (typeof value !== "object") {
return false; return false;
} }
return SUPPORTED_RAW_TYPES.includes(rawType(value)); return SUPPORTED_RAW_TYPES.has(rawType(value));
} }
/** /**
* Creates a reactive from the given object/callback if possible and returns it, * Creates a reactive from the given object/callback if possible and returns it,
@@ -2045,7 +2047,7 @@ function reactive(target, callback = NO_CALLBACK) {
const reactivesForTarget = reactiveCache.get(target); const reactivesForTarget = reactiveCache.get(target);
if (!reactivesForTarget.has(callback)) { if (!reactivesForTarget.has(callback)) {
const targetRawType = rawType(target); const targetRawType = rawType(target);
const handler = COLLECTION_RAW_TYPES.includes(targetRawType) const handler = COLLECTION_RAWTYPES.has(targetRawType)
? collectionsProxyHandler(target, callback, targetRawType) ? collectionsProxyHandler(target, callback, targetRawType)
: basicProxyHandler(callback); : basicProxyHandler(callback);
const proxy = new Proxy(target, handler); const proxy = new Proxy(target, handler);
@@ -2074,7 +2076,7 @@ function basicProxyHandler(callback) {
set(target, key, value, receiver) { set(target, key, value, receiver) {
const hadKey = objectHasOwnProperty.call(target, key); const hadKey = objectHasOwnProperty.call(target, key);
const originalValue = Reflect.get(target, key, receiver); const originalValue = Reflect.get(target, key, receiver);
const ret = Reflect.set(target, key, toRaw(value), receiver); const ret = Reflect.set(target, key, value, receiver);
if (!hadKey && objectHasOwnProperty.call(target, key)) { if (!hadKey && objectHasOwnProperty.call(target, key)) {
notifyReactives(target, KEYCHANGES); notifyReactives(target, KEYCHANGES);
} }
@@ -2178,7 +2180,7 @@ function delegateAndNotify(setterName, getterName, target) {
if (hadKey !== hasKey) { if (hadKey !== hasKey) {
notifyReactives(target, KEYCHANGES); notifyReactives(target, KEYCHANGES);
} }
if (originalValue !== target[getterName](key)) { if (originalValue !== value) {
notifyReactives(target, key); notifyReactives(target, key);
} }
return ret; return ret;
@@ -2999,13 +3001,15 @@ function prepareList(collection) {
keys = [...collection.keys()]; keys = [...collection.keys()];
values = [...collection.values()]; values = [...collection.values()];
} }
else if (Symbol.iterator in Object(collection)) {
keys = [...collection];
values = keys;
}
else if (collection && typeof collection === "object") { else if (collection && typeof collection === "object") {
values = Object.values(collection); if (Symbol.iterator in collection) {
keys = Object.keys(collection); keys = [...collection];
values = keys;
}
else {
values = Object.keys(collection);
keys = Object.values(collection);
}
} }
else { else {
throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`); throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`);
@@ -3160,14 +3164,8 @@ const helpers = {
makeRefWrapper, makeRefWrapper,
}; };
/** const bdom = { text, createBlock, list, multi, html, toggler, comment };
* Parses an XML string into an XML document, throwing errors on parser errors function parseXML$1(xml) {
* 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 parser = new DOMParser();
const doc = parser.parseFromString(xml, "text/xml"); const doc = parser.parseFromString(xml, "text/xml");
if (doc.getElementsByTagName("parsererror").length) { if (doc.getElementsByTagName("parsererror").length) {
@@ -3194,9 +3192,7 @@ function parseXML(xml) {
throw new OwlError(msg); throw new OwlError(msg);
} }
return doc; return doc;
} }
const bdom = { text, createBlock, list, multi, html, toggler, comment };
class TemplateSet { class TemplateSet {
constructor(config = {}) { constructor(config = {}) {
this.rawTemplates = Object.create(globalTemplates); this.rawTemplates = Object.create(globalTemplates);
@@ -3206,26 +3202,14 @@ class TemplateSet {
this.translateFn = config.translateFn; this.translateFn = config.translateFn;
this.translatableAttributes = config.translatableAttributes; this.translatableAttributes = config.translatableAttributes;
if (config.templates) { if (config.templates) {
if (config.templates instanceof Document || typeof config.templates === "string") { this.addTemplates(config.templates);
this.addTemplates(config.templates);
}
else {
for (const name in config.templates) {
this.addTemplate(name, config.templates[name]);
}
}
} }
this.getRawTemplate = config.getTemplate;
} }
static registerTemplate(name, fn) { static registerTemplate(name, fn) {
globalTemplates[name] = fn; globalTemplates[name] = fn;
} }
addTemplate(name, template) { addTemplate(name, template) {
if (name in this.rawTemplates) { if (name in this.rawTemplates) {
// this check can be expensive, just silently ignore double definitions outside dev mode
if (!this.dev) {
return;
}
const rawTemplate = this.rawTemplates[name]; const rawTemplate = this.rawTemplates[name];
const currentAsString = typeof rawTemplate === "string" const currentAsString = typeof rawTemplate === "string"
? rawTemplate ? rawTemplate
@@ -3245,16 +3229,15 @@ class TemplateSet {
// empty string // empty string
return; return;
} }
xml = xml instanceof Document ? xml : parseXML(xml); xml = xml instanceof Document ? xml : parseXML$1(xml);
for (const template of xml.querySelectorAll("[t-name]")) { for (const template of xml.querySelectorAll("[t-name]")) {
const name = template.getAttribute("t-name"); const name = template.getAttribute("t-name");
this.addTemplate(name, template); this.addTemplate(name, template);
} }
} }
getTemplate(name) { getTemplate(name) {
var _a;
if (!(name in this.templates)) { if (!(name in this.templates)) {
const rawTemplate = ((_a = this.getRawTemplate) === null || _a === void 0 ? void 0 : _a.call(this, name)) || this.rawTemplates[name]; const rawTemplate = this.rawTemplates[name];
if (rawTemplate === undefined) { if (rawTemplate === undefined) {
let extraInfo = ""; let extraInfo = "";
try { try {
@@ -3870,7 +3853,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) { if (!hasRoot && !ctx.preventRoot) {
this.target.hasRoot = true; this.target.hasRoot = true;
block.isRoot = true; block.isRoot = true;
} }
@@ -3893,7 +3876,7 @@ class CodeGenerator {
if (ctx.tKeyExpr) { if (ctx.tKeyExpr) {
blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`; blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`;
} }
if (block.isRoot) { if (block.isRoot && !ctx.preventRoot) {
if (this.target.on) { if (this.target.on) {
blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on); blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on);
} }
@@ -4069,6 +4052,11 @@ 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")) {
@@ -4184,10 +4172,7 @@ 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 nameSpace = ast.ns || ctx.nameSpace; const dom = xmlDoc.createElement(ast.tag);
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);
@@ -4229,7 +4214,7 @@ class CodeGenerator {
break; break;
} }
} }
this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx); this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
} }
} }
return block.varName; return block.varName;
@@ -4332,7 +4317,7 @@ class CodeGenerator {
break; break;
} }
} }
this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx); this.addLine(`let ${block.children.map((c) => c.varName)};`, 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(", ");
@@ -4361,18 +4346,18 @@ class CodeGenerator {
} }
this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`); this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`);
this.target.indentLevel++; this.target.indentLevel++;
this.addLine(`ctx[\`${ast.elem}\`] = ${keys}[${loopVar}];`); this.addLine(`ctx[\`${ast.elem}\`] = ${vals}[${loopVar}];`);
if (!ast.hasNoFirst) { if (!ast.hasNoFirst) {
this.addLine(`ctx[\`${ast.elem}_first\`] = ${loopVar} === 0;`); this.addLine(`ctx[\`${ast.elem}_first\`] = ${loopVar} === 0;`);
} }
if (!ast.hasNoLast) { if (!ast.hasNoLast) {
this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${keys}.length - 1;`); this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${vals}.length - 1;`);
} }
if (!ast.hasNoIndex) { if (!ast.hasNoIndex) {
this.addLine(`ctx[\`${ast.elem}_index\`] = ${loopVar};`); this.addLine(`ctx[\`${ast.elem}_index\`] = ${loopVar};`);
} }
if (!ast.hasNoValue) { if (!ast.hasNoValue) {
this.addLine(`ctx[\`${ast.elem}_value\`] = ${vals}[${loopVar}];`); this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
} }
this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar); this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar);
if (this.dev) { if (this.dev) {
@@ -4447,6 +4432,7 @@ 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);
@@ -4455,19 +4441,21 @@ class CodeGenerator {
} }
} }
if (isNewBlock) { if (isNewBlock) {
if (block.hasDynamicChildren && block.children.length) { if (block.hasDynamicChildren) {
const code = this.target.code; if (block.children.length) {
const children = block.children.slice(); const code = this.target.code;
let current = children.shift(); const children = block.children.slice();
for (let i = codeIdx; i < code.length; i++) { let current = children.shift();
if (code[i].trimStart().startsWith(`const ${current.varName} `)) { for (let i = codeIdx; i < code.length; i++) {
code[i] = code[i].replace(`const ${current.varName}`, current.varName); if (code[i].trimStart().startsWith(`const ${current.varName} `)) {
current = children.shift(); code[i] = code[i].replace(`const ${current.varName}`, current.varName);
if (!current) current = children.shift();
break; 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(", "); const args = block.children.map((c) => c.varName).join(", ");
this.insertBlock(`multi([${args}])`, block, ctx); this.insertBlock(`multi([${args}])`, block, ctx);
@@ -4481,23 +4469,24 @@ 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, { ctxVar }); const subCtx = createContext(ctx, { preventRoot: true, 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");
@@ -4505,6 +4494,7 @@ 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,
@@ -4513,6 +4503,7 @@ 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,
@@ -4834,7 +4825,7 @@ function parse(xml) {
} }
function _parse(xml) { function _parse(xml) {
normalizeXML(xml); normalizeXML(xml);
const ctx = { inPreTag: false }; const ctx = { inPreTag: false, inSVG: 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) {
@@ -4925,7 +4916,9 @@ function parseDOMNode(node, ctx) {
if (tagName === "pre") { if (tagName === "pre") {
ctx.inPreTag = true; ctx.inPreTag = true;
} }
let ns = !ctx.nameSpace && ROOT_SVG_TAGS.has(tagName) ? "http://www.w3.org/2000/svg" : null; const shouldAddSVGNS = ROOT_SVG_TAGS.has(tagName) && !ctx.inSVG;
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();
@@ -4964,9 +4957,9 @@ function parseDOMNode(node, ctx) {
const isSelect = tagName === "select"; const isSelect = tagName === "select";
const isCheckboxInput = isInput && typeAttr === "checkbox"; const isCheckboxInput = isInput && typeAttr === "checkbox";
const isRadioInput = isInput && typeAttr === "radio"; const isRadioInput = isInput && typeAttr === "radio";
const hasTrimMod = attr.includes(".trim"); const hasLazyMod = attr.includes(".lazy");
const hasLazyMod = hasTrimMod || attr.includes(".lazy");
const hasNumberMod = attr.includes(".number"); const hasNumberMod = attr.includes(".number");
const hasTrimMod = attr.includes(".trim");
const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input"; const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input";
model = { model = {
baseExpr, baseExpr,
@@ -4987,9 +4980,6 @@ 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}'`);
@@ -5002,9 +4992,6 @@ 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 */,
@@ -5297,14 +5284,14 @@ function parseComponent(node, ctx) {
// be ignored) // be ignored)
let el = slotNode.parentElement; let el = slotNode.parentElement;
let isInSubComponent = false; let isInSubComponent = false;
while (el && el !== clone) { while (el !== clone) {
if (el.hasAttribute("t-component") || el.tagName[0] === el.tagName[0].toUpperCase()) { if (el.hasAttribute("t-component") || el.tagName[0] === el.tagName[0].toUpperCase()) {
isInSubComponent = true; isInSubComponent = true;
break; break;
} }
el = el.parentElement; el = el.parentElement;
} }
if (isInSubComponent || !el) { if (isInSubComponent) {
continue; continue;
} }
slotNode.removeAttribute("t-set-slot"); slotNode.removeAttribute("t-set-slot");
@@ -5512,6 +5499,41 @@ function normalizeTEscTOut(el) {
function normalizeXML(el) { function normalizeXML(el) {
normalizeTIf(el); normalizeTIf(el);
normalizeTEscTOut(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 = {}) { function compile(template, options = {}) {
@@ -5525,20 +5547,11 @@ function compile(template, options = {}) {
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext }); const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
const code = codeGenerator.generateCode(); const code = codeGenerator.generateCode();
// template function // template function
try { return new Function("app, bdom, helpers", code);
return new Function("app, bdom, helpers", code);
}
catch (originalError) {
const { name } = options;
const nameStr = name ? `template "${name}"` : "anonymous template";
const err = new OwlError(`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`);
err.cause = originalError;
throw err;
}
} }
// 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.9"; const version = "2.2";
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Scheduler // Scheduler
@@ -5627,8 +5640,13 @@ const DEV_MSG = () => {
This is not suitable for production use. This is not suitable for production use.
See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration for more information.`; See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration for more information.`;
}; };
const apps = new Set(); window.__OWL_DEVTOOLS__ || (window.__OWL_DEVTOOLS__ = {
window.__OWL_DEVTOOLS__ || (window.__OWL_DEVTOOLS__ = { apps, Fiber, RootFiber, toRaw, reactive }); apps: new Set(),
Fiber: Fiber,
RootFiber: RootFiber,
toRaw: toRaw,
reactive: reactive,
});
class App extends TemplateSet { class App extends TemplateSet {
constructor(Root, config = {}) { constructor(Root, config = {}) {
super(config); super(config);
@@ -5636,7 +5654,7 @@ class App extends TemplateSet {
this.root = null; this.root = null;
this.name = config.name || ""; this.name = config.name || "";
this.Root = Root; this.Root = Root;
apps.add(this); window.__OWL_DEVTOOLS__.apps.add(this);
if (config.test) { if (config.test) {
this.dev = true; this.dev = true;
} }
@@ -5690,10 +5708,10 @@ class App extends TemplateSet {
} }
destroy() { destroy() {
if (this.root) { if (this.root) {
this.scheduler.flush();
this.root.destroy(); this.root.destroy();
this.scheduler.processTasks();
} }
apps.delete(this); window.__OWL_DEVTOOLS__.apps.delete(this);
} }
createComponent(name, isStatic, hasSlotsProp, hasDynamicPropList, propList) { createComponent(name, isStatic, hasSlotsProp, hasDynamicPropList, propList) {
const isDynamic = !isStatic; const isDynamic = !isStatic;
@@ -5768,7 +5786,6 @@ class App extends TemplateSet {
} }
} }
App.validateTarget = validateTarget; App.validateTarget = validateTarget;
App.apps = apps;
App.version = version; App.version = version;
async function mount(C, target, config = {}) { async function mount(C, target, config = {}) {
return new App(C, config).mount(target, config); return new App(C, config).mount(target, config);
@@ -5885,7 +5902,7 @@ function useChildSubEnv(envExtension) {
* *
* @template T * @template T
* @param {Effect<T>} effect the effect to run on component mount and/or patch * @param {Effect<T>} effect the effect to run on component mount and/or patch
* @param {()=>[...T]} [computeDependencies=()=>[NaN]] a callback to compute * @param {()=>T} [computeDependencies=()=>[NaN]] a callback to compute
* dependencies that will decide if the effect needs to be cleaned up and * dependencies that will decide if the effect needs to be cleaned up and
* run again. If the dependencies did not change, the effect will not run * run again. If the dependencies did not change, the effect will not run
* again. The default value returns an array containing only NaN because * again. The default value returns an array containing only NaN because
@@ -5967,6 +5984,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 = '2024-01-12T14:43:56.804Z'; __info__.date = '2023-07-19T13:22:24.480Z';
__info__.hash = '7b3e39b'; __info__.hash = '2e07799';
__info__.url = 'https://github.com/odoo/owl'; __info__.url = 'https://github.com/odoo/owl';
+5 -1
View File
@@ -43,6 +43,10 @@ class TaskList {
} }
} }
toggleTask(task) {
task.isCompleted = !task.isCompleted;
}
toggleTask(id) { toggleTask(id) {
const task = this.tasks.find(t => t.id === id); const task = this.tasks.find(t => t.id === id);
task.isCompleted = !task.isCompleted; task.isCompleted = !task.isCompleted;
@@ -57,7 +61,7 @@ class TaskList {
clearCompleted() { clearCompleted() {
const tasks = this.tasks.filter(t => t.isCompleted); const tasks = this.tasks.filter(t => t.isCompleted);
for (let task of tasks) { for (let task of tasks) {
this.deleteTask(task.id); this.deleteTask(task);
} }
} }
+4 -4
View File
@@ -1,6 +1,6 @@
{ {
"name": "@odoo/owl", "name": "@odoo/owl",
"version": "2.2.9", "version": "2.2.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -5890,9 +5890,9 @@
} }
}, },
"word-wrap": { "word-wrap": {
"version": "1.2.3", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
"dev": true "dev": true
}, },
"wrap-ansi": { "wrap-ansi": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@odoo/owl", "name": "@odoo/owl",
"version": "2.2.9", "version": "2.2.1",
"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",
-4
View File
@@ -1,4 +0,0 @@
// Custom error class that wraps error that happen in the owl lifecycle
export class OwlError extends Error {
cause?: any;
}
-38
View File
@@ -1,38 +0,0 @@
import { OwlError } from "./owl_error";
/**
* 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
*/
export function parseXML(xml: string): XMLDocument {
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;
}
+38 -30
View File
@@ -29,7 +29,7 @@ import {
Attrs, Attrs,
EventHandlers, EventHandlers,
} from "./parser"; } from "./parser";
import { OwlError } from "../common/owl_error"; import { OwlError } from "../runtime/error_handling";
type BlockType = "block" | "text" | "multi" | "list" | "html" | "comment"; type BlockType = "block" | "text" | "multi" | "list" | "html" | "comment";
const whitespaceRE = /\s+/g; const whitespaceRE = /\s+/g;
@@ -160,6 +160,7 @@ interface Context {
block: BlockDescription | null; block: BlockDescription | null;
index: number | string; index: number | string;
forceNewBlock: boolean; forceNewBlock: boolean;
preventRoot?: boolean;
isLast?: boolean; isLast?: boolean;
translate: boolean; translate: boolean;
tKeyExpr: string | null; tKeyExpr: string | null;
@@ -376,7 +377,7 @@ export class CodeGenerator {
): BlockDescription { ): BlockDescription {
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) { if (!hasRoot && !ctx.preventRoot) {
this.target.hasRoot = true; this.target.hasRoot = true;
block.isRoot = true; block.isRoot = true;
} }
@@ -402,7 +403,7 @@ export class CodeGenerator {
blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`; blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`;
} }
if (block.isRoot) { if (block.isRoot && !ctx.preventRoot) {
if (this.target.on) { if (this.target.on) {
blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on); blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on);
} }
@@ -585,6 +586,11 @@ export class CodeGenerator {
} }
// attributes // attributes
const attrs: Attrs = {}; const attrs: 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;
@@ -713,10 +719,7 @@ export class CodeGenerator {
attrs["block-ref"] = String(idx); attrs["block-ref"] = String(idx);
} }
const nameSpace = ast.ns || ctx.nameSpace; const dom = xmlDoc.createElement(ast.tag);
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);
@@ -758,7 +761,7 @@ export class CodeGenerator {
if (!current) break; if (!current) break;
} }
} }
this.addLine(`let ${block!.children.map((c) => c.varName).join(", ")};`, codeIdx); this.addLine(`let ${block!.children.map((c) => c.varName)};`, codeIdx);
} }
} }
return block!.varName; return block!.varName;
@@ -860,7 +863,7 @@ export class CodeGenerator {
if (!current) break; if (!current) break;
} }
} }
this.addLine(`let ${block!.children.map((c) => c.varName).join(", ")};`, codeIdx); this.addLine(`let ${block!.children.map((c) => c.varName)};`, codeIdx);
} }
// note: this part is duplicated from end of compilemulti: // note: this part is duplicated from end of compilemulti:
@@ -891,18 +894,18 @@ export class CodeGenerator {
} }
this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`); this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`);
this.target.indentLevel++; this.target.indentLevel++;
this.addLine(`ctx[\`${ast.elem}\`] = ${keys}[${loopVar}];`); this.addLine(`ctx[\`${ast.elem}\`] = ${vals}[${loopVar}];`);
if (!ast.hasNoFirst) { if (!ast.hasNoFirst) {
this.addLine(`ctx[\`${ast.elem}_first\`] = ${loopVar} === 0;`); this.addLine(`ctx[\`${ast.elem}_first\`] = ${loopVar} === 0;`);
} }
if (!ast.hasNoLast) { if (!ast.hasNoLast) {
this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${keys}.length - 1;`); this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${vals}.length - 1;`);
} }
if (!ast.hasNoIndex) { if (!ast.hasNoIndex) {
this.addLine(`ctx[\`${ast.elem}_index\`] = ${loopVar};`); this.addLine(`ctx[\`${ast.elem}_index\`] = ${loopVar};`);
} }
if (!ast.hasNoValue) { if (!ast.hasNoValue) {
this.addLine(`ctx[\`${ast.elem}_value\`] = ${vals}[${loopVar}];`); this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
} }
this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar); this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar);
if (this.dev) { if (this.dev) {
@@ -986,6 +989,7 @@ export 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);
@@ -994,18 +998,20 @@ export class CodeGenerator {
} }
} }
if (isNewBlock) { if (isNewBlock) {
if (block!.hasDynamicChildren && block!.children.length) { if (block!.hasDynamicChildren) {
const code = this.target.code; if (block!.children.length) {
const children = block!.children.slice(); const code = this.target.code;
let current = children.shift(); const children = block!.children.slice();
for (let i = codeIdx; i < code.length; i++) { let current = children.shift();
if (code[i].trimStart().startsWith(`const ${current!.varName} `)) { for (let i = codeIdx; i < code.length; i++) {
code[i] = code[i].replace(`const ${current!.varName}`, current!.varName); if (code[i].trimStart().startsWith(`const ${current!.varName} `)) {
current = children.shift(); code[i] = code[i].replace(`const ${current!.varName}`, current!.varName);
if (!current) break; 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(", "); const args = block!.children.map((c) => c.varName).join(", ");
@@ -1021,24 +1027,24 @@ export 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, { ctxVar }); const subCtx = createContext(ctx, { preventRoot: true, ctxVar });
const bl = this.compileMulti({ type: ASTType.Multi, content: ast.body }, subCtx); const bl = this.compileMulti({ type: ASTType.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");
@@ -1046,6 +1052,7 @@ export 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,
@@ -1053,6 +1060,7 @@ export 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,
+1 -12
View File
@@ -2,7 +2,6 @@ import type { TemplateSet } from "../runtime/template_set";
import type { BDom } from "../runtime/blockdom"; import type { BDom } from "../runtime/blockdom";
import { CodeGenerator, Config } from "./code_generator"; import { CodeGenerator, Config } from "./code_generator";
import { parse } from "./parser"; import { parse } from "./parser";
import { OwlError } from "../common/owl_error";
export type Template = (context: any, vnode: any, key?: string) => BDom; export type Template = (context: any, vnode: any, key?: string) => BDom;
@@ -28,15 +27,5 @@ export function compile(
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext }); const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
const code = codeGenerator.generateCode(); const code = codeGenerator.generateCode();
// template function // template function
try { return new Function("app, bdom, helpers", code) as TemplateFunction;
return new Function("app, bdom, helpers", code) as TemplateFunction;
} catch (originalError: any) {
const { name } = options;
const nameStr = name ? `template "${name}"` : "anonymous template";
const err = new OwlError(
`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`
);
err.cause = originalError;
throw err;
}
} }
+1 -1
View File
@@ -1,4 +1,4 @@
import { OwlError } from "../common/owl_error"; import { OwlError } from "../runtime/error_handling";
/** /**
* Owl QWeb Expression Parser * Owl QWeb Expression Parser
+47 -15
View File
@@ -1,5 +1,4 @@
import { OwlError } from "../common/owl_error"; import { OwlError } from "../runtime/error_handling";
import { parseXML } from "../common/utils";
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// AST Type definition // AST Type definition
@@ -214,14 +213,14 @@ export function parse(xml: string | Element): AST {
function _parse(xml: Element): AST { function _parse(xml: Element): AST {
normalizeXML(xml); normalizeXML(xml);
const ctx = { inPreTag: false }; const ctx = { inPreTag: false, inSVG: false };
return parseNode(xml, ctx) || { type: ASTType.Text, value: "" }; return parseNode(xml, ctx) || { type: ASTType.Text, value: "" };
} }
interface ParsingContext { interface ParsingContext {
tModelInfo?: TModelInfo | null; tModelInfo?: TModelInfo | null;
nameSpace?: string;
inPreTag: boolean; inPreTag: boolean;
inSVG: boolean;
} }
function parseNode(node: Node, ctx: ParsingContext): AST | null { function parseNode(node: Node, ctx: ParsingContext): AST | null {
@@ -324,8 +323,9 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
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");
@@ -367,9 +367,9 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
const isSelect = tagName === "select"; const isSelect = tagName === "select";
const isCheckboxInput = isInput && typeAttr === "checkbox"; const isCheckboxInput = isInput && typeAttr === "checkbox";
const isRadioInput = isInput && typeAttr === "radio"; const isRadioInput = isInput && typeAttr === "radio";
const hasTrimMod = attr.includes(".trim"); const hasLazyMod = attr.includes(".lazy");
const hasLazyMod = hasTrimMod || attr.includes(".lazy");
const hasNumberMod = attr.includes(".number"); const hasNumberMod = attr.includes(".number");
const hasTrimMod = attr.includes(".trim");
const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input"; const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input";
model = { model = {
@@ -389,8 +389,6 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
} }
} 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}'`);
@@ -403,9 +401,6 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
attrs[attr] = value; attrs[attr] = value;
} }
} }
if (ns) {
ctx.nameSpace = ns;
}
const children = parseChildren(node, ctx); const children = parseChildren(node, ctx);
return { return {
@@ -741,14 +736,14 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
// be ignored) // be ignored)
let el = slotNode.parentElement!; let el = slotNode.parentElement!;
let isInSubComponent = false; let isInSubComponent = false;
while (el && el !== clone) { while (el !== clone) {
if (el!.hasAttribute("t-component") || el!.tagName[0] === el!.tagName[0].toUpperCase()) { if (el!.hasAttribute("t-component") || el!.tagName[0] === el!.tagName[0].toUpperCase()) {
isInSubComponent = true; isInSubComponent = true;
break; break;
} }
el = el.parentElement!; el = el.parentElement!;
} }
if (isInSubComponent || !el) { if (isInSubComponent) {
continue; continue;
} }
@@ -973,3 +968,40 @@ function normalizeXML(el: Element) {
normalizeTIf(el); normalizeTIf(el);
normalizeTEscTOut(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: string): XMLDocument {
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;
}
+11 -9
View File
@@ -1,8 +1,7 @@
import { version } from "../version"; import { version } from "../version";
import { Component, ComponentConstructor, Props } from "./component"; import { Component, ComponentConstructor, Props } from "./component";
import { ComponentNode } from "./component_node"; import { ComponentNode } from "./component_node";
import { nodeErrorHandlers, handleError } from "./error_handling"; import { nodeErrorHandlers, OwlError, handleError } from "./error_handling";
import { OwlError } from "../common/owl_error";
import { Fiber, RootFiber, MountOptions } from "./fibers"; import { Fiber, RootFiber, MountOptions } from "./fibers";
import { Scheduler } from "./scheduler"; import { Scheduler } from "./scheduler";
import { validateProps } from "./template_helpers"; import { validateProps } from "./template_helpers";
@@ -35,8 +34,6 @@ This is not suitable for production use.
See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration for more information.`; See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration for more information.`;
}; };
const apps = new Set<App>();
declare global { declare global {
interface Window { interface Window {
__OWL_DEVTOOLS__: { __OWL_DEVTOOLS__: {
@@ -49,7 +46,13 @@ declare global {
} }
} }
window.__OWL_DEVTOOLS__ ||= { apps, Fiber, RootFiber, toRaw, reactive }; window.__OWL_DEVTOOLS__ ||= {
apps: new Set<App>(),
Fiber: Fiber,
RootFiber: RootFiber,
toRaw: toRaw,
reactive: reactive,
};
export class App< export class App<
T extends abstract new (...args: any) => any = any, T extends abstract new (...args: any) => any = any,
@@ -57,7 +60,6 @@ export class App<
E = any E = any
> extends TemplateSet { > extends TemplateSet {
static validateTarget = validateTarget; static validateTarget = validateTarget;
static apps = apps;
static version = version; static version = version;
name: string; name: string;
@@ -72,7 +74,7 @@ export class App<
super(config); super(config);
this.name = config.name || ""; this.name = config.name || "";
this.Root = Root; this.Root = Root;
apps.add(this); window.__OWL_DEVTOOLS__.apps.add(this);
if (config.test) { if (config.test) {
this.dev = true; this.dev = true;
} }
@@ -134,10 +136,10 @@ export class App<
destroy() { destroy() {
if (this.root) { if (this.root) {
this.scheduler.flush();
this.root.destroy(); this.root.destroy();
this.scheduler.processTasks();
} }
apps.delete(this); window.__OWL_DEVTOOLS__.apps.delete(this);
} }
createComponent<P extends Props>( createComponent<P extends Props>(
+7 -3
View File
@@ -1,4 +1,4 @@
import { OwlError } from "../../common/owl_error"; import { OwlError } from "../error_handling";
import { attrsSetter, attrsUpdater, createAttrUpdater, setClass, updateClass } from "./attributes"; import { attrsSetter, attrsUpdater, createAttrUpdater, setClass, updateClass } from "./attributes";
import { config } from "./config"; import { config } from "./config";
import { createEventHandler } from "./events"; import { createEventHandler } from "./events";
@@ -144,7 +144,12 @@ function buildTree(
info.push({ type: "child", idx: index }); info.push({ type: "child", idx: index });
el = document.createTextNode(""); el = document.createTextNode("");
} }
currentNS ||= (node as Element).namespaceURI; const attrs = (node as Element).attributes;
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)
@@ -160,7 +165,6 @@ function buildTree(
const fragment = document.createElement("template").content; const fragment = document.createElement("template").content;
fragment.appendChild(el); fragment.appendChild(el);
} }
const attrs = (node as Element).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;
+1 -1
View File
@@ -23,7 +23,7 @@ export type ComponentConstructor<P extends Props = any, E = any> = (new (
export class Component<Props = any, Env = any> { export class Component<Props = any, Env = any> {
static template: string = ""; static template: string = "";
static props?: Schema; static props?: any;
static defaultProps?: any; static defaultProps?: any;
props: Props; props: Props;
+1 -2
View File
@@ -1,8 +1,7 @@
import type { App, Env } from "./app"; import type { App, Env } from "./app";
import { BDom, VNode } from "./blockdom"; import { BDom, VNode } from "./blockdom";
import { Component, ComponentConstructor, Props } from "./component"; import { Component, ComponentConstructor, Props } from "./component";
import { fibersInError } from "./error_handling"; import { fibersInError, OwlError } from "./error_handling";
import { OwlError } from "../common/owl_error";
import { Fiber, makeChildFiber, makeRootFiber, MountFiber, MountOptions } from "./fibers"; import { Fiber, makeChildFiber, makeRootFiber, MountFiber, MountOptions } from "./fibers";
import { clearReactivesForCallback, getSubscriptions, reactive, targets } from "./reactivity"; import { clearReactivesForCallback, getSubscriptions, reactive, targets } from "./reactivity";
import { STATUS } from "./status"; import { STATUS } from "./status";
+5 -1
View File
@@ -1,7 +1,11 @@
import { OwlError } from "../common/owl_error";
import type { ComponentNode } from "./component_node"; import type { ComponentNode } from "./component_node";
import type { Fiber } from "./fibers"; import type { Fiber } from "./fibers";
// Custom error class that wraps error that happen in the owl lifecycle
export class OwlError extends Error {
cause?: any;
}
// Maps fibers to thrown errors // Maps fibers to thrown errors
export const fibersInError: WeakMap<Fiber, any> = new WeakMap(); export const fibersInError: WeakMap<Fiber, any> = new WeakMap();
export const nodeErrorHandlers: WeakMap<ComponentNode, ((error: any) => void)[]> = new WeakMap(); export const nodeErrorHandlers: WeakMap<ComponentNode, ((error: any) => void)[]> = new WeakMap();
+1 -1
View File
@@ -1,6 +1,6 @@
import { filterOutModifiersFromData } from "./blockdom/config"; import { filterOutModifiersFromData } from "./blockdom/config";
import { STATUS } from "./status"; import { STATUS } from "./status";
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => { export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => {
const { data: _data, modifiers } = filterOutModifiersFromData(data); const { data: _data, modifiers } = filterOutModifiersFromData(data);
+1 -2
View File
@@ -1,7 +1,6 @@
import { BDom, mount } from "./blockdom"; import { BDom, mount } from "./blockdom";
import type { ComponentNode } from "./component_node"; import type { ComponentNode } from "./component_node";
import { fibersInError } from "./error_handling"; import { fibersInError, OwlError } from "./error_handling";
import { OwlError } from "../common/owl_error";
import { STATUS } from "./status"; import { STATUS } from "./status";
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber { export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
+5 -5
View File
@@ -59,7 +59,7 @@ export function useChildSubEnv(envExtension: Env) {
// useEffect // useEffect
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
type EffectDeps<T extends unknown[]> = T | (T extends [...infer H, never] ? EffectDeps<H> : never); type EffectDeps<T extends any[]> = T | (T extends [...infer H, never] ? EffectDeps<H> : never);
/** /**
* @template T * @template T
@@ -67,7 +67,7 @@ type EffectDeps<T extends unknown[]> = T | (T extends [...infer H, never] ? Effe
* @returns {void|(()=>void)} a cleanup function that reverses the side * @returns {void|(()=>void)} a cleanup function that reverses the side
* effects of the effect callback. * effects of the effect callback.
*/ */
type Effect<T extends unknown[]> = (...dependencies: EffectDeps<T>) => void | (() => void); type Effect<T extends [...T]> = (...dependencies: EffectDeps<T>) => void | (() => void);
/** /**
* This hook will run a callback when a component is mounted and patched, and * This hook will run a callback when a component is mounted and patched, and
@@ -76,15 +76,15 @@ type Effect<T extends unknown[]> = (...dependencies: EffectDeps<T>) => void | ((
* *
* @template T * @template T
* @param {Effect<T>} effect the effect to run on component mount and/or patch * @param {Effect<T>} effect the effect to run on component mount and/or patch
* @param {()=>[...T]} [computeDependencies=()=>[NaN]] a callback to compute * @param {()=>T} [computeDependencies=()=>[NaN]] a callback to compute
* dependencies that will decide if the effect needs to be cleaned up and * dependencies that will decide if the effect needs to be cleaned up and
* run again. If the dependencies did not change, the effect will not run * run again. If the dependencies did not change, the effect will not run
* again. The default value returns an array containing only NaN because * again. The default value returns an array containing only NaN because
* NaN !== NaN, which will cause the effect to rerun on every patch. * NaN !== NaN, which will cause the effect to rerun on every patch.
*/ */
export function useEffect<T extends unknown[]>( export function useEffect<T extends [...T]>(
effect: Effect<T>, effect: Effect<T>,
computeDependencies: () => [...T] = () => [NaN] as never computeDependencies: () => T = () => [NaN] as never
) { ) {
let cleanup: (() => void) | void; let cleanup: (() => void) | void;
let dependencies: T; let dependencies: T;
+1 -1
View File
@@ -55,7 +55,7 @@ export {
onError, onError,
} from "./lifecycle_hooks"; } from "./lifecycle_hooks";
export { validate, validateType } from "./validation"; export { validate, validateType } from "./validation";
export { OwlError } from "../common/owl_error"; export { OwlError } from "./error_handling";
export const __info__ = { export const __info__ = {
version: App.version, version: App.version,
+1 -2
View File
@@ -1,6 +1,5 @@
import { getCurrent } from "./component_node"; import { getCurrent } from "./component_node";
import { nodeErrorHandlers } from "./error_handling"; import { nodeErrorHandlers, OwlError } from "./error_handling";
import { OwlError } from "../common/owl_error";
const TIMEOUT = Symbol("timeout"); const TIMEOUT = Symbol("timeout");
function wrapError(fn: (...args: any[]) => any, hookName: string) { function wrapError(fn: (...args: any[]) => any, hookName: string) {
+2 -2
View File
@@ -1,7 +1,7 @@
import { onMounted, onWillUnmount } from "./lifecycle_hooks"; import { onMounted, onWillUnmount } from "./lifecycle_hooks";
import { BDom, text, VNode } from "./blockdom"; import { BDom, text, VNode } from "./blockdom";
import { Component } from "./component"; import { Component } from "./component";
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
const VText: any = text("").constructor; const VText: any = text("").constructor;
@@ -65,7 +65,7 @@ export class Portal extends Component {
type: String, type: String,
}, },
slots: true, slots: true,
} as const; };
setup() { setup() {
const node: any = this.__owl__; const node: any = this.__owl__;
+7 -47
View File
@@ -1,5 +1,5 @@
import type { Callback } from "./utils"; import type { Callback } from "./utils";
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
// Special key to subscribe to, to be notified of key creation/deletion // Special key to subscribe to, to be notified of key creation/deletion
const KEYCHANGES = Symbol("Key changes"); const KEYCHANGES = Symbol("Key changes");
@@ -20,9 +20,8 @@ type CollectionRawType = "Set" | "Map" | "WeakMap";
const objectToString = Object.prototype.toString; const objectToString = Object.prototype.toString;
const objectHasOwnProperty = Object.prototype.hasOwnProperty; const objectHasOwnProperty = Object.prototype.hasOwnProperty;
// Use arrays because Array.includes is faster than Set.has for small arrays const SUPPORTED_RAW_TYPES = new Set(["Object", "Array", "Set", "Map", "WeakMap"]);
const SUPPORTED_RAW_TYPES = ["Object", "Array", "Set", "Map", "WeakMap"]; const COLLECTION_RAWTYPES = new Set(["Set", "Map", "WeakMap"]);
const COLLECTION_RAW_TYPES = ["Set", "Map", "WeakMap"];
/** /**
* extract "RawType" from strings like "[object RawType]" => this lets us ignore * extract "RawType" from strings like "[object RawType]" => this lets us ignore
@@ -46,7 +45,7 @@ function canBeMadeReactive(value: any): boolean {
if (typeof value !== "object") { if (typeof value !== "object") {
return false; return false;
} }
return SUPPORTED_RAW_TYPES.includes(rawType(value)); return SUPPORTED_RAW_TYPES.has(rawType(value));
} }
/** /**
* Creates a reactive from the given object/callback if possible and returns it, * Creates a reactive from the given object/callback if possible and returns it,
@@ -221,36 +220,12 @@ export function reactive<T extends Target>(target: T, callback: Callback = NO_CA
const reactivesForTarget = reactiveCache.get(target)!; const reactivesForTarget = reactiveCache.get(target)!;
if (!reactivesForTarget.has(callback)) { if (!reactivesForTarget.has(callback)) {
const targetRawType = rawType(target); const targetRawType = rawType(target);
const handler = COLLECTION_RAW_TYPES.includes(targetRawType) const handler = COLLECTION_RAWTYPES.has(targetRawType)
? collectionsProxyHandler(target as Collection, callback, targetRawType as CollectionRawType) ? collectionsProxyHandler(target as Collection, callback, targetRawType as CollectionRawType)
: basicProxyHandler<T>(callback); : basicProxyHandler<T>(callback);
const proxy = new Proxy(target, handler as ProxyHandler<T>) as Reactive<T>; const proxy = new Proxy(target, handler as ProxyHandler<T>) as Reactive<T>;
reactivesForTarget.set(callback, proxy); reactivesForTarget.set(callback, proxy);
targets.set(proxy, target); targets.set(proxy, target);
// FIXME: this probably slows down reactive creation significantly, we probably don't want to do
// it all the time. Maybe should be a separate function.
const derivedDescriptors = Object.entries(Object.getOwnPropertyDescriptors(target)).filter(
([k, descriptor]) => {
if (toRaw(descriptor.value)?.[IS_DERIVED_DESCRIPTOR]) {
delete target[k as keyof typeof target]; // prevent circular call in effect below
return true;
}
return false;
}
);
for (const [
key,
{
value: [deps, compute],
},
] of derivedDescriptors) {
effect(
(proxy, deps) => {
proxy[key as keyof typeof proxy] = Reflect.apply(compute, proxy, deps);
},
[proxy, deps]
);
}
} }
return reactivesForTarget.get(callback) as Reactive<T>; return reactivesForTarget.get(callback) as Reactive<T>;
} }
@@ -274,7 +249,7 @@ function basicProxyHandler<T extends Target>(callback: Callback): ProxyHandler<T
set(target, key, value, receiver) { set(target, key, value, receiver) {
const hadKey = objectHasOwnProperty.call(target, key); const hadKey = objectHasOwnProperty.call(target, key);
const originalValue = Reflect.get(target, key, receiver); const originalValue = Reflect.get(target, key, receiver);
const ret = Reflect.set(target, key, toRaw(value), receiver); const ret = Reflect.set(target, key, value, receiver);
if (!hadKey && objectHasOwnProperty.call(target, key)) { if (!hadKey && objectHasOwnProperty.call(target, key)) {
notifyReactives(target, KEYCHANGES); notifyReactives(target, KEYCHANGES);
} }
@@ -393,7 +368,7 @@ function delegateAndNotify(
if (hadKey !== hasKey) { if (hadKey !== hasKey) {
notifyReactives(target, KEYCHANGES); notifyReactives(target, KEYCHANGES);
} }
if (originalValue !== target[getterName](key)) { if (originalValue !== value) {
notifyReactives(target, key); notifyReactives(target, key);
} }
return ret; return ret;
@@ -487,18 +462,3 @@ function collectionsProxyHandler<T extends Collection>(
}, },
}) as ProxyHandler<T>; }) as ProxyHandler<T>;
} }
const IS_DERIVED_DESCRIPTOR = Symbol("is derived descriptor");
export function derived<T extends Reactive<any>[], U>(deps: T, compute: (...args: T) => U) {
return Object.assign([deps, compute], { [IS_DERIVED_DESCRIPTOR]: true }) as unknown as U;
}
/**
* Creates a side-effect that runs based on the content of reactive objects.
*/
export function effect<T extends object[]>(cb: (...args: [...T]) => void, deps: [...T]) {
const reactiveDeps = reactive(deps, () => {
cb(...reactiveDeps);
});
cb(...reactiveDeps);
}
+8 -6
View File
@@ -4,7 +4,7 @@ import { html } from "./blockdom/index";
import { isOptional, validateSchema } from "./validation"; import { isOptional, validateSchema } from "./validation";
import type { ComponentConstructor } from "./component"; import type { ComponentConstructor } from "./component";
import { markRaw } from "./reactivity"; import { markRaw } from "./reactivity";
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
import type { ComponentNode } from "./component_node"; import type { ComponentNode } from "./component_node";
const ObjectCreate = Object.create; const ObjectCreate = Object.create;
@@ -70,12 +70,14 @@ function prepareList(collection: unknown): [unknown[], unknown[], number, undefi
} else if (collection instanceof Map) { } else if (collection instanceof Map) {
keys = [...collection.keys()]; keys = [...collection.keys()];
values = [...collection.values()]; values = [...collection.values()];
} else if (Symbol.iterator in Object(collection)) {
keys = [...(<Iterable<unknown>>collection)];
values = keys;
} else if (collection && typeof collection === "object") { } else if (collection && typeof collection === "object") {
values = Object.values(collection); if (Symbol.iterator in collection) {
keys = Object.keys(collection); keys = [...(<Iterable<unknown>>collection)];
values = keys;
} else {
values = Object.keys(collection);
keys = Object.values(collection);
}
} else { } else {
throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`); throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`);
} }
+34 -18
View File
@@ -3,17 +3,45 @@ import { comment, createBlock, html, list, multi, text, toggler } from "./blockd
import { getCurrent } from "./component_node"; import { getCurrent } from "./component_node";
import { Portal, portalTemplate } from "./portal"; import { Portal, portalTemplate } from "./portal";
import { helpers } from "./template_helpers"; import { helpers } from "./template_helpers";
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
import { parseXML } from "../common/utils";
const bdom = { text, createBlock, list, multi, html, toggler, comment }; const bdom = { text, createBlock, list, multi, html, toggler, comment };
function parseXML(xml: string): Document {
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;
}
export interface TemplateSetConfig { export interface TemplateSetConfig {
dev?: boolean; dev?: boolean;
translatableAttributes?: string[]; translatableAttributes?: string[];
translateFn?: (s: string) => string; translateFn?: (s: string) => string;
templates?: string | Document | Record<string, string>; templates?: string | Document;
getTemplate?: (s: string) => Element | Function | string | void;
} }
export class TemplateSet { export class TemplateSet {
@@ -23,7 +51,6 @@ export class TemplateSet {
dev: boolean; dev: boolean;
rawTemplates: typeof globalTemplates = Object.create(globalTemplates); rawTemplates: typeof globalTemplates = Object.create(globalTemplates);
templates: { [name: string]: Template } = {}; templates: { [name: string]: Template } = {};
getRawTemplate?: (s: string) => Element | Function | string | void;
translateFn?: (s: string) => string; translateFn?: (s: string) => string;
translatableAttributes?: string[]; translatableAttributes?: string[];
Portal = Portal; Portal = Portal;
@@ -33,23 +60,12 @@ export class TemplateSet {
this.translateFn = config.translateFn; this.translateFn = config.translateFn;
this.translatableAttributes = config.translatableAttributes; this.translatableAttributes = config.translatableAttributes;
if (config.templates) { if (config.templates) {
if (config.templates instanceof Document || typeof config.templates === "string") { this.addTemplates(config.templates);
this.addTemplates(config.templates);
} else {
for (const name in config.templates) {
this.addTemplate(name, config.templates[name]);
}
}
} }
this.getRawTemplate = config.getTemplate;
} }
addTemplate(name: string, template: string | Element) { addTemplate(name: string, template: string | Element) {
if (name in this.rawTemplates) { if (name in this.rawTemplates) {
// this check can be expensive, just silently ignore double definitions outside dev mode
if (!this.dev) {
return;
}
const rawTemplate = this.rawTemplates[name]; const rawTemplate = this.rawTemplates[name];
const currentAsString = const currentAsString =
typeof rawTemplate === "string" typeof rawTemplate === "string"
@@ -80,7 +96,7 @@ export class TemplateSet {
getTemplate(name: string): Template { getTemplate(name: string): Template {
if (!(name in this.templates)) { if (!(name in this.templates)) {
const rawTemplate = this.getRawTemplate?.(name) || this.rawTemplates[name]; const rawTemplate = this.rawTemplates[name];
if (rawTemplate === undefined) { if (rawTemplate === undefined) {
let extraInfo = ""; let extraInfo = "";
try { try {
+1 -1
View File
@@ -1,4 +1,4 @@
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
export type Callback = () => void; export type Callback = () => void;
/** /**
+1 -2
View File
@@ -1,4 +1,4 @@
import { OwlError } from "../common/owl_error"; import { OwlError } from "./error_handling";
import { toRaw } from "./reactivity"; import { toRaw } from "./reactivity";
type BaseType = type BaseType =
@@ -8,7 +8,6 @@ type BaseType =
| typeof Date | typeof Date
| typeof Object | typeof Object
| typeof Array | typeof Array
| typeof Function
| true | true
| "*"; | "*";
+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.9"; export const version = "2.2.1";
+1 -1
View File
@@ -353,7 +353,7 @@ exports[`Reactivity: useState useless atoms should be deleted 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Object.keys(ctx['state']));; const [k_block2, v_block2, l_block2, c_block2] = prepareList(Object.keys(ctx['state']));;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`id\`] = k_block2[i1]; ctx[\`id\`] = v_block2[i1];
const key1 = ctx['id']; const key1 = ctx['id'];
c_block2[i1] = withKey(comp1({id: ctx['id']}, key + \`__1__\${key1}\`, node, this, null), key1); c_block2[i1] = withKey(comp1({id: ctx['id']}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
-41
View File
@@ -15,34 +15,6 @@ exports[`app App supports env with getters/setters 1`] = `
}" }"
`; `;
exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately on destroy 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
const comp1 = app.createComponent(\`B\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") {
let b2, b3;
b2 = text(\`A\`);
if (ctx['state'].value) {
b3 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2, b3]);
}
}"
`;
exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately on destroy 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`B\`);
}
}"
`;
exports[`app can configure an app with props 1`] = ` exports[`app can configure an app with props 1`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
@@ -57,19 +29,6 @@ exports[`app can configure an app with props 1`] = `
}" }"
`; `;
exports[`app can load templates from an object name-string 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div class=\\"hello\\">hello</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`app can mount app in an iframe 1`] = ` exports[`app can mount app in an iframe 1`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
+2 -92
View File
@@ -1,15 +1,6 @@
import { App, Component, mount, onWillStart, useState, xml } from "../../src"; import { App, Component, mount, xml } from "../../src";
import { status } from "../../src/runtime/status"; import { status } from "../../src/runtime/status";
import { import { makeTestFixture, snapshotEverything, nextTick, elem } from "../helpers";
makeTestFixture,
snapshotEverything,
nextTick,
elem,
useLogLifecycle,
makeDeferred,
nextMicroTick,
steps,
} from "../helpers";
let fixture: HTMLElement; let fixture: HTMLElement;
@@ -103,85 +94,4 @@ describe("app", () => {
expect(iframeDoc.contains(div)).toBe(false); expect(iframeDoc.contains(div)).toBe(false);
expect(status(comp)).toBe("destroyed"); expect(status(comp)).toBe("destroyed");
}); });
test("app: clear scheduler tasks and destroy cancelled nodes immediately on destroy", async () => {
let def = makeDeferred();
class B extends Component {
static template = xml`B`;
setup() {
useLogLifecycle();
onWillStart(() => def);
}
}
class A extends Component {
static template = xml`A<t t-if="state.value"><B/></t>`;
static components = { B };
state = useState({ value: false });
setup() {
useLogLifecycle();
}
}
const app = new App(A);
const comp = await app.mount(fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:setup",
"A:willStart",
"A:willRender",
"A:rendered",
"A:mounted",
]
`);
comp.state.value = true;
await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:willRender",
"B:setup",
"B:willStart",
"A:rendered",
]
`);
// rerender to force the instantiation of a new B component (and cancelling the first)
comp.render();
await nextMicroTick();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:willRender",
"B:setup",
"B:willStart",
"A:rendered",
]
`);
app.destroy();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:willUnmount",
"B:willDestroy",
"A:willDestroy",
"B:willDestroy",
]
`);
});
test("can load templates from an object name-string", async () => {
const templates = {
hello: `<div class="hello">hello</div>`,
world: `<div>world</div>`,
};
class SomeComponent extends Component {
static template = "hello";
}
const app = new App(SomeComponent, { templates });
await app.mount(fixture);
expect(fixture.querySelector(".hello")).toBeDefined();
// Only the "hello" template is used, so the "world" template is not yet loaded
expect(Object.keys(app.templates)).toEqual(["hello"]);
expect(Object.keys(app.rawTemplates)).toEqual(["hello", "world"]);
});
}); });
+2 -4
View File
@@ -244,14 +244,12 @@ describe("misc", () => {
}); });
test("namespace is not propagated to siblings", () => { test("namespace is not propagated to siblings", () => {
const block = createBlock(`<div><svg xmlns="someNameSpace"><g/></svg><div></div></div>`); const block = createBlock(`<div><svg block-ns="someNameSpace"><g/></svg><div></div></div>`);
const fixture = makeTestFixture(); const fixture = makeTestFixture();
mount(block(), fixture); mount(block(), fixture);
expect(fixture.innerHTML).toBe( expect(fixture.innerHTML).toBe("<div><svg><g></g></svg><div></div></div>");
'<div><svg xmlns="someNameSpace"><g></g></svg><div></div></div>'
);
expect(fixture.querySelector("svg")!.namespaceURI).toBe("someNameSpace"); expect(fixture.querySelector("svg")!.namespaceURI).toBe("someNameSpace");
expect(fixture.querySelector("g")!.namespaceURI).toBe("someNameSpace"); expect(fixture.querySelector("g")!.namespaceURI).toBe("someNameSpace");
const allDivs = fixture.querySelectorAll("div"); const allDivs = fixture.querySelectorAll("div");
+7 -7
View File
@@ -30,22 +30,22 @@ describe("namespace", () => {
expect(fixture.firstElementChild!.namespaceURI).toBe(XHTML_URI); expect(fixture.firstElementChild!.namespaceURI).toBe(XHTML_URI);
}); });
test("namespace can be changed with xmlns", () => { test("namespace can be changed with block-ns", () => {
const block = createBlock(`<tag xmlns="${SVG_URI}"/>`); const block = createBlock(`<tag block-ns="${SVG_URI}"/>`);
const tree = block(); const tree = block();
mount(tree, fixture); mount(tree, fixture);
expect(fixture.innerHTML).toBe(`<tag xmlns="${SVG_URI}"></tag>`); expect(fixture.innerHTML).toBe("<tag></tag>");
expect(fixture.firstElementChild!.namespaceURI).toBe(SVG_URI); expect(fixture.firstElementChild!.namespaceURI).toBe(SVG_URI);
}); });
test("namespace is kept for children", () => { test("namespace is kept for children", () => {
const block = createBlock( const block = createBlock(
`<parent xmlns="${SVG_URI}"><child><subchild/></child><child/></parent>` `<parent block-ns="${SVG_URI}"><child><subchild/></child><child/></parent>`
); );
const tree = block(); const tree = block();
mount(tree, fixture); mount(tree, fixture);
expect(fixture.innerHTML).toBe( expect(fixture.innerHTML).toBe(
`<parent xmlns="${SVG_URI}"><child><subchild></subchild></child><child></child></parent>` "<parent><child><subchild></subchild></child><child></child></parent>"
); );
const parent = fixture.firstElementChild!; const parent = fixture.firstElementChild!;
const child1 = parent.firstElementChild!; const child1 = parent.firstElementChild!;
@@ -58,10 +58,10 @@ describe("namespace", () => {
}); });
test("various namespaces in same block", () => { test("various namespaces in same block", () => {
const block = createBlock(`<none><one xmlns="one"/><two xmlns="two"/></none>`); const block = createBlock(`<none><one block-ns="one"/><two block-ns="two"/></none>`);
const tree = block(); const tree = block();
mount(tree, fixture); mount(tree, fixture);
expect(fixture.innerHTML).toBe('<none><one xmlns="one"></one><two xmlns="two"></two></none>'); expect(fixture.innerHTML).toBe("<none><one></one><two></two></none>");
const none = fixture.firstElementChild!; const none = fixture.firstElementChild!;
const one = none.firstElementChild!; const one = none.firstElementChild!;
const two = one.nextElementSibling!; const two = one.nextElementSibling!;
@@ -34,7 +34,7 @@ exports[`comments properly handle comments between t-if/t-else 1`] = `
let block3 = createBlock(\`<span>owl</span>\`); let block3 = createBlock(\`<span>owl</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (true) { if (true) {
b2 = block2(); b2 = block2();
} else { } else {
@@ -72,7 +72,7 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['someval']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(['someval']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`action\`] = k_block2[i1]; ctx[\`action\`] = v_block2[i1];
ctx[\`action_index\`] = i1; ctx[\`action_index\`] = i1;
const key1 = ctx['action_index']; const key1 = ctx['action_index'];
const v1 = ctx['activate']; const v1 = ctx['activate'];
@@ -142,7 +142,7 @@ exports[`t-on handler is bound to proper owner, part 2 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`value\`] = k_block1[i1]; ctx[\`value\`] = v_block1[i1];
const key1 = ctx['value']; const key1 = ctx['value'];
let hdlr1 = [ctx['add'], ctx]; let hdlr1 = [ctx['add'], ctx];
c_block1[i1] = withKey(block2([hdlr1]), key1); c_block1[i1] = withKey(block2([hdlr1]), key1);
@@ -189,11 +189,11 @@ exports[`t-on handler is bound to proper owner, part 4 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`value\`] = k_block1[i1]; ctx[\`value\`] = v_block1[i1];
ctx[\`value_first\`] = i1 === 0; ctx[\`value_first\`] = i1 === 0;
ctx[\`value_last\`] = i1 === k_block1.length - 1; ctx[\`value_last\`] = i1 === v_block1.length - 1;
ctx[\`value_index\`] = i1; ctx[\`value_index\`] = i1;
ctx[\`value_value\`] = v_block1[i1]; ctx[\`value_value\`] = k_block1[i1];
const key1 = ctx['value']; const key1 = ctx['value'];
c_block1[i1] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`), key1); c_block1[i1] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
} }
@@ -348,7 +348,7 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-f
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`project\`] = k_block2[i1]; ctx[\`project\`] = v_block2[i1];
const key1 = ctx['project']; const key1 = ctx['project'];
const v1 = ctx['onEdit']; const v1 = ctx['onEdit'];
const v2 = ctx['project']; const v2 = ctx['project'];
+21 -21
View File
@@ -18,7 +18,7 @@ exports[`misc complex template 1`] = `
let block13 = createBlock(\`<i class=\\"fa fa-fw fa-clock-o\\" title=\\"This commit is the head of a base branch\\"/>\`); let block13 = createBlock(\`<i class=\\"fa fa-fw fa-clock-o\\" title=\\"This commit is the head of a base branch\\"/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4, b6, b8; let b2,b3,b4,b6,b8;
let attr1 = \`batch_tile \${ctx['options'].more?'more':'nomore'}\`; let attr1 = \`batch_tile \${ctx['options'].more?'more':'nomore'}\`;
let attr2 = \`card bg-\${ctx['klass']}-light\`; let attr2 = \`card bg-\${ctx['klass']}-light\`;
let attr3 = \`/runbot/batch/\${ctx['batch'].id}\`; let attr3 = \`/runbot/batch/\${ctx['batch'].id}\`;
@@ -33,7 +33,7 @@ exports[`misc complex template 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(_slot=>_slot.build_id.id&&!_slot.trigger_id.manual&&(ctx['options'].trigger_display[_slot.trigger_id.id])));; const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(_slot=>_slot.build_id.id&&!_slot.trigger_id.manual&&(ctx['options'].trigger_display[_slot.trigger_id.id])));;
for (let i1 = 0; i1 < l_block4; i1++) { for (let i1 = 0; i1 < l_block4; i1++) {
ctx[\`slot\`] = k_block4[i1]; ctx[\`slot\`] = v_block4[i1];
const key1 = ctx['slot'].id; const key1 = ctx['slot'].id;
c_block4[i1] = withKey(comp1({class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, this, null), key1); c_block4[i1] = withKey(comp1({class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
@@ -42,7 +42,7 @@ exports[`misc complex template 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block6, v_block6, l_block6, c_block6] = prepareList([1,2,3,4]);; const [k_block6, v_block6, l_block6, c_block6] = prepareList([1,2,3,4]);;
for (let i1 = 0; i1 < l_block6; i1++) { for (let i1 = 0; i1 < l_block6; i1++) {
ctx[\`x\`] = k_block6[i1]; ctx[\`x\`] = v_block6[i1];
const key1 = ctx['x']; const key1 = ctx['x'];
c_block6[i1] = withKey(block7(), key1); c_block6[i1] = withKey(block7(), key1);
} }
@@ -51,9 +51,9 @@ exports[`misc complex template 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block8, v_block8, l_block8, c_block8] = prepareList(ctx['commit_links']);; const [k_block8, v_block8, l_block8, c_block8] = prepareList(ctx['commit_links']);;
for (let i1 = 0; i1 < l_block8; i1++) { for (let i1 = 0; i1 < l_block8; i1++) {
ctx[\`commit_link\`] = k_block8[i1]; ctx[\`commit_link\`] = v_block8[i1];
const key1 = ctx['commit_link'].id; const key1 = ctx['commit_link'].id;
let b10, b11, b12, b13; let b10,b11,b12,b13;
let attr5 = \`/runbot/commit/\${ctx['commit_link'].commit_id}\`; let attr5 = \`/runbot/commit/\${ctx['commit_link'].commit_id}\`;
let attr6 = \`badge badge-light batch_commit match_type_\${ctx['commit_link'].match_type}\`; let attr6 = \`badge badge-light batch_commit match_type_\${ctx['commit_link'].match_type}\`;
if (ctx['commit_link'].match_type=='new') { if (ctx['commit_link'].match_type=='new') {
@@ -99,11 +99,11 @@ exports[`misc global 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([4,5,6]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList([4,5,6]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`value\`] = k_block2[i1]; ctx[\`value\`] = v_block2[i1];
ctx[\`value_first\`] = i1 === 0; ctx[\`value_first\`] = i1 === 0;
ctx[\`value_last\`] = i1 === k_block2.length - 1; ctx[\`value_last\`] = i1 === v_block2.length - 1;
ctx[\`value_index\`] = i1; ctx[\`value_index\`] = i1;
ctx[\`value_value\`] = v_block2[i1]; ctx[\`value_value\`] = k_block2[i1];
const key1 = ctx['value']; const key1 = ctx['value'];
let txt1 = ctx['value']; let txt1 = ctx['value'];
const b4 = block4([txt1]); const b4 = block4([txt1]);
@@ -112,16 +112,16 @@ exports[`misc global 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
setContextValue(ctx, \\"foo\\", 'aaa'); setContextValue(ctx, \\"foo\\", 'aaa');
const b7 = callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`); const b6 = callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`);
ctx = ctx.__proto__; ctx = ctx.__proto__;
const b8 = callTemplate_2.call(this, ctx, node, key + \`__2__\${key1}\`); const b7 = callTemplate_2.call(this, ctx, node, key + \`__2__\${key1}\`);
setContextValue(ctx, \\"foo\\", 'bbb'); setContextValue(ctx, \\"foo\\", 'bbb');
const b9 = callTemplate_3.call(this, ctx, node, key + \`__3__\${key1}\`); const b8 = callTemplate_3.call(this, ctx, node, key + \`__3__\${key1}\`);
const b6 = multi([b7, b8, b9]); const b5 = multi([b6, b7, b8]);
ctx[zero] = b6; ctx[zero] = b5;
const b5 = callTemplate_4.call(this, ctx, node, key + \`__4__\${key1}\`); const b9 = callTemplate_4.call(this, ctx, node, key + \`__4__\${key1}\`);
ctx = ctx.__proto__; ctx = ctx.__proto__;
c_block2[i1] = withKey(multi([b4, b5]), key1); c_block2[i1] = withKey(multi([b4, b9]), key1);
} }
ctx = ctx.__proto__; ctx = ctx.__proto__;
const b2 = list(c_block2); const b2 = list(c_block2);
@@ -217,13 +217,13 @@ exports[`misc other complex template 1`] = `
let block25 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block25 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b4, b14, b17, b22, b23, b24, b25; let b2,b4,b14,b17,b22,b23,b24,b25;
let attr1 = \`/runbot/\${ctx['project'].slug}\`; let attr1 = \`/runbot/\${ctx['project'].slug}\`;
let txt1 = ctx['project'].name; let txt1 = ctx['project'].name;
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`project\`] = k_block2[i1]; ctx[\`project\`] = v_block2[i1];
const key1 = ctx['project'].id; const key1 = ctx['project'].id;
let hdlr1 = [ctx['selectProject'](ctx['project']), ctx]; let hdlr1 = [ctx['selectProject'](ctx['project']), ctx];
let txt2 = ctx['project'].name; let txt2 = ctx['project'].name;
@@ -232,12 +232,12 @@ exports[`misc other complex template 1`] = `
ctx = ctx.__proto__; ctx = ctx.__proto__;
b2 = list(c_block2); b2 = list(c_block2);
if (ctx['user']) { if (ctx['user']) {
let b5, b6; let b5,b6;
if (ctx['user'].public) { if (ctx['user'].public) {
let attr2 = \`/web/login?redirect=/\`; let attr2 = \`/web/login?redirect=/\`;
b5 = block5([attr2]); b5 = block5([attr2]);
} else { } else {
let b7, b10, b13; let b7,b10,b13;
if (ctx['nb_assigned_errors']&&ctx['nb_assigned_errors']>0) { if (ctx['nb_assigned_errors']&&ctx['nb_assigned_errors']>0) {
let attr3 = \`You have \${ctx['nb_assigned_errors']} random bug assigned\`; let attr3 = \`You have \${ctx['nb_assigned_errors']} random bug assigned\`;
let txt3 = ctx['nb_assigned_errors']; let txt3 = ctx['nb_assigned_errors'];
@@ -263,7 +263,7 @@ exports[`misc other complex template 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block15, v_block15, l_block15, c_block15] = prepareList(ctx['categories']);; const [k_block15, v_block15, l_block15, c_block15] = prepareList(ctx['categories']);;
for (let i1 = 0; i1 < l_block15; i1++) { for (let i1 = 0; i1 < l_block15; i1++) {
ctx[\`category\`] = k_block15[i1]; ctx[\`category\`] = v_block15[i1];
const key1 = ctx['category'].id; const key1 = ctx['category'].id;
let attr6 = ctx['category'].id; let attr6 = ctx['category'].id;
let prop1 = new Boolean(ctx['category'].id==ctx['options'].active_category_id); let prop1 = new Boolean(ctx['category'].id==ctx['options'].active_category_id);
@@ -284,7 +284,7 @@ exports[`misc other complex template 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block18, v_block18, l_block18, c_block18] = prepareList(ctx['triggers']);; const [k_block18, v_block18, l_block18, c_block18] = prepareList(ctx['triggers']);;
for (let i1 = 0; i1 < l_block18; i1++) { for (let i1 = 0; i1 < l_block18; i1++) {
ctx[\`trigger\`] = k_block18[i1]; ctx[\`trigger\`] = v_block18[i1];
const key1 = ctx['trigger'].id; const key1 = ctx['trigger'].id;
let b20; let b20;
if (!ctx['trigger'].manual&&ctx['trigger'].project_id===ctx['project'].id&&ctx['trigger'].category_id===ctx['options'].active_category_id) { if (!ctx['trigger'].manual&&ctx['trigger'].project_id===ctx['project'].id&&ctx['trigger'].category_id===ctx['options'].active_category_id) {
@@ -12,7 +12,7 @@ exports[`memory t-foreach does not leak stuff in global scope 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
const key1 = ctx['item_index']; const key1 = ctx['item_index'];
c_block2[i1] = withKey(text(ctx['item']), key1); c_block2[i1] = withKey(text(ctx['item']), key1);
+11 -11
View File
@@ -5,7 +5,7 @@ exports[`properly support svg add proper namespace to g tags 1`] = `
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<g xmlns=\\"http://www.w3.org/2000/svg\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/> </g>\`); let block1 = createBlock(\`<g block-ns=\\"http://www.w3.org/2000/svg\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/> </g>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
return block1(); return block1();
@@ -18,7 +18,7 @@ exports[`properly support svg add proper namespace to svg 1`] = `
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"100px\\" height=\\"90px\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/> </svg>\`); let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\" width=\\"100px\\" height=\\"90px\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/> </svg>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
return block1(); return block1();
@@ -31,7 +31,7 @@ exports[`properly support svg namespace to g tags not added if already in svg na
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><g/></svg>\`); let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><g/></svg>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
return block1(); return block1();
@@ -44,7 +44,7 @@ exports[`properly support svg namespace to svg tags added even if already in svg
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><svg/></svg>\`); let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><svg/></svg>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
return block1(); return block1();
@@ -58,8 +58,8 @@ exports[`properly support svg svg creates new block if it is within html -- 2 1`
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block2 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><polygon fill=\\"#000000\\" points=\\"0 0 4 4 8 0\\" transform=\\"translate(5 7)\\"/><block-child-0 xmlns=\\"\\"/></svg>\`); let block2 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><polygon fill=\\"#000000\\" points=\\"0 0 4 4 8 0\\" transform=\\"translate(5 7)\\"/><block-child-0/></svg>\`);
let block3 = createBlock(\`<path xmlns=\\"http://www.w3.org/2000/svg\\"/>\`); let block3 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b3; let b3;
@@ -78,7 +78,7 @@ exports[`properly support svg svg creates new block if it is within html 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block2 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><polygon fill=\\"#000000\\" points=\\"0 0 4 4 8 0\\" transform=\\"translate(5 7)\\"/></svg>\`); let block2 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><polygon fill=\\"#000000\\" points=\\"0 0 4 4 8 0\\" transform=\\"translate(5 7)\\"/></svg>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
const b2 = block2(); const b2 = block2();
@@ -93,7 +93,7 @@ exports[`properly support svg svg namespace added to sub templates if root tag i
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
const callTemplate_1 = app.getTemplate(\`path\`); const callTemplate_1 = app.getTemplate(\`path\`);
let block1 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><block-child-0 xmlns=\\"\\"/></svg>\`); let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
@@ -107,7 +107,7 @@ exports[`properly support svg svg namespace added to sub templates if root tag i
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<path xmlns=\\"http://www.w3.org/2000/svg\\"/>\`); let block1 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
return block1(); return block1();
@@ -120,8 +120,8 @@ exports[`properly support svg svg namespace added to sub-blocks 1`] = `
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><block-child-0 xmlns=\\"\\"/></svg>\`); let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
let block2 = createBlock(\`<path xmlns=\\"http://www.w3.org/2000/svg\\"/>\`); let block2 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2; let b2;
+75 -203
View File
@@ -61,19 +61,19 @@ exports[`t-call (template calling) call with several sub nodes on same line 1`]
const callTemplate_1 = app.getTemplate(\`sub\`); const callTemplate_1 = app.getTemplate(\`sub\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block4 = createBlock(\`<span>hey</span>\`); let block3 = createBlock(\`<span>hey</span>\`);
let block6 = createBlock(\`<span>yay</span>\`); let block5 = createBlock(\`<span>yay</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b4 = block4(); const b3 = block3();
const b5 = text(\` \`); const b4 = text(\` \`);
const b6 = block6(); const b5 = block5();
const b3 = multi([b4, b5, b6]); const b2 = multi([b3, b4, b5]);
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b6 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b6]);
} }
}" }"
`; `;
@@ -101,19 +101,19 @@ exports[`t-call (template calling) cascading t-call t-out='0' 1`] = `
const callTemplate_1 = app.getTemplate(\`subTemplate\`); const callTemplate_1 = app.getTemplate(\`subTemplate\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block4 = createBlock(\`<span>hey</span>\`); let block3 = createBlock(\`<span>hey</span>\`);
let block6 = createBlock(\`<span>yay</span>\`); let block5 = createBlock(\`<span>yay</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b4 = block4(); const b3 = block3();
const b5 = text(\` \`); const b4 = text(\` \`);
const b6 = block6(); const b5 = block5();
const b3 = multi([b4, b5, b6]); const b2 = multi([b3, b4, b5]);
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b6 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b6]);
} }
}" }"
`; `;
@@ -126,17 +126,17 @@ exports[`t-call (template calling) cascading t-call t-out='0' 2`] = `
const callTemplate_1 = app.getTemplate(\`subSubTemplate\`); const callTemplate_1 = app.getTemplate(\`subSubTemplate\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block4 = createBlock(\`<span>cascade 0</span>\`); let block3 = createBlock(\`<span>cascade 0</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b4 = block4(); const b3 = block3();
const b5 = ctx[zero]; const b4 = ctx[zero];
const b3 = multi([b4, b5]); const b2 = multi([b3, b4]);
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b5 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b5]);
} }
}" }"
`; `;
@@ -149,17 +149,17 @@ exports[`t-call (template calling) cascading t-call t-out='0' 3`] = `
const callTemplate_1 = app.getTemplate(\`finalTemplate\`); const callTemplate_1 = app.getTemplate(\`finalTemplate\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block4 = createBlock(\`<span>cascade 1</span>\`); let block3 = createBlock(\`<span>cascade 1</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b4 = block4(); const b3 = block3();
const b5 = ctx[zero]; const b4 = ctx[zero];
const b3 = multi([b4, b5]); const b2 = multi([b3, b4]);
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b5 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b5]);
} }
}" }"
`; `;
@@ -186,17 +186,17 @@ exports[`t-call (template calling) cascading t-call t-out='0', without external
let { isBoundary, zero } = helpers; let { isBoundary, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`subTemplate\`); const callTemplate_1 = app.getTemplate(\`subTemplate\`);
let block3 = createBlock(\`<span>hey</span>\`); let block2 = createBlock(\`<span>hey</span>\`);
let block5 = createBlock(\`<span>yay</span>\`); let block4 = createBlock(\`<span>yay</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b2 = block2();
const b4 = text(\` \`); const b3 = text(\` \`);
const b5 = block5(); const b4 = block4();
const b2 = multi([b3, b4, b5]); const b1 = multi([b2, b3, b4]);
ctx[zero] = b2; ctx[zero] = b1;
return callTemplate_1.call(this, ctx, node, key + \`__1\`); return callTemplate_1.call(this, ctx, node, key + \`__1\`);
} }
}" }"
@@ -209,15 +209,15 @@ exports[`t-call (template calling) cascading t-call t-out='0', without external
let { isBoundary, zero } = helpers; let { isBoundary, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`subSubTemplate\`); const callTemplate_1 = app.getTemplate(\`subSubTemplate\`);
let block3 = createBlock(\`<span>cascade 0</span>\`); let block2 = createBlock(\`<span>cascade 0</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b2 = block2();
const b4 = ctx[zero]; const b3 = ctx[zero];
const b2 = multi([b3, b4]); const b1 = multi([b2, b3]);
ctx[zero] = b2; ctx[zero] = b1;
return callTemplate_1.call(this, ctx, node, key + \`__1\`); return callTemplate_1.call(this, ctx, node, key + \`__1\`);
} }
}" }"
@@ -230,15 +230,15 @@ exports[`t-call (template calling) cascading t-call t-out='0', without external
let { isBoundary, zero } = helpers; let { isBoundary, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`finalTemplate\`); const callTemplate_1 = app.getTemplate(\`finalTemplate\`);
let block3 = createBlock(\`<span>cascade 1</span>\`); let block2 = createBlock(\`<span>cascade 1</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b2 = block2();
const b4 = ctx[zero]; const b3 = ctx[zero];
const b2 = multi([b3, b4]); const b1 = multi([b2, b3]);
ctx[zero] = b2; ctx[zero] = b1;
return callTemplate_1.call(this, ctx, node, key + \`__1\`); return callTemplate_1.call(this, ctx, node, key + \`__1\`);
} }
}" }"
@@ -342,15 +342,15 @@ exports[`t-call (template calling) nested t-calls with magic variable 0 1`] = `
const callTemplate_1 = app.getTemplate(\`grandchild\`); const callTemplate_1 = app.getTemplate(\`grandchild\`);
const callTemplate_2 = app.getTemplate(\`child\`); const callTemplate_2 = app.getTemplate(\`child\`);
let block3 = createBlock(\`<p>Some content...</p>\`); let block1 = createBlock(\`<p>Some content...</p>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b1 = block1();
ctx[zero] = b3; ctx[zero] = b1;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
ctx = ctx.__proto__; ctx = ctx.__proto__;
ctx[zero] = b2; ctx[zero] = b2;
@@ -440,11 +440,11 @@ exports[`t-call (template calling) recursive template, part 2 2`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`subtree\`] = k_block2[i1]; ctx[\`subtree\`] = v_block2[i1];
ctx[\`subtree_first\`] = i1 === 0; ctx[\`subtree_first\`] = i1 === 0;
ctx[\`subtree_last\`] = i1 === k_block2.length - 1; ctx[\`subtree_last\`] = i1 === v_block2.length - 1;
ctx[\`subtree_index\`] = i1; ctx[\`subtree_index\`] = i1;
ctx[\`subtree_value\`] = v_block2[i1]; ctx[\`subtree_value\`] = k_block2[i1];
const key1 = ctx['subtree_index']; const key1 = ctx['subtree_index'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
@@ -495,11 +495,11 @@ exports[`t-call (template calling) recursive template, part 3 2`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`subtree\`] = k_block2[i1]; ctx[\`subtree\`] = v_block2[i1];
ctx[\`subtree_first\`] = i1 === 0; ctx[\`subtree_first\`] = i1 === 0;
ctx[\`subtree_last\`] = i1 === k_block2.length - 1; ctx[\`subtree_last\`] = i1 === v_block2.length - 1;
ctx[\`subtree_index\`] = i1; ctx[\`subtree_index\`] = i1;
ctx[\`subtree_value\`] = v_block2[i1]; ctx[\`subtree_value\`] = k_block2[i1];
const key1 = ctx['subtree_index']; const key1 = ctx['subtree_index'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
@@ -553,11 +553,11 @@ exports[`t-call (template calling) recursive template, part 4: with t-set recurs
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`subtree\`] = k_block2[i1]; ctx[\`subtree\`] = v_block2[i1];
ctx[\`subtree_first\`] = i1 === 0; ctx[\`subtree_first\`] = i1 === 0;
ctx[\`subtree_last\`] = i1 === k_block2.length - 1; ctx[\`subtree_last\`] = i1 === v_block2.length - 1;
ctx[\`subtree_index\`] = i1; ctx[\`subtree_index\`] = i1;
ctx[\`subtree_value\`] = v_block2[i1]; ctx[\`subtree_value\`] = k_block2[i1];
const key1 = ctx['subtree_index']; const key1 = ctx['subtree_index'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
@@ -571,134 +571,6 @@ exports[`t-call (template calling) recursive template, part 4: with t-set recurs
}" }"
`; `;
exports[`t-call (template calling) root t-call with body: t-foreach 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { isBoundary, prepareList, withKey, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`subTemplate\`);
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1]);;
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`i\`] = k_block2[i1];
const key1 = ctx['i'];
c_block2[i1] = withKey(text(\`1\`), key1);
}
ctx = ctx.__proto__;
const b2 = list(c_block2);
ctx[zero] = b2;
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-foreach 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`sub\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-if false 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { isBoundary, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`subTemplate\`);
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
let b3;
if (false) {
b3 = text(\`zero\`);
}
const b2 = multi([b3]);
ctx[zero] = b2;
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-if false 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`sub\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-if true 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { isBoundary, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`subTemplate\`);
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
let b3;
if (true) {
b3 = text(\`zero\`);
}
const b2 = multi([b3]);
ctx[zero] = b2;
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-if true 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`sub\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-out with default 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { isBoundary, safeOutput, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`subTemplate\`);
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
const b2 = safeOutput(ctx['nothing']);
ctx[zero] = b2;
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
}
}"
`;
exports[`t-call (template calling) root t-call with body: t-out with default 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`sub\`);
}
}"
`;
exports[`t-call (template calling) scoped parameters 1`] = ` exports[`t-call (template calling) scoped parameters 1`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
@@ -833,13 +705,13 @@ exports[`t-call (template calling) t-call with body content as root of a templat
let { isBoundary, zero } = helpers; let { isBoundary, zero } = helpers;
const callTemplate_1 = app.getTemplate(\`antony\`); const callTemplate_1 = app.getTemplate(\`antony\`);
let block2 = createBlock(\`<p>antony</p>\`); let block1 = createBlock(\`<p>antony</p>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b2 = block2(); const b1 = block1();
ctx[zero] = b2; ctx[zero] = b1;
return callTemplate_1.call(this, ctx, node, key + \`__1\`); return callTemplate_1.call(this, ctx, node, key + \`__1\`);
} }
}" }"
@@ -941,11 +813,11 @@ exports[`t-call (template calling) t-call with t-set inside and outside 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`v\`] = k_block2[i1]; ctx[\`v\`] = v_block2[i1];
ctx[\`v_first\`] = i1 === 0; ctx[\`v_first\`] = i1 === 0;
ctx[\`v_last\`] = i1 === k_block2.length - 1; ctx[\`v_last\`] = i1 === v_block2.length - 1;
ctx[\`v_index\`] = i1; ctx[\`v_index\`] = i1;
ctx[\`v_value\`] = v_block2[i1]; ctx[\`v_value\`] = k_block2[i1];
const key1 = ctx['v_index']; const key1 = ctx['v_index'];
setContextValue(ctx, \\"val\\", ctx['v'].val); setContextValue(ctx, \\"val\\", ctx['v'].val);
ctx = Object.create(ctx); ctx = Object.create(ctx);
@@ -1008,11 +880,11 @@ exports[`t-call (template calling) t-call with t-set inside and outside. 2 2`] =
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`v\`] = k_block2[i1]; ctx[\`v\`] = v_block2[i1];
ctx[\`v_first\`] = i1 === 0; ctx[\`v_first\`] = i1 === 0;
ctx[\`v_last\`] = i1 === k_block2.length - 1; ctx[\`v_last\`] = i1 === v_block2.length - 1;
ctx[\`v_index\`] = i1; ctx[\`v_index\`] = i1;
ctx[\`v_value\`] = v_block2[i1]; ctx[\`v_value\`] = k_block2[i1];
const key1 = ctx['v_index']; const key1 = ctx['v_index'];
setContextValue(ctx, \\"val\\", ctx['v'].val); setContextValue(ctx, \\"val\\", ctx['v'].val);
ctx = Object.create(ctx); ctx = Object.create(ctx);
@@ -1056,7 +928,7 @@ exports[`t-call (template calling) t-call, conditional and t-set in t-call body
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1 ctx[isBoundary] = 1
let b2, b3; let b2,b3;
setContextValue(ctx, \\"v1\\", 'elif'); setContextValue(ctx, \\"v1\\", 'elif');
if (ctx['v1']==='if') { if (ctx['v1']==='if') {
b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
@@ -1203,8 +1075,8 @@ exports[`t-call (template calling) with unused body 1`] = `
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b2 = text(\`WHEEE\`); const b1 = text(\`WHEEE\`);
ctx[zero] = b2; ctx[zero] = b1;
return callTemplate_1.call(this, ctx, node, key + \`__1\`); return callTemplate_1.call(this, ctx, node, key + \`__1\`);
} }
}" }"
@@ -1264,8 +1136,8 @@ exports[`t-call (template calling) with used body 1`] = `
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b2 = text(\`ok\`); const b1 = text(\`ok\`);
ctx[zero] = b2; ctx[zero] = b1;
return callTemplate_1.call(this, ctx, node, key + \`__1\`); return callTemplate_1.call(this, ctx, node, key + \`__1\`);
} }
}" }"
@@ -180,15 +180,15 @@ exports[`t-esc t-esc=0 is escaped 1`] = `
const callTemplate_1 = app.getTemplate(\`sub\`); const callTemplate_1 = app.getTemplate(\`sub\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block3 = createBlock(\`<p>escaped</p>\`); let block2 = createBlock(\`<p>escaped</p>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b2 = block2();
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b3]);
} }
}" }"
`; `;
@@ -12,7 +12,7 @@ exports[`t-foreach does not pollute the rendering context 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList([1]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
c_block2[i1] = withKey(text(ctx['item']), key1); c_block2[i1] = withKey(text(ctx['item']), key1);
} }
@@ -35,7 +35,7 @@ exports[`t-foreach iterate on items (on a element node) 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1,2]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList([1,2]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
let txt1 = ctx['item']; let txt1 = ctx['item'];
c_block2[i1] = withKey(block3([txt1]), key1); c_block2[i1] = withKey(block3([txt1]), key1);
@@ -58,9 +58,9 @@ exports[`t-foreach iterate on items 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block2[i1]; ctx[\`item_value\`] = k_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
const b4 = text(\` [\`); const b4 = text(\` [\`);
const b5 = text(ctx['item_index']); const b5 = text(ctx['item_index']);
@@ -87,9 +87,9 @@ exports[`t-foreach iterate, Map param 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['value']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['value']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block1[i1]; ctx[\`item_value\`] = k_block1[i1];
const key1 = ctx['item_index']; const key1 = ctx['item_index'];
const b3 = text(\` [\`); const b3 = text(\` [\`);
const b4 = text(ctx['item_index']); const b4 = text(ctx['item_index']);
@@ -115,9 +115,9 @@ exports[`t-foreach iterate, Set param 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['value']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['value']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block1[i1]; ctx[\`item_value\`] = k_block1[i1];
const key1 = ctx['item_index']; const key1 = ctx['item_index'];
const b3 = text(\` [\`); const b3 = text(\` [\`);
const b4 = text(ctx['item_index']); const b4 = text(ctx['item_index']);
@@ -145,9 +145,9 @@ exports[`t-foreach iterate, dict param 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['value']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['value']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block2[i1]; ctx[\`item_value\`] = k_block2[i1];
const key1 = ctx['item_index']; const key1 = ctx['item_index'];
const b4 = text(\` [\`); const b4 = text(\` [\`);
const b5 = text(ctx['item_index']); const b5 = text(ctx['item_index']);
@@ -174,9 +174,9 @@ exports[`t-foreach iterate, generator param 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['gen']());; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['gen']());;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block1[i1]; ctx[\`item_value\`] = k_block1[i1];
const key1 = ctx['item_index']; const key1 = ctx['item_index'];
const b3 = text(\` [\`); const b3 = text(\` [\`);
const b4 = text(ctx['item_index']); const b4 = text(ctx['item_index']);
@@ -202,9 +202,9 @@ exports[`t-foreach iterate, iterable param 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['map'].values());; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['map'].values());;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block1[i1]; ctx[\`item_value\`] = k_block1[i1];
const key1 = ctx['item_index']; const key1 = ctx['item_index'];
const b3 = text(\` [\`); const b3 = text(\` [\`);
const b4 = text(ctx['item_index']); const b4 = text(ctx['item_index']);
@@ -232,12 +232,12 @@ exports[`t-foreach iterate, position 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(5));; const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(5));;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`elem\`] = k_block2[i1]; ctx[\`elem\`] = v_block2[i1];
ctx[\`elem_first\`] = i1 === 0; ctx[\`elem_first\`] = i1 === 0;
ctx[\`elem_last\`] = i1 === k_block2.length - 1; ctx[\`elem_last\`] = i1 === v_block2.length - 1;
ctx[\`elem_index\`] = i1; ctx[\`elem_index\`] = i1;
const key1 = ctx['elem']; const key1 = ctx['elem'];
let b4, b5, b6, b7, b8, b9; let b4,b5,b6,b7,b8,b9;
b4 = text(\` -\`); b4 = text(\` -\`);
if (ctx['elem_first']) { if (ctx['elem_first']) {
b5 = text(\` first\`); b5 = text(\` first\`);
@@ -256,34 +256,6 @@ exports[`t-foreach iterate, position 1`] = `
}" }"
`; `;
exports[`t-foreach iterate, string param 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { prepareList, withKey } = helpers;
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList('abc');;
for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1];
ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block1[i1];
const key1 = ctx['item_index'];
const b3 = text(\` [\`);
const b4 = text(ctx['item_index']);
const b5 = text(\`: \`);
const b6 = text(ctx['item']);
const b7 = text(\` \`);
const b8 = text(ctx['item_value']);
const b9 = text(\`] \`);
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7, b8, b9]), key1);
}
return list(c_block1);
}
}"
`;
exports[`t-foreach simple iteration (in a node) 1`] = ` exports[`t-foreach simple iteration (in a node) 1`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
@@ -296,7 +268,7 @@ exports[`t-foreach simple iteration (in a node) 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);; const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
c_block2[i1] = withKey(text(ctx['item']), key1); c_block2[i1] = withKey(text(ctx['item']), key1);
} }
@@ -316,7 +288,7 @@ exports[`t-foreach simple iteration 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
c_block1[i1] = withKey(text(ctx['item']), key1); c_block1[i1] = withKey(text(ctx['item']), key1);
} }
@@ -338,7 +310,7 @@ exports[`t-foreach simple iteration with two nodes inside 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
let txt1 = ctx['item']; let txt1 = ctx['item'];
const b3 = block3([txt1]); const b3 = block3([txt1]);
@@ -367,20 +339,20 @@ exports[`t-foreach t-call with body in t-foreach in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`a\`] = k_block2[i1]; ctx[\`a\`] = v_block2[i1];
ctx[\`a_first\`] = i1 === 0; ctx[\`a_first\`] = i1 === 0;
ctx[\`a_last\`] = i1 === k_block2.length - 1; ctx[\`a_last\`] = i1 === v_block2.length - 1;
ctx[\`a_index\`] = i1; ctx[\`a_index\`] = i1;
ctx[\`a_value\`] = v_block2[i1]; ctx[\`a_value\`] = k_block2[i1];
const key1 = ctx['a']; const key1 = ctx['a'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);; const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);;
for (let i2 = 0; i2 < l_block4; i2++) { for (let i2 = 0; i2 < l_block4; i2++) {
ctx[\`b\`] = k_block4[i2]; ctx[\`b\`] = v_block4[i2];
ctx[\`b_first\`] = i2 === 0; ctx[\`b_first\`] = i2 === 0;
ctx[\`b_last\`] = i2 === k_block4.length - 1; ctx[\`b_last\`] = i2 === v_block4.length - 1;
ctx[\`b_index\`] = i2; ctx[\`b_index\`] = i2;
ctx[\`b_value\`] = v_block4[i2]; ctx[\`b_value\`] = k_block4[i2];
const key2 = ctx['b']; const key2 = ctx['b'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
@@ -436,20 +408,20 @@ exports[`t-foreach t-call without body in t-foreach in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`a\`] = k_block2[i1]; ctx[\`a\`] = v_block2[i1];
ctx[\`a_first\`] = i1 === 0; ctx[\`a_first\`] = i1 === 0;
ctx[\`a_last\`] = i1 === k_block2.length - 1; ctx[\`a_last\`] = i1 === v_block2.length - 1;
ctx[\`a_index\`] = i1; ctx[\`a_index\`] = i1;
ctx[\`a_value\`] = v_block2[i1]; ctx[\`a_value\`] = k_block2[i1];
const key1 = ctx['a']; const key1 = ctx['a'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);; const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);;
for (let i2 = 0; i2 < l_block4; i2++) { for (let i2 = 0; i2 < l_block4; i2++) {
ctx[\`b\`] = k_block4[i2]; ctx[\`b\`] = v_block4[i2];
ctx[\`b_first\`] = i2 === 0; ctx[\`b_first\`] = i2 === 0;
ctx[\`b_last\`] = i2 === k_block4.length - 1; ctx[\`b_last\`] = i2 === v_block4.length - 1;
ctx[\`b_index\`] = i2; ctx[\`b_index\`] = i2;
ctx[\`b_value\`] = v_block4[i2]; ctx[\`b_value\`] = k_block4[i2];
const key2 = ctx['b']; const key2 = ctx['b'];
c_block4[i2] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2); c_block4[i2] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
} }
@@ -503,12 +475,12 @@ exports[`t-foreach t-foreach in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`number\`] = k_block2[i1]; ctx[\`number\`] = v_block2[i1];
const key1 = ctx['number']; const key1 = ctx['number'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['letters']);; const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['letters']);;
for (let i2 = 0; i2 < l_block3; i2++) { for (let i2 = 0; i2 < l_block3; i2++) {
ctx[\`letter\`] = k_block3[i2]; ctx[\`letter\`] = v_block3[i2];
const key2 = ctx['letter']; const key2 = ctx['letter'];
const b5 = text(\` [\`); const b5 = text(\` [\`);
const b6 = text(ctx['number']); const b6 = text(ctx['number']);
@@ -537,7 +509,7 @@ exports[`t-foreach t-foreach with t-if inside (no external node) 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['elems']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['elems']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = k_block1[i1]; ctx[\`elem\`] = v_block1[i1];
const key1 = ctx['elem'].id; const key1 = ctx['elem'].id;
let b3; let b3;
if (ctx['elem'].id<3) { if (ctx['elem'].id<3) {
@@ -564,7 +536,7 @@ exports[`t-foreach t-foreach with t-if inside 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['elems']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['elems']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`elem\`] = k_block2[i1]; ctx[\`elem\`] = v_block2[i1];
const key1 = ctx['elem'].id; const key1 = ctx['elem'].id;
let b4; let b4;
if (ctx['elem'].id<3) { if (ctx['elem'].id<3) {
@@ -592,7 +564,7 @@ exports[`t-foreach t-key on t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['things']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['things']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`thing\`] = k_block2[i1]; ctx[\`thing\`] = v_block2[i1];
const key1 = ctx['thing']; const key1 = ctx['thing'];
c_block2[i1] = withKey(block3(), key1); c_block2[i1] = withKey(block3(), key1);
} }
@@ -615,7 +587,7 @@ exports[`t-foreach throws error if invalid loop expression 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['abc']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['abc']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
const key1 = ctx['item']; const key1 = ctx['item'];
const tKey_1 = ctx['item_index']; const tKey_1 = ctx['item_index'];
@@ -642,7 +614,7 @@ exports[`t-foreach with t-memo 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item'].id; const key1 = ctx['item'].id;
const memo1 = [ctx['item'].x]; const memo1 = [ctx['item'].x];
const vnode1 = cache[key1];; const vnode1 = cache[key1];;
+16 -16
View File
@@ -8,7 +8,7 @@ exports[`t-if a t-if next to a div 1`] = `
let block2 = createBlock(\`<div>foo</div>\`); let block2 = createBlock(\`<div>foo</div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = block2(); b2 = block2();
if (ctx['cond']) { if (ctx['cond']) {
b3 = text(\`1\`); b3 = text(\`1\`);
@@ -44,7 +44,7 @@ exports[`t-if boolean value condition elif (no outside node) 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4, b5; let b2,b3,b4,b5;
if (ctx['color']=='black') { if (ctx['color']=='black') {
b2 = text(\`black pearl\`); b2 = text(\`black pearl\`);
} else if (ctx['color']=='yellow') { } else if (ctx['color']=='yellow') {
@@ -67,7 +67,7 @@ exports[`t-if boolean value condition elif 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4, b5; let b2,b3,b4,b5;
if (ctx['color']=='black') { if (ctx['color']=='black') {
b2 = text(\`black pearl\`); b2 = text(\`black pearl\`);
} else if (ctx['color']=='yellow') { } else if (ctx['color']=='yellow') {
@@ -90,7 +90,7 @@ exports[`t-if boolean value condition else 1`] = `
let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`); let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`ok\`); b2 = text(\`ok\`);
} else { } else {
@@ -109,7 +109,7 @@ exports[`t-if boolean value condition false else 1`] = `
let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`); let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`fail\`); b2 = text(\`fail\`);
} else { } else {
@@ -145,7 +145,7 @@ exports[`t-if can use some boolean operators in expressions 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/><block-child-4/><block-child-5/><block-child-6/><block-child-7/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/><block-child-4/><block-child-5/><block-child-6/><block-child-7/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4, b5, b6, b7, b8, b9; let b2,b3,b4,b5,b6,b7,b8,b9;
if (ctx['cond1']&&ctx['cond2']) { if (ctx['cond1']&&ctx['cond2']) {
b2 = text(\`and\`); b2 = text(\`and\`);
} }
@@ -239,7 +239,7 @@ exports[`t-if simple t-if/t-else 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`1\`); b2 = text(\`1\`);
} else { } else {
@@ -258,7 +258,7 @@ exports[`t-if simple t-if/t-else in a div 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`1\`); b2 = text(\`1\`);
} else { } else {
@@ -277,7 +277,7 @@ exports[`t-if t-esc with t-elif 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (false) { if (false) {
b2 = text(\`abc\`); b2 = text(\`abc\`);
} else { } else {
@@ -314,7 +314,7 @@ exports[`t-if t-if and t-else with two nodes 1`] = `
let block5 = createBlock(\`<span>b</span>\`); let block5 = createBlock(\`<span>b</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`1\`); b2 = text(\`1\`);
} else { } else {
@@ -372,7 +372,7 @@ exports[`t-if t-if with empty content 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`hello\`); b2 = text(\`hello\`);
if (ctx['condition']) { if (ctx['condition']) {
b3 = text(\`\`); b3 = text(\`\`);
@@ -388,7 +388,7 @@ exports[`t-if t-if/t-else with more content 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`asf\`); b2 = text(\`asf\`);
@@ -458,7 +458,7 @@ exports[`t-if t-set, then t-if, part 3 1`] = `
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1 ctx[isBoundary] = 1
let b2, b3; let b2,b3;
setContextValue(ctx, \\"y\\", false); setContextValue(ctx, \\"y\\", false);
setContextValue(ctx, \\"x\\", ctx['y']); setContextValue(ctx, \\"x\\", ctx['y']);
if (ctx['x']) { if (ctx['x']) {
@@ -477,7 +477,7 @@ exports[`t-if two consecutive t-if 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['cond1']) { if (ctx['cond1']) {
b2 = text(\`1\`); b2 = text(\`1\`);
} }
@@ -497,7 +497,7 @@ exports[`t-if two consecutive t-if in a div 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['cond1']) { if (ctx['cond1']) {
b2 = text(\`1\`); b2 = text(\`1\`);
} }
@@ -520,7 +520,7 @@ exports[`t-if two t-ifs next to each other 1`] = `
let block5 = createBlock(\`<p>2</p>\`); let block5 = createBlock(\`<p>2</p>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
let txt1 = ctx['text']; let txt1 = ctx['text'];
b2 = block2([txt1]); b2 = block2([txt1]);
@@ -58,7 +58,7 @@ exports[`t-key t-key directive in a list 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['beers']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['beers']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`beer\`] = k_block2[i1]; ctx[\`beer\`] = v_block2[i1];
const key1 = ctx['beer'].id; const key1 = ctx['beer'].id;
let txt1 = ctx['beer'].name; let txt1 = ctx['beer'].name;
c_block2[i1] = withKey(block3([txt1]), key1); c_block2[i1] = withKey(block3([txt1]), key1);
@@ -79,7 +79,7 @@ exports[`t-key t-key on sub dom node pushes a child block in its parent 1`] = `
let block3 = createBlock(\`<div><h1/></div>\`); let block3 = createBlock(\`<div><h1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['hasSpan']) { if (ctx['hasSpan']) {
b2 = block2(); b2 = block2();
} }
+11 -11
View File
@@ -35,15 +35,15 @@ exports[`t-out multiple calls to t-out 1`] = `
const callTemplate_1 = app.getTemplate(\`sub\`); const callTemplate_1 = app.getTemplate(\`sub\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block3 = createBlock(\`<span>coucou</span>\`); let block2 = createBlock(\`<span>coucou</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b2 = block2();
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b3]);
} }
}" }"
`; `;
@@ -102,15 +102,15 @@ exports[`t-out t-out 0 1`] = `
const callTemplate_1 = app.getTemplate(\`_basic-callee\`); const callTemplate_1 = app.getTemplate(\`_basic-callee\`);
let block1 = createBlock(\`<div><block-child-0/></div>\`); let block1 = createBlock(\`<div><block-child-0/></div>\`);
let block3 = createBlock(\`<div>zero</div>\`); let block2 = createBlock(\`<div>zero</div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b3 = block3(); const b2 = block2();
ctx[zero] = b3; ctx[zero] = b2;
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); const b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]); return block1([], [b3]);
} }
}" }"
`; `;
@@ -309,7 +309,7 @@ exports[`t-out t-out switch markup on bdom 1`] = `
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1 ctx[isBoundary] = 1
let b3, b5; let b3,b5;
ctx[\`bdom\`] = new LazyValue(value1, ctx, this, node, key); ctx[\`bdom\`] = new LazyValue(value1, ctx, this, node, key);
if (ctx['hasBdom']) { if (ctx['hasBdom']) {
const b4 = safeOutput(ctx['bdom']); const b4 = safeOutput(ctx['bdom']);
@@ -105,7 +105,7 @@ exports[`t-ref refs in a loop 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
const tKey_1 = ctx['item']; const tKey_1 = ctx['item'];
const v1 = ctx['item']; const v1 = ctx['item'];
@@ -94,7 +94,7 @@ exports[`t-set set from body literal (with t-if/t-else 1`] = `
let { isBoundary, withDefault, LazyValue } = helpers; let { isBoundary, withDefault, LazyValue } = helpers;
function value1(ctx, node, key = \\"\\") { function value1(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['condition']) { if (ctx['condition']) {
b2 = text(\`true\`); b2 = text(\`true\`);
} else { } else {
@@ -351,7 +351,7 @@ exports[`t-set t-set outside modified in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
const key1 = ctx['val']; const key1 = ctx['val'];
let txt1 = ctx['iter']; let txt1 = ctx['iter'];
c_block2[i1] = withKey(block3([txt1]), key1); c_block2[i1] = withKey(block3([txt1]), key1);
@@ -381,7 +381,7 @@ exports[`t-set t-set outside modified in t-foreach increment-after operator 1`]
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
const key1 = ctx['val']; const key1 = ctx['val'];
let txt1 = ctx['iter']; let txt1 = ctx['iter'];
c_block2[i1] = withKey(block3([txt1]), key1); c_block2[i1] = withKey(block3([txt1]), key1);
@@ -411,7 +411,7 @@ exports[`t-set t-set outside modified in t-foreach increment-before operator 1`]
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
const key1 = ctx['val']; const key1 = ctx['val'];
let txt1 = ctx['iter']; let txt1 = ctx['iter'];
c_block2[i1] = withKey(block3([txt1]), key1); c_block2[i1] = withKey(block3([txt1]), key1);
@@ -441,7 +441,7 @@ exports[`t-set t-set should reuse variable if possible 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`elem\`] = k_block2[i1]; ctx[\`elem\`] = v_block2[i1];
ctx[\`elem_index\`] = i1; ctx[\`elem_index\`] = i1;
const key1 = ctx['elem_index']; const key1 = ctx['elem_index'];
let txt1 = ctx['v']; let txt1 = ctx['v'];
@@ -101,55 +101,3 @@ exports[`loading templates can load a few templates from an XMLDocument 2`] = `
} }
}" }"
`; `;
exports[`loading templates getTemplate: element returned (2) 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>Hello World!</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`loading templates getTemplate: element returned 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>Hello World!</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`loading templates getTemplate: template string returned 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>Hello World!</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`loading templates getTemplate: undefined returned 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>Hello World!</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
+5 -10
View File
@@ -9,20 +9,20 @@ describe("properly support svg", () => {
test("add proper namespace to svg", () => { test("add proper namespace to svg", () => {
const template = `<svg width="100px" height="90px"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </svg>`; const template = `<svg width="100px" height="90px"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </svg>`;
expect(renderToString(template)).toBe( expect(renderToString(template)).toBe(
`<svg xmlns="http://www.w3.org/2000/svg" width="100px" height="90px"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"></circle> </svg>` `<svg width=\"100px\" height=\"90px\"><circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"green\" stroke-width=\"1\" fill=\"yellow\"></circle> </svg>`
); );
}); });
test("add proper namespace to g tags", () => { test("add proper namespace to g tags", () => {
const template = `<g><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </g>`; const template = `<g><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </g>`;
expect(renderToString(template)).toBe( expect(renderToString(template)).toBe(
`<g xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"></circle> </g>` `<g><circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"green\" stroke-width=\"1\" fill=\"yellow\"></circle> </g>`
); );
}); });
test("namespace to g tags not added if already in svg namespace", () => { test("namespace to g tags not added if already in svg namespace", () => {
const template = `<svg><g/></svg>`; const template = `<svg><g/></svg>`;
expect(renderToString(template)).toBe(`<svg xmlns="http://www.w3.org/2000/svg"><g></g></svg>`); expect(renderToString(template)).toBe(`<svg><g></g></svg>`);
}); });
test("namespace to svg tags added even if already in svg namespace", () => { test("namespace to svg tags added even if already in svg namespace", () => {
@@ -41,13 +41,8 @@ describe("properly support svg", () => {
test("svg namespace added to sub-blocks", () => { test("svg namespace added to sub-blocks", () => {
const template = `<svg><path t-if="path"/></svg>`; const template = `<svg><path t-if="path"/></svg>`;
expect(renderToString(template, { path: false })).toBe( expect(renderToString(template, { path: false })).toBe(`<svg></svg>`);
`<svg xmlns="http://www.w3.org/2000/svg"></svg>` expect(renderToString(template, { path: true })).toBe(`<svg><path></path></svg>`);
);
// Because the path is its own block, it has its own xmlns attribute
expect(renderToString(template, { path: true })).toBe(
`<svg xmlns="http://www.w3.org/2000/svg"><path xmlns="http://www.w3.org/2000/svg"></path></svg>`
);
const bdom = renderToBdom(template, { path: true }); const bdom = renderToBdom(template, { path: true });
const fixture = makeTestFixture(); const fixture = makeTestFixture();
-42
View File
@@ -430,48 +430,6 @@ describe("t-call (template calling)", () => {
expect(context.renderToString("main")).toBe(expected); expect(context.renderToString("main")).toBe(expected);
}); });
test("root t-call with body: t-if true", () => {
const context = new TestContext();
const subTemplate = `sub`;
const main = `<t t-call="subTemplate"><t t-if="true">zero</t></t>`;
context.addTemplate("subTemplate", subTemplate);
context.addTemplate("main", main);
const expected = "sub";
expect(context.renderToString("main")).toBe(expected);
});
test("root t-call with body: t-if false", () => {
const context = new TestContext();
const subTemplate = `sub`;
const main = `<t t-call="subTemplate"><t t-if="false">zero</t></t>`;
context.addTemplate("subTemplate", subTemplate);
context.addTemplate("main", main);
const expected = "sub";
expect(context.renderToString("main")).toBe(expected);
});
test("root t-call with body: t-out with default", () => {
const context = new TestContext();
const subTemplate = `sub`;
const main = `<t t-call="subTemplate"><t t-out="nothing">default</t></t>`;
context.addTemplate("subTemplate", subTemplate);
context.addTemplate("main", main);
const expected = "sub";
expect(context.renderToString("main")).toBe(expected);
});
test("root t-call with body: t-foreach", () => {
const context = new TestContext();
const subTemplate = `sub`;
const main = `<t t-call="subTemplate">
<t t-foreach="[1]" t-as="i" t-key="i">1</t>
</t>`;
context.addTemplate("subTemplate", subTemplate);
context.addTemplate("main", main);
const expected = "sub";
expect(context.renderToString("main")).toBe(expected);
});
test("dynamic t-call", () => { test("dynamic t-call", () => {
const context = new TestContext(); const context = new TestContext();
const foo = `<foo><t t-esc="val"/></foo>`; const foo = `<foo><t t-esc="val"/></foo>`;
+1 -10
View File
@@ -110,7 +110,7 @@ describe("t-foreach", () => {
<t t-foreach="value" t-as="item" t-key="item_index"> <t t-foreach="value" t-as="item" t-key="item_index">
[<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>] [<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>]
</t>`; </t>`;
const expected = ` [0: a 1] [1: b 2] [2: c 3] `; const expected = ` [0: 1 a] [1: 2 b] [2: 3 c] `;
const context = { const context = {
value: new Map([ value: new Map([
["a", 1], ["a", 1],
@@ -131,15 +131,6 @@ describe("t-foreach", () => {
expect(renderToString(template, context)).toBe(expected); expect(renderToString(template, context)).toBe(expected);
}); });
test("iterate, string param", () => {
const template = `
<t t-foreach="'abc'" t-as="item" t-key="item_index">
[<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>]
</t>`;
const expected = ` [0: a a] [1: b b] [2: c c] `;
expect(renderToString(template)).toBe(expected);
});
test("iterate, iterable param", () => { test("iterate, iterable param", () => {
const template = ` const template = `
<t t-foreach="map.values()" t-as="item" t-key="item_index"> <t t-foreach="map.values()" t-as="item" t-key="item_index">
-58
View File
@@ -78,62 +78,4 @@ describe("loading templates", () => {
context.addTemplates(xml); context.addTemplates(xml);
expect(Object.keys(context.rawTemplates)).toEqual([]); expect(Object.keys(context.rawTemplates)).toEqual([]);
}); });
test("getTemplate: element returned", () => {
const context = new TestContext({
getTemplate: (name) => {
if (name === "main") {
const data = `<div>Hello World!</div>`;
const xml = new DOMParser().parseFromString(data, "text/xml");
return xml.firstChild as Element;
}
return;
},
});
const result = context.renderToString("main");
expect(result).toBe("<div>Hello World!</div>");
});
test("getTemplate: element returned (2)", () => {
const context = new TestContext({
getTemplate: (name) => {
if (name === "main") {
const doc = new Document();
const div = doc.createElement("div");
div.append(doc.createTextNode("Hello World!"));
return div;
}
return;
},
});
const result = context.renderToString("main");
expect(result).toBe("<div>Hello World!</div>");
});
test("getTemplate: template string returned", () => {
const context = new TestContext({
getTemplate: (name) => {
if (name === "main") {
return `<div>Hello World!</div>`;
}
return;
},
});
const result = context.renderToString("main");
expect(result).toBe("<div>Hello World!</div>");
});
test("getTemplate: undefined returned", () => {
const context = new TestContext({
getTemplate: () => {},
});
const data = `<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<div t-name="main">Hello World!</div>
</templates>`;
const xml = new DOMParser().parseFromString(data, "text/xml");
context.addTemplates(xml);
const result = context.renderToString("main");
expect(result).toBe("<div>Hello World!</div>");
});
}); });
+2 -27
View File
@@ -11,8 +11,8 @@ describe("basic validation", () => {
expect(() => context.getTemplate("invalidname")).toThrow("Missing template"); expect(() => context.getTemplate("invalidname")).toThrow("Missing template");
}); });
test("cannot add a different template with the same name in dev mode", () => { test("cannot add a different template with the same name", () => {
const context = new TemplateSet({ dev: true }); const context = new TemplateSet();
context.addTemplate("test", `<t/>`); context.addTemplate("test", `<t/>`);
// Same template with the same name is fine // Same template with the same name is fine
expect(() => context.addTemplate("test", "<t/>")).not.toThrow(); expect(() => context.addTemplate("test", "<t/>")).not.toThrow();
@@ -20,13 +20,6 @@ describe("basic validation", () => {
expect(() => context.addTemplate("test", "<div/>")).toThrow("already defined"); expect(() => context.addTemplate("test", "<div/>")).toThrow("already defined");
}); });
test("adding different template with same name outside dev mode silently ignores it", () => {
const context = new TemplateSet({ dev: false });
context.addTemplate("test", `<t/>`);
expect(() => context.addTemplate("test", "<div/>")).not.toThrow();
expect(context.rawTemplates.test).toBe("<t/>");
});
test("invalid xml", () => { test("invalid xml", () => {
const template = "<div>"; const template = "<div>";
expect(() => snapshotTemplate(template)).toThrow("Invalid XML in template"); expect(() => snapshotTemplate(template)).toThrow("Invalid XML in template");
@@ -44,22 +37,4 @@ describe("basic validation", () => {
const template = `<div t-best-beer="rochefort 10">test</div>`; const template = `<div t-best-beer="rochefort 10">test</div>`;
expect(() => renderToString(template)).toThrow("Unknown QWeb directive: 't-best-beer'"); expect(() => renderToString(template)).toThrow("Unknown QWeb directive: 't-best-beer'");
}); });
test("compilation error", () => {
const template = `<div t-att-class="a b">test</div>`;
expect(() => renderToString(template))
.toThrow(`Failed to compile anonymous template: Unexpected identifier
generated code:
function(app, bdom, helpers) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div block-attribute-0="class">test</div>\`);
return function template(ctx, node, key = "") {
let attr1 = ctx['a']ctx['b'];
return block1([attr1]);
}
}`);
});
}); });
@@ -440,7 +440,7 @@ exports[`basics higher order components parent and child 2`] = `
const comp2 = app.createComponent(\`ChildB\`, true, false, false, []); const comp2 = app.createComponent(\`ChildB\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['props'].child==='a') { if (ctx['props'].child==='a') {
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
} else { } else {
@@ -492,7 +492,7 @@ exports[`basics list of two sub components inside other nodes 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].blips);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].blips);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`blip\`] = k_block2[i1]; ctx[\`blip\`] = v_block2[i1];
const key1 = ctx['blip'].id; const key1 = ctx['blip'].id;
const b4 = comp1({}, key + \`__1__\${key1}\`, node, this, null); const b4 = comp1({}, key + \`__1__\${key1}\`, node, this, null);
const b5 = comp2({}, key + \`__2__\${key1}\`, node, this, null); const b5 = comp2({}, key + \`__2__\${key1}\`, node, this, null);
@@ -738,7 +738,7 @@ exports[`basics sub components between t-ifs 1`] = `
let block5 = createBlock(\`<span>test</span>\`); let block5 = createBlock(\`<span>test</span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4, b5; let b2,b3,b4,b5;
if (ctx['state'].flag) { if (ctx['state'].flag) {
b2 = block2(); b2 = block2();
} else { } else {
@@ -776,7 +776,7 @@ exports[`basics t-elif works with t-component 1`] = `
let block2 = createBlock(\`<div>somediv</div>\`); let block2 = createBlock(\`<div>somediv</div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].flag) { if (ctx['state'].flag) {
b2 = block2(); b2 = block2();
} else if (!ctx['state'].flag) { } else if (!ctx['state'].flag) {
@@ -810,7 +810,7 @@ exports[`basics t-else with empty string works with t-component 1`] = `
let block2 = createBlock(\`<div>somediv</div>\`); let block2 = createBlock(\`<div>somediv</div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].flag) { if (ctx['state'].flag) {
b2 = block2(); b2 = block2();
} else { } else {
@@ -844,7 +844,7 @@ exports[`basics t-else works with t-component 1`] = `
let block2 = createBlock(\`<div>somediv</div>\`); let block2 = createBlock(\`<div>somediv</div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].flag) { if (ctx['state'].flag) {
b2 = block2(); b2 = block2();
} else { } else {
@@ -909,7 +909,7 @@ exports[`basics t-key on a component with t-if, and a sibling component 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (false) { if (false) {
const tKey_1 = 'str'; const tKey_1 = 'str';
b2 = toggler(tKey_1, comp1({}, tKey_1 + key + \`__1\`, node, this, null)); b2 = toggler(tKey_1, comp1({}, tKey_1 + key + \`__1\`, node, this, null));
@@ -1084,7 +1084,7 @@ exports[`basics updating a component with t-foreach as root 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
c_block1[i1] = withKey(text(ctx['item']), key1); c_block1[i1] = withKey(text(ctx['item']), key1);
} }
@@ -1135,7 +1135,7 @@ exports[`basics widget after a t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));; const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`elem\`] = k_block2[i1]; ctx[\`elem\`] = v_block2[i1];
ctx[\`elem_index\`] = i1; ctx[\`elem_index\`] = i1;
const key1 = ctx['elem_index']; const key1 = ctx['elem_index'];
c_block2[i1] = withKey(text(\`txt\`), key1); c_block2[i1] = withKey(text(\`txt\`), key1);
@@ -1248,7 +1248,7 @@ exports[`support svg components add proper namespace to svg 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
const comp1 = app.createComponent(\`GComp\`, true, false, false, []); const comp1 = app.createComponent(\`GComp\`, true, false, false, []);
let block1 = createBlock(\`<svg xmlns=\\"http://www.w3.org/2000/svg\\"><block-child-0 xmlns=\\"\\"/></svg>\`); let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
const b2 = comp1({}, key + \`__1\`, node, this, null); const b2 = comp1({}, key + \`__1\`, node, this, null);
@@ -1262,7 +1262,7 @@ exports[`support svg components add proper namespace to svg 2`] = `
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<g xmlns=\\"http://www.w3.org/2000/svg\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/></g>\`); let block1 = createBlock(\`<g block-ns=\\"http://www.w3.org/2000/svg\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/></g>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
return block1(); return block1();
@@ -1282,7 +1282,7 @@ exports[`t-out in components can render list of t-out 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].items);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].items);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
const b4 = text(ctx['item']); const b4 = text(ctx['item']);
const b5 = safeOutput(ctx['item']); const b5 = safeOutput(ctx['item']);
@@ -13,7 +13,7 @@ exports[`Cascading renders after microtaskTick 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['state']);; const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['state']);;
for (let i1 = 0; i1 < l_block4; i1++) { for (let i1 = 0; i1 < l_block4; i1++) {
ctx[\`elem\`] = k_block4[i1]; ctx[\`elem\`] = v_block4[i1];
const key1 = ctx['elem'].id; const key1 = ctx['elem'].id;
c_block4[i1] = withKey(text(ctx['elem'].id), key1); c_block4[i1] = withKey(text(ctx['elem'].id), key1);
} }
@@ -34,7 +34,7 @@ exports[`Cascading renders after microtaskTick 2`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = k_block1[i1]; ctx[\`elem\`] = v_block1[i1];
const key1 = ctx['elem'].id; const key1 = ctx['elem'].id;
c_block1[i1] = withKey(comp1({id: ctx['elem'].id}, key + \`__1__\${key1}\`, node, this, null), key1); c_block1[i1] = withKey(comp1({id: ctx['elem'].id}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
@@ -61,7 +61,7 @@ exports[`another scenario with delayed rendering 1`] = `
const comp1 = app.createComponent(\`B\`, true, false, false, [\\"value\\"]); const comp1 = app.createComponent(\`B\`, true, false, false, [\\"value\\"]);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`A\`); b2 = text(\`A\`);
if (ctx['state'].value<15) { if (ctx['state'].value<15) {
b3 = comp1({value: ctx['state'].value}, key + \`__1\`, node, this, null); b3 = comp1({value: ctx['state'].value}, key + \`__1\`, node, this, null);
@@ -184,7 +184,7 @@ exports[`changing state before first render does not trigger a render (with pare
}" }"
`; `;
exports[`changing state before first render does not trigger a render (with parent) 3`] = ` exports[`changing state before first render does not trigger a render (with parent) 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -244,7 +244,7 @@ exports[`components are not destroyed between animation frame 1`] = `
const comp1 = app.createComponent(\`B\`, true, false, false, []); const comp1 = app.createComponent(\`B\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`A\`); b2 = text(\`A\`);
if (ctx['state'].flag) { if (ctx['state'].flag) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -254,7 +254,7 @@ exports[`components are not destroyed between animation frame 1`] = `
}" }"
`; `;
exports[`components are not destroyed between animation frame 3`] = ` exports[`components are not destroyed between animation frame 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -268,7 +268,7 @@ exports[`components are not destroyed between animation frame 3`] = `
}" }"
`; `;
exports[`components are not destroyed between animation frame 5`] = ` exports[`components are not destroyed between animation frame 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -748,7 +748,7 @@ exports[`concurrent renderings scenario 10 2`] = `
}" }"
`; `;
exports[`concurrent renderings scenario 10 4`] = ` exports[`concurrent renderings scenario 10 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -831,7 +831,7 @@ exports[`concurrent renderings scenario 13 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
if (ctx['state'].bool) { if (ctx['state'].bool) {
b3 = comp2({}, key + \`__2\`, node, this, null); b3 = comp2({}, key + \`__2\`, node, this, null);
@@ -978,7 +978,7 @@ exports[`concurrent renderings scenario 16 3`] = `
const comp1 = app.createComponent(\`D\`, true, false, false, []); const comp1 = app.createComponent(\`D\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4, b5, b6, b7, b8; let b2,b3,b4,b5,b6,b7,b8;
b2 = text(ctx['props'].fromA); b2 = text(ctx['props'].fromA);
b3 = text(\`:\`); b3 = text(\`:\`);
b4 = text(ctx['props'].fromB); b4 = text(ctx['props'].fromB);
@@ -993,7 +993,7 @@ exports[`concurrent renderings scenario 16 3`] = `
}" }"
`; `;
exports[`concurrent renderings scenario 16 6`] = ` exports[`concurrent renderings scenario 16 4`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1012,7 +1012,7 @@ exports[`creating two async components, scenario 1 1`] = `
const comp2 = app.createComponent(\`ChildB\`, true, false, false, []); const comp2 = app.createComponent(\`ChildB\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].flagA) { if (ctx['state'].flagA) {
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
} }
@@ -1024,7 +1024,7 @@ exports[`creating two async components, scenario 1 1`] = `
}" }"
`; `;
exports[`creating two async components, scenario 1 3`] = ` exports[`creating two async components, scenario 1 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1038,7 +1038,7 @@ exports[`creating two async components, scenario 1 3`] = `
}" }"
`; `;
exports[`creating two async components, scenario 1 5`] = ` exports[`creating two async components, scenario 1 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1061,7 +1061,7 @@ exports[`creating two async components, scenario 2 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = comp1({val: ctx['state'].valA}, key + \`__1\`, node, this, null); b2 = comp1({val: ctx['state'].valA}, key + \`__1\`, node, this, null);
if (ctx['state'].flagB) { if (ctx['state'].flagB) {
b3 = comp2({val: ctx['state'].valB}, key + \`__2\`, node, this, null); b3 = comp2({val: ctx['state'].valB}, key + \`__2\`, node, this, null);
@@ -1085,7 +1085,7 @@ exports[`creating two async components, scenario 2 2`] = `
}" }"
`; `;
exports[`creating two async components, scenario 2 5`] = ` exports[`creating two async components, scenario 2 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1109,7 +1109,7 @@ exports[`creating two async components, scenario 3 (patching in the same frame)
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = comp1({val: ctx['state'].valA}, key + \`__1\`, node, this, null); b2 = comp1({val: ctx['state'].valA}, key + \`__1\`, node, this, null);
if (ctx['state'].flagB) { if (ctx['state'].flagB) {
b3 = comp2({val: ctx['state'].valB}, key + \`__2\`, node, this, null); b3 = comp2({val: ctx['state'].valB}, key + \`__2\`, node, this, null);
@@ -1133,7 +1133,7 @@ exports[`creating two async components, scenario 3 (patching in the same frame)
}" }"
`; `;
exports[`creating two async components, scenario 3 (patching in the same frame) 5`] = ` exports[`creating two async components, scenario 3 (patching in the same frame) 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1308,7 +1308,7 @@ exports[`delayed render does not go through when t-component value changed 2`] =
}" }"
`; `;
exports[`delayed render does not go through when t-component value changed 4`] = ` exports[`delayed render does not go through when t-component value changed 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1421,7 +1421,7 @@ exports[`delayed rendering, destruction, stuff happens 2`] = `
const comp1 = app.createComponent(\`C\`, true, false, false, [\\"value\\"]); const comp1 = app.createComponent(\`C\`, true, false, false, [\\"value\\"]);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`B\`); b2 = text(\`B\`);
if (ctx['state'].hasChild) { if (ctx['state'].hasChild) {
b3 = comp1({value: ctx['state'].someValue+ctx['props'].value}, key + \`__1\`, node, this, null); b3 = comp1({value: ctx['state'].someValue+ctx['props'].value}, key + \`__1\`, node, this, null);
@@ -1514,7 +1514,7 @@ exports[`delayed rendering, reusing fiber then component is destroyed and stuff
const comp1 = app.createComponent(\`B\`, true, false, false, [\\"value\\"]); const comp1 = app.createComponent(\`B\`, true, false, false, [\\"value\\"]);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`A\`); b2 = text(\`A\`);
if (ctx['state'].value<15) { if (ctx['state'].value<15) {
b3 = comp1({value: ctx['state'].value}, key + \`__1\`, node, this, null); b3 = comp1({value: ctx['state'].value}, key + \`__1\`, node, this, null);
@@ -1572,7 +1572,7 @@ exports[`delayed rendering, then component is destroyed and stuff 2`] = `
const comp1 = app.createComponent(\`C\`, true, false, false, []); const comp1 = app.createComponent(\`C\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(ctx['props'].value); b2 = text(ctx['props'].value);
if (ctx['props'].value<10) { if (ctx['props'].value<10) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -1605,7 +1605,7 @@ exports[`destroyed component causes other soon to be destroyed component to rere
const comp2 = app.createComponent(\`C\`, true, false, false, [\\"value\\"]); const comp2 = app.createComponent(\`C\`, true, false, false, [\\"value\\"]);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\` A \`); b2 = text(\` A \`);
if (ctx['state'].flag) { if (ctx['state'].flag) {
const b4 = comp1({value: ctx['state'].valueB}, key + \`__1\`, node, this, null); const b4 = comp1({value: ctx['state'].valueB}, key + \`__1\`, node, this, null);
@@ -1617,7 +1617,7 @@ exports[`destroyed component causes other soon to be destroyed component to rere
}" }"
`; `;
exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 3`] = ` exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1628,7 +1628,7 @@ exports[`destroyed component causes other soon to be destroyed component to rere
}" }"
`; `;
exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 4`] = ` exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1646,7 +1646,7 @@ exports[`destroying/recreating a subcomponent, other scenario 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, []); const comp1 = app.createComponent(\`Child\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`parent\`); b2 = text(\`parent\`);
if (ctx['state'].hasChild) { if (ctx['state'].hasChild) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -1656,7 +1656,7 @@ exports[`destroying/recreating a subcomponent, other scenario 1`] = `
}" }"
`; `;
exports[`destroying/recreating a subcomponent, other scenario 3`] = ` exports[`destroying/recreating a subcomponent, other scenario 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1685,7 +1685,7 @@ exports[`destroying/recreating a subwidget with different props (if start is not
}" }"
`; `;
exports[`destroying/recreating a subwidget with different props (if start is not over) 3`] = ` exports[`destroying/recreating a subwidget with different props (if start is not over) 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1787,7 +1787,7 @@ exports[`rendering component again in next microtick 1`] = `
}" }"
`; `;
exports[`rendering component again in next microtick 3`] = ` exports[`rendering component again in next microtick 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -1846,7 +1846,7 @@ exports[`renderings, destruction, patch, stuff, ... yet another variation 2`] =
const comp1 = app.createComponent(\`C\`, true, false, false, []); const comp1 = app.createComponent(\`C\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(\`B\`); b2 = text(\`B\`);
if (ctx['props'].value===33) { if (ctx['props'].value===33) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -1901,7 +1901,7 @@ exports[`t-foreach with dynamic async component 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['list']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['list']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`arr\`] = k_block1[i1]; ctx[\`arr\`] = v_block1[i1];
ctx[\`arr_index\`] = i1; ctx[\`arr_index\`] = i1;
const key1 = ctx['arr_index']; const key1 = ctx['arr_index'];
let b3; let b3;
@@ -12,18 +12,6 @@ exports[`basics display a nice error if a component is not a component 1`] = `
}" }"
`; `;
exports[`basics display a nice error if a non-root component template fails to compile 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") {
return comp1({}, key + \`__1\`, node, this, null);
}
}"
`;
exports[`basics display a nice error if it cannot find component (in dev mode) 1`] = ` exports[`basics display a nice error if it cannot find component (in dev mode) 1`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
@@ -103,7 +91,7 @@ exports[`basics simple catchError 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['error']) { if (ctx['error']) {
b2 = text(\`Error\`); b2 = text(\`Error\`);
} else { } else {
@@ -201,7 +189,7 @@ exports[`can catch errors an error in onWillDestroy 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, []); const comp1 = app.createComponent(\`Child\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(ctx['state'].value); b2 = text(ctx['state'].value);
if (ctx['state'].hasChild) { if (ctx['state'].hasChild) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -231,7 +219,7 @@ exports[`can catch errors an error in onWillDestroy, variation 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, []); const comp1 = app.createComponent(\`Child\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
b2 = text(ctx['state'].value); b2 = text(ctx['state'].value);
if (ctx['state'].hasChild) { if (ctx['state'].hasChild) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -241,7 +229,7 @@ exports[`can catch errors an error in onWillDestroy, variation 1`] = `
}" }"
`; `;
exports[`can catch errors an error in onWillDestroy, variation 3`] = ` exports[`can catch errors an error in onWillDestroy, variation 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -295,7 +283,7 @@ exports[`can catch errors can catch an error in a component render function 2`]
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -350,7 +338,7 @@ exports[`can catch errors can catch an error in the constructor call of a compon
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -394,7 +382,7 @@ exports[`can catch errors can catch an error in the constructor call of a compon
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -474,7 +462,7 @@ exports[`can catch errors can catch an error in the initial call of a component
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -532,7 +520,7 @@ exports[`can catch errors can catch an error in the initial call of a component
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -593,7 +581,7 @@ exports[`can catch errors can catch an error in the mounted call (in child of ch
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -626,7 +614,7 @@ exports[`can catch errors can catch an error in the mounted call (in root compon
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -680,7 +668,7 @@ exports[`can catch errors can catch an error in the mounted call 2`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -735,7 +723,7 @@ exports[`can catch errors can catch an error in the willPatch call 2`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -790,7 +778,7 @@ exports[`can catch errors can catch an error in the willStart call 2`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -847,7 +835,7 @@ exports[`can catch errors can catch an error origination from a child's willStar
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -893,7 +881,7 @@ exports[`can catch errors catchError in catchError 1`] = `
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['error']) { if (ctx['error']) {
b2 = text(\`Error\`); b2 = text(\`Error\`);
} else { } else {
@@ -950,7 +938,7 @@ exports[`can catch errors catching error, rethrow, render parent -- a main comp
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(Object.values(ctx['state'].cps));; const [k_block1, v_block1, l_block1, c_block1] = prepareList(Object.values(ctx['state'].cps));;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`cp\`] = k_block1[i1]; ctx[\`cp\`] = v_block1[i1];
const key1 = ctx['cp'].id; const key1 = ctx['cp'].id;
const v1 = ctx['this']; const v1 = ctx['this'];
const v2 = ctx['cp']; const v2 = ctx['cp'];
@@ -1029,7 +1017,7 @@ exports[`can catch errors catching in child makes parent render 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(Object.entries(ctx['this'].elements));; const [k_block1, v_block1, l_block1, c_block1] = prepareList(Object.entries(ctx['this'].elements));;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = k_block1[i1]; ctx[\`elem\`] = v_block1[i1];
const key1 = ctx['elem'][0]; const key1 = ctx['elem'][0];
const v1 = ctx['this']; const v1 = ctx['this'];
const v2 = ctx['elem']; const v2 = ctx['elem'];
@@ -1123,7 +1111,7 @@ exports[`can catch errors error in mounted on a component with a sibling (proper
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].error) { if (ctx['state'].error) {
b2 = text(\`Error handled\`); b2 = text(\`Error handled\`);
} else { } else {
@@ -1167,7 +1155,7 @@ exports[`can catch errors onError in class inheritance is called if rethrown 2`]
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (!ctx['state'].error) { if (!ctx['state'].error) {
b2 = text(ctx['this'].will.crash); b2 = text(ctx['this'].will.crash);
} else { } else {
@@ -1198,7 +1186,7 @@ exports[`can catch errors onError in class inheritance is not called if no rethr
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`); let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (!ctx['state'].error) { if (!ctx['state'].error) {
b2 = text(ctx['this'].will.crash); b2 = text(ctx['this'].will.crash);
} else { } else {
@@ -117,7 +117,7 @@ exports[`event handling objects from scope are properly captured by t-on 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
const v1 = ctx['onClick']; const v1 = ctx['onClick'];
const v2 = ctx['item']; const v2 = ctx['item'];
@@ -158,7 +158,7 @@ exports[`event handling t-on with handler bound to dynamic argument on a t-forea
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
const v1 = ctx['onClick']; const v1 = ctx['onClick'];
const v2 = ctx['item']; const v2 = ctx['item'];
@@ -34,7 +34,7 @@ exports[`basics can select a sub widget 1`] = `
const comp2 = app.createComponent(\`OtherChild\`, true, false, false, []); const comp2 = app.createComponent(\`OtherChild\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['env'].options.flag) { if (ctx['env'].options.flag) {
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
} }
@@ -80,7 +80,7 @@ exports[`basics can select a sub widget, part 2 1`] = `
const comp2 = app.createComponent(\`OtherChild\`, true, false, false, []); const comp2 = app.createComponent(\`OtherChild\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].flag) { if (ctx['state'].flag) {
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
} }
@@ -54,7 +54,7 @@ exports[`lifecycle hooks component semantics 3`] = `
let block1 = createBlock(\`<div>C<block-child-0/><block-child-1/><block-child-2/></div>\`); let block1 = createBlock(\`<div>C<block-child-0/><block-child-1/><block-child-2/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4; let b2,b3,b4;
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
if (ctx['state'].flag) { if (ctx['state'].flag) {
b3 = comp2({}, key + \`__2\`, node, this, null); b3 = comp2({}, key + \`__2\`, node, this, null);
@@ -92,7 +92,7 @@ exports[`lifecycle hooks component semantics 5`] = `
}" }"
`; `;
exports[`lifecycle hooks component semantics 7`] = ` exports[`lifecycle hooks component semantics 6`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -174,7 +174,7 @@ exports[`lifecycle hooks destroy new children before being mountged 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, []); const comp1 = app.createComponent(\`Child\`, true, false, false, []);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3, b4; let b2,b3,b4;
b2 = text(\`before\`); b2 = text(\`before\`);
if (ctx['state'].flag) { if (ctx['state'].flag) {
b3 = comp1({}, key + \`__1\`, node, this, null); b3 = comp1({}, key + \`__1\`, node, this, null);
@@ -185,7 +185,7 @@ exports[`lifecycle hooks destroy new children before being mountged 1`] = `
}" }"
`; `;
exports[`lifecycle hooks destroy new children before being mountged 3`] = ` exports[`lifecycle hooks destroy new children before being mountged 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -291,7 +291,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 1`] = `
}" }"
`; `;
exports[`lifecycle hooks lifecycle semantics, part 2 3`] = ` exports[`lifecycle hooks lifecycle semantics, part 2 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -303,7 +303,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 3`] = `
}" }"
`; `;
exports[`lifecycle hooks lifecycle semantics, part 2 4`] = ` exports[`lifecycle hooks lifecycle semantics, part 2 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -348,7 +348,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 1`] = `
}" }"
`; `;
exports[`lifecycle hooks lifecycle semantics, part 4 3`] = ` exports[`lifecycle hooks lifecycle semantics, part 4 2`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -360,7 +360,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 3`] = `
}" }"
`; `;
exports[`lifecycle hooks lifecycle semantics, part 4 4`] = ` exports[`lifecycle hooks lifecycle semantics, part 4 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -826,7 +826,7 @@ exports[`lifecycle hooks willStart, mounted on subwidget rendered after main is
let block3 = createBlock(\`<div/>\`); let block3 = createBlock(\`<div/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].ok) { if (ctx['state'].ok) {
b2 = comp1({}, key + \`__1\`, node, this, null); b2 = comp1({}, key + \`__1\`, node, this, null);
} else { } else {
@@ -11,7 +11,7 @@ exports[`.alike suffix in a list 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state'].elems);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state'].elems);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = k_block1[i1]; ctx[\`elem\`] = v_block1[i1];
const key1 = ctx['elem'].id; const key1 = ctx['elem'].id;
const v1 = ctx['this']; const v1 = ctx['this'];
const v2 = ctx['elem']; const v2 = ctx['elem'];
@@ -106,7 +106,7 @@ exports[`basics arrow functions as prop correctly capture their scope 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
const key1 = ctx['item'].val; const key1 = ctx['item'].val;
const v1 = ctx['onClick']; const v1 = ctx['onClick'];
const v2 = ctx['item']; const v2 = ctx['item'];
@@ -39,7 +39,7 @@ exports[`default props can set default boolean values 2`] = `
let block1 = createBlock(\`<span><block-child-0/><block-child-1/></span>\`); let block1 = createBlock(\`<span><block-child-0/><block-child-1/></span>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['props'].p) { if (ctx['props'].p) {
b2 = text(\`hey\`); b2 = text(\`hey\`);
} }
@@ -23,7 +23,7 @@ exports[`refs can use 2 refs with same name in a t-if/t-else situation 1`] = `
let block3 = createBlock(\`<span block-ref=\\"0\\"/>\`); let block3 = createBlock(\`<span block-ref=\\"0\\"/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].value) { if (ctx['state'].value) {
let ref1 = (el) => this.__owl__.setRef((\`coucou\`), el); let ref1 = (el) => this.__owl__.setRef((\`coucou\`), el);
b2 = block2([ref1]); b2 = block2([ref1]);
@@ -509,7 +509,7 @@ exports[`slots default slot with slot scope: shorthand syntax 1`] = `
const comp1 = app.createComponent(\`Child\`, true, true, false, []); const comp1 = app.createComponent(\`Child\`, true, true, false, []);
function slot1(ctx, node, key = \\"\\") { function slot1(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['slotScope'].bool) { if (ctx['slotScope'].bool) {
b2 = text(\`some text\`); b2 = text(\`some text\`);
} else { } else {
@@ -633,7 +633,7 @@ exports[`slots dynamic slot in multiple locations 2`] = `
let block2 = createBlock(\`<p><block-child-0/></p>\`); let block2 = createBlock(\`<p><block-child-0/></p>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b4; let b2,b4;
if (ctx['props'].location===1) { if (ctx['props'].location===1) {
const slot1 = ('coffee'); const slot1 = ('coffee');
const b3 = toggler(slot1, callSlot(ctx, node, key + \`__1\`, slot1, true, {})); const b3 = toggler(slot1, callSlot(ctx, node, key + \`__1\`, slot1, true, {}));
@@ -1066,45 +1066,6 @@ exports[`slots multiple slots containing components 3`] = `
}" }"
`; `;
exports[`slots named slot inside named slot in t-component 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { capture, markRaw } = helpers;
const comp1 = app.createComponent(null, false, true, false, []);
const comp2 = app.createComponent(\`Child\`, true, true, false, []);
function slot1(ctx, node, key = \\"\\") {
const b2 = text(\` outer \`);
const ctx2 = capture(ctx);
const Comp1 = ctx['Child'];
const b4 = toggler(Comp1, comp1({slots: markRaw({'brol': {__render: slot2.bind(this), __ctx: ctx2}})}, (Comp1).name + key + \`__1\`, node, this, Comp1));
return multi([b2, b4]);
}
function slot2(ctx, node, key = \\"\\") {
return text(ctx['value']);
}
return function template(ctx, node, key = \\"\\") {
const ctx1 = capture(ctx);
return comp2({slots: markRaw({'brol': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__2\`, node, this, null);
}
}"
`;
exports[`slots named slot inside named slot in t-component 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { callSlot } = helpers;
return function template(ctx, node, key = \\"\\") {
return callSlot(ctx, node, key, 'brol', false, {});
}
}"
`;
exports[`slots named slot inside slot 1`] = ` exports[`slots named slot inside slot 1`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
@@ -1501,7 +1462,7 @@ exports[`slots simple default slot with params 1`] = `
const comp1 = app.createComponent(\`Child\`, true, true, false, []); const comp1 = app.createComponent(\`Child\`, true, true, false, []);
function slot1(ctx, node, key = \\"\\") { function slot1(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['slotScope'].bool) { if (ctx['slotScope'].bool) {
b2 = text(\`some text\`); b2 = text(\`some text\`);
} else { } else {
@@ -1597,7 +1558,7 @@ exports[`slots simple dynamic slot with slot scope 1`] = `
const comp1 = app.createComponent(\`Child\`, true, true, false, []); const comp1 = app.createComponent(\`Child\`, true, true, false, []);
function slot1(ctx, node, key = \\"\\") { function slot1(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['slotScope'].bool) { if (ctx['slotScope'].bool) {
b2 = text(\`some text\`); b2 = text(\`some text\`);
} else { } else {
@@ -1704,7 +1665,7 @@ exports[`slots simple slot with slot scope 1`] = `
const comp1 = app.createComponent(\`Child\`, true, true, false, []); const comp1 = app.createComponent(\`Child\`, true, true, false, []);
function slot1(ctx, node, key = \\"\\") { function slot1(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['slotScope'].bool) { if (ctx['slotScope'].bool) {
b2 = text(\`some text\`); b2 = text(\`some text\`);
} else { } else {
@@ -2121,7 +2082,7 @@ exports[`slots slot in multiple locations 2`] = `
let block2 = createBlock(\`<p><block-child-0/></p>\`); let block2 = createBlock(\`<p><block-child-0/></p>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b4; let b2,b4;
if (ctx['props'].location===1) { if (ctx['props'].location===1) {
const b3 = callSlot(ctx, node, key, 'default', false, {}); const b3 = callSlot(ctx, node, key, 'default', false, {});
b2 = block2([], [b3]); b2 = block2([], [b3]);
@@ -2179,7 +2140,7 @@ exports[`slots slot in t-foreach locations 2`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['props'].list);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['props'].list);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = k_block1[i1]; ctx[\`elem\`] = v_block1[i1];
ctx[\`elem_index\`] = i1; ctx[\`elem_index\`] = i1;
const key1 = ctx['elem_index']; const key1 = ctx['elem_index'];
let txt1 = ctx['elem']; let txt1 = ctx['elem'];
@@ -2469,7 +2430,7 @@ exports[`slots slots are rendered with proper context, part 2 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].users);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].users);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`user\`] = k_block2[i1]; ctx[\`user\`] = v_block2[i1];
const key1 = ctx['user'].id; const key1 = ctx['user'].id;
const ctx1 = capture(ctx); const ctx1 = capture(ctx);
const b7 = comp1({to: '/user/'+ctx['user'].id,slots: markRaw({'default': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__1__\${key1}\`, node, this, null); const b7 = comp1({to: '/user/'+ctx['user'].id,slots: markRaw({'default': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__1__\${key1}\`, node, this, null);
@@ -2517,7 +2478,7 @@ exports[`slots slots are rendered with proper context, part 3 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].users);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].users);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`user\`] = k_block2[i1]; ctx[\`user\`] = v_block2[i1];
const key1 = ctx['user'].id; const key1 = ctx['user'].id;
setContextValue(ctx, \\"userdescr\\", 'User '+ctx['user'].name); setContextValue(ctx, \\"userdescr\\", 'User '+ctx['user'].name);
const ctx1 = capture(ctx); const ctx1 = capture(ctx);
@@ -2664,7 +2625,7 @@ exports[`slots slots in t-foreach and re-rendering 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));; const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`n\`] = k_block2[i1]; ctx[\`n\`] = v_block2[i1];
ctx[\`n_index\`] = i1; ctx[\`n_index\`] = i1;
const key1 = ctx['n_index']; const key1 = ctx['n_index'];
const ctx1 = capture(ctx); const ctx1 = capture(ctx);
@@ -2713,14 +2674,14 @@ exports[`slots slots in t-foreach in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['tree']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['tree']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`node1\`] = k_block2[i1]; ctx[\`node1\`] = v_block2[i1];
const key1 = ctx['node1'].key; const key1 = ctx['node1'].key;
let txt1 = ctx['node1'].value; let txt1 = ctx['node1'].value;
const b4 = block4([txt1]); const b4 = block4([txt1]);
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block6, v_block6, l_block6, c_block6] = prepareList(ctx['node1'].nodes);; const [k_block6, v_block6, l_block6, c_block6] = prepareList(ctx['node1'].nodes);;
for (let i2 = 0; i2 < l_block6; i2++) { for (let i2 = 0; i2 < l_block6; i2++) {
ctx[\`node2\`] = k_block6[i2]; ctx[\`node2\`] = v_block6[i2];
const key2 = ctx['node2'].key; const key2 = ctx['node2'].key;
const ctx1 = capture(ctx); const ctx1 = capture(ctx);
c_block6[i2] = withKey(comp1({slots: markRaw({'default': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__1__\${key1}__\${key2}\`, node, this, null), key2); c_block6[i2] = withKey(comp1({slots: markRaw({'default': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__1__\${key1}__\${key2}\`, node, this, null), key2);
@@ -2770,7 +2731,7 @@ exports[`slots slots in t-foreach with t-set and re-rendering 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));; const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`n\`] = k_block2[i1]; ctx[\`n\`] = v_block2[i1];
ctx[\`n_index\`] = i1; ctx[\`n_index\`] = i1;
const key1 = ctx['n_index']; const key1 = ctx['n_index'];
setContextValue(ctx, \\"dummy\\", ctx['n_index']); setContextValue(ctx, \\"dummy\\", ctx['n_index']);
@@ -2920,13 +2881,13 @@ exports[`slots t-slot in recursive templates 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['items']);; const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block3; i1++) { for (let i1 = 0; i1 < l_block3; i1++) {
ctx[\`item\`] = k_block3[i1]; ctx[\`item\`] = v_block3[i1];
ctx[\`item_first\`] = i1 === 0; ctx[\`item_first\`] = i1 === 0;
ctx[\`item_last\`] = i1 === k_block3.length - 1; ctx[\`item_last\`] = i1 === v_block3.length - 1;
ctx[\`item_index\`] = i1; ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = v_block3[i1]; ctx[\`item_value\`] = k_block3[i1];
const key1 = ctx['item'].name; const key1 = ctx['item'].name;
let b5, b6; let b5,b6;
if (!ctx['item'].children.length) { if (!ctx['item'].children.length) {
b5 = text(ctx['item'].name); b5 = text(ctx['item'].name);
} else { } else {
@@ -166,7 +166,7 @@ exports[`style and class handling class on sub component, which is switched to a
const comp2 = app.createComponent(\`ChildB\`, true, false, false, [\\"class\\"]); const comp2 = app.createComponent(\`ChildB\`, true, false, false, [\\"class\\"]);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['props'].child==='a') { if (ctx['props'].child==='a') {
b2 = comp1({class: ctx['props'].class}, key + \`__1\`, node, this, null); b2 = comp1({class: ctx['props'].class}, key + \`__1\`, node, this, null);
} else { } else {
@@ -10,8 +10,8 @@ exports[`t-call dynamic t-call 1`] = `
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx); ctx = Object.create(ctx);
ctx[isBoundary] = 1; ctx[isBoundary] = 1;
const b2 = text(\` owl \`); const b1 = text(\` owl \`);
ctx[zero] = b2; ctx[zero] = b1;
const template1 = (ctx['current'].template); const template1 = (ctx['current'].template);
return call(this, template1, ctx, node, key + \`__1\`); return call(this, template1, ctx, node, key + \`__1\`);
} }
@@ -364,7 +364,7 @@ exports[`t-call sub components in two t-calls 1`] = `
let block3 = createBlock(\`<div><block-child-0/></div>\`); let block3 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].val===1) { if (ctx['state'].val===1) {
b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`); b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
} else { } else {
@@ -415,11 +415,11 @@ exports[`t-call t-call in t-foreach and children component 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b','c']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b','c']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
ctx[\`val_first\`] = i1 === 0; ctx[\`val_first\`] = i1 === 0;
ctx[\`val_last\`] = i1 === k_block2.length - 1; ctx[\`val_last\`] = i1 === v_block2.length - 1;
ctx[\`val_index\`] = i1; ctx[\`val_index\`] = i1;
ctx[\`val_value\`] = v_block2[i1]; ctx[\`val_value\`] = k_block2[i1];
const key1 = ctx['val']; const key1 = ctx['val'];
c_block2[i1] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`), key1); c_block2[i1] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
} }
@@ -180,7 +180,7 @@ exports[`t-component switching dynamic component 2`] = `
}" }"
`; `;
exports[`t-component switching dynamic component 4`] = ` exports[`t-component switching dynamic component 3`] = `
"function anonymous(app, bdom, helpers "function anonymous(app, bdom, helpers
) { ) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
@@ -14,7 +14,7 @@ exports[`list of components components in a node in a t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = k_block2[i1]; ctx[\`item\`] = v_block2[i1];
const key1 = 'li_'+ctx['item']; const key1 = 'li_'+ctx['item'];
const b4 = comp1({item: ctx['item']}, key + \`__1__\${key1}\`, node, this, null); const b4 = comp1({item: ctx['item']}, key + \`__1__\${key1}\`, node, this, null);
c_block2[i1] = withKey(block3([], [b4]), key1); c_block2[i1] = withKey(block3([], [b4]), key1);
@@ -51,7 +51,7 @@ exports[`list of components crash on duplicate key in dev mode 1`] = `
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1,2]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([1,2]);;
const keys1 = new Set(); const keys1 = new Set();
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
const key1 = 'child'; const key1 = 'child';
if (keys1.has(String(key1))) { throw new OwlError(\`Got duplicate key in t-foreach: \${key1}\`)} if (keys1.has(String(key1))) { throw new OwlError(\`Got duplicate key in t-foreach: \${key1}\`)}
keys1.add(String(key1)); keys1.add(String(key1));
@@ -87,7 +87,7 @@ exports[`list of components crash when using object as keys that serialize to th
const [k_block1, v_block1, l_block1, c_block1] = prepareList([{},{}]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([{},{}]);;
const keys1 = new Set(); const keys1 = new Set();
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = k_block1[i1]; ctx[\`item\`] = v_block1[i1];
const key1 = ctx['item']; const key1 = ctx['item'];
if (keys1.has(String(key1))) { throw new OwlError(\`Got duplicate key in t-foreach: \${key1}\`)} if (keys1.has(String(key1))) { throw new OwlError(\`Got duplicate key in t-foreach: \${key1}\`)}
keys1.add(String(key1)); keys1.add(String(key1));
@@ -125,7 +125,7 @@ exports[`list of components list of sub components inside other nodes 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].blips);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].blips);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`blip\`] = k_block2[i1]; ctx[\`blip\`] = v_block2[i1];
const key1 = ctx['blip'].id; const key1 = ctx['blip'].id;
const b4 = comp1({}, key + \`__1__\${key1}\`, node, this, null); const b4 = comp1({}, key + \`__1__\${key1}\`, node, this, null);
c_block2[i1] = withKey(block3([], [b4]), key1); c_block2[i1] = withKey(block3([], [b4]), key1);
@@ -191,7 +191,7 @@ exports[`list of components order is correct when slots are not of same type 2`]
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['slotNames']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['slotNames']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`slotName\`] = k_block1[i1]; ctx[\`slotName\`] = v_block1[i1];
const key1 = ctx['slotName']; const key1 = ctx['slotName'];
const slot1 = (ctx['slotName']); const slot1 = (ctx['slotName']);
c_block1[i1] = withKey(toggler(slot1, callSlot(ctx, node, key1 + \`__1__\${key1}\`, slot1, true, {})), key1); c_block1[i1] = withKey(toggler(slot1, callSlot(ctx, node, key1 + \`__1__\${key1}\`, slot1, true, {})), key1);
@@ -214,13 +214,13 @@ exports[`list of components reconciliation alg works for t-foreach in t-foreach
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].s);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].s);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`section\`] = k_block2[i1]; ctx[\`section\`] = v_block2[i1];
ctx[\`section_index\`] = i1; ctx[\`section_index\`] = i1;
const key1 = ctx['section_index']; const key1 = ctx['section_index'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['section'].blips);; const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['section'].blips);;
for (let i2 = 0; i2 < l_block3; i2++) { for (let i2 = 0; i2 < l_block3; i2++) {
ctx[\`blip\`] = k_block3[i2]; ctx[\`blip\`] = v_block3[i2];
ctx[\`blip_index\`] = i2; ctx[\`blip_index\`] = i2;
const key2 = ctx['blip_index']; const key2 = ctx['blip_index'];
c_block3[i2] = withKey(comp1({blip: ctx['blip']}, key + \`__1__\${key1}__\${key2}\`, node, this, null), key2); c_block3[i2] = withKey(comp1({blip: ctx['blip']}, key + \`__1__\${key1}__\${key2}\`, node, this, null), key2);
@@ -263,12 +263,12 @@ exports[`list of components reconciliation alg works for t-foreach in t-foreach,
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].rows);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].rows);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`row\`] = k_block2[i1]; ctx[\`row\`] = v_block2[i1];
const key1 = ctx['row']; const key1 = ctx['row'];
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['state'].cols);; const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['state'].cols);;
for (let i2 = 0; i2 < l_block4; i2++) { for (let i2 = 0; i2 < l_block4; i2++) {
ctx[\`col\`] = k_block4[i2]; ctx[\`col\`] = v_block4[i2];
const key2 = ctx['col']; const key2 = ctx['col'];
const b6 = comp1({row: ctx['row'],col: ctx['col']}, key + \`__1__\${key1}__\${key2}\`, node, this, null); const b6 = comp1({row: ctx['row'],col: ctx['col']}, key + \`__1__\${key1}__\${key2}\`, node, this, null);
c_block4[i2] = withKey(block5([], [b6]), key2); c_block4[i2] = withKey(block5([], [b6]), key2);
@@ -308,7 +308,7 @@ exports[`list of components simple list 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state'].elems);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state'].elems);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = k_block1[i1]; ctx[\`elem\`] = v_block1[i1];
const key1 = ctx['elem'].id; const key1 = ctx['elem'].id;
c_block1[i1] = withKey(comp1({value: ctx['elem'].value}, key + \`__1__\${key1}\`, node, this, null), key1); c_block1[i1] = withKey(comp1({value: ctx['elem'].value}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
@@ -344,7 +344,7 @@ exports[`list of components sub components rendered in a loop 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].numbers);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].numbers);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`number\`] = k_block2[i1]; ctx[\`number\`] = v_block2[i1];
const key1 = ctx['number']; const key1 = ctx['number'];
c_block2[i1] = withKey(comp1({n: ctx['number']}, key + \`__1__\${key1}\`, node, this, null), key1); c_block2[i1] = withKey(comp1({n: ctx['number']}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
@@ -381,7 +381,7 @@ exports[`list of components sub components with some state rendered in a loop 1`
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].numbers);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].numbers);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`number\`] = k_block2[i1]; ctx[\`number\`] = v_block2[i1];
const key1 = ctx['number']; const key1 = ctx['number'];
c_block2[i1] = withKey(comp1({}, key + \`__1__\${key1}\`, node, this, null), key1); c_block2[i1] = withKey(comp1({}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
@@ -418,7 +418,7 @@ exports[`list of components switch component position 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['clist']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['clist']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`c\`] = k_block2[i1]; ctx[\`c\`] = v_block2[i1];
const key1 = ctx['c']; const key1 = ctx['c'];
c_block2[i1] = withKey(comp1({key: ctx['c']}, key + \`__1__\${key1}\`, node, this, null), key1); c_block2[i1] = withKey(comp1({key: ctx['c']}, key + \`__1__\${key1}\`, node, this, null), key1);
} }
@@ -455,7 +455,7 @@ exports[`list of components t-foreach with t-component, and update 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));; const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`n\`] = k_block2[i1]; ctx[\`n\`] = v_block2[i1];
ctx[\`n_index\`] = i1; ctx[\`n_index\`] = i1;
const key1 = ctx['n_index']; const key1 = ctx['n_index'];
c_block2[i1] = withKey(comp1({val: ctx['n_index']}, key + \`__1__\${key1}\`, node, this, null), key1); c_block2[i1] = withKey(comp1({val: ctx['n_index']}, key + \`__1__\${key1}\`, node, this, null), key1);
@@ -13,7 +13,7 @@ exports[`t-key t-foreach with t-key switch component position 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['clist']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['clist']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`c\`] = k_block2[i1]; ctx[\`c\`] = v_block2[i1];
const key1 = ctx['c']; const key1 = ctx['c'];
const tKey_1 = ctx['key1']; const tKey_1 = ctx['key1'];
c_block2[i1] = withKey(comp1({key: ctx['c']+ctx['key1']}, tKey_1 + key + \`__1__\${key1}\`, node, this, null), tKey_1 + key1); c_block2[i1] = withKey(comp1({key: ctx['c']+ctx['key1']}, tKey_1 + key + \`__1__\${key1}\`, node, this, null), tKey_1 + key1);
@@ -44,26 +44,7 @@ exports[`t-model directive .trim modifier 1`] = `
let { text, createBlock, list, multi, html, toggler, comment } = bdom; let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { toNumber } = helpers; let { toNumber } = helpers;
let block1 = createBlock(\`<div><input block-property-0=\\"value\\" block-handler-1=\\"change\\"/><span><block-text-2/></span></div>\`); let block1 = createBlock(\`<div><input block-property-0=\\"value\\" block-handler-1=\\"input\\"/><span><block-text-2/></span></div>\`);
return function template(ctx, node, key = \\"\\") {
const bExpr1 = ctx['state'];
const expr1 = 'text';
let prop1 = bExpr1[expr1];
let hdlr1 = [(ev) => { bExpr1[expr1] = ev.target.value.trim(); }];
let txt1 = ctx['state'].text;
return block1([prop1, hdlr1, txt1]);
}
}"
`;
exports[`t-model directive .trim modifier implies .lazy modifier 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { toNumber } = helpers;
let block1 = createBlock(\`<div><input block-property-0=\\"value\\" block-handler-1=\\"change\\"/><span><block-text-2/></span></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
const bExpr1 = ctx['state']; const bExpr1 = ctx['state'];
@@ -215,7 +196,7 @@ exports[`t-model directive in a t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`thing\`] = k_block2[i1]; ctx[\`thing\`] = v_block2[i1];
const key1 = ctx['thing'].id; const key1 = ctx['thing'].id;
const bExpr1 = ctx['thing']; const bExpr1 = ctx['thing'];
const expr1 = 'f'; const expr1 = 'f';
@@ -242,7 +223,7 @@ exports[`t-model directive in a t-foreach, part 2 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`thing\`] = k_block2[i1]; ctx[\`thing\`] = v_block2[i1];
ctx[\`thing_index\`] = i1; ctx[\`thing_index\`] = i1;
const key1 = ctx['thing_index']; const key1 = ctx['thing_index'];
const bExpr1 = ctx['state']; const bExpr1 = ctx['state'];
@@ -270,7 +251,7 @@ exports[`t-model directive in a t-foreach, part 3 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['names']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['names']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`name\`] = k_block2[i1]; ctx[\`name\`] = v_block2[i1];
ctx[\`name_index\`] = i1; ctx[\`name_index\`] = i1;
const key1 = ctx['name_index']; const key1 = ctx['name_index'];
const bExpr1 = ctx['state'].values; const bExpr1 = ctx['state'].values;
@@ -395,7 +376,7 @@ exports[`t-model directive on an input, type=checkbox 1`] = `
let block1 = createBlock(\`<div><input type=\\"checkbox\\" block-property-0=\\"checked\\" block-handler-1=\\"input\\"/><span><block-child-0/><block-child-1/></span></div>\`); let block1 = createBlock(\`<div><input type=\\"checkbox\\" block-property-0=\\"checked\\" block-handler-1=\\"input\\"/><span><block-child-0/><block-child-1/></span></div>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
const bExpr1 = ctx['state']; const bExpr1 = ctx['state'];
const expr1 = 'flag'; const expr1 = 'flag';
let prop1 = bExpr1[expr1]; let prop1 = bExpr1[expr1];
@@ -504,7 +485,7 @@ exports[`t-model directive t-model with dynamic number values on select options
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].options);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].options);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`o\`] = k_block2[i1]; ctx[\`o\`] = v_block2[i1];
const key1 = ctx['o'].value; const key1 = ctx['o'].value;
let attr1 = ctx['o'].value; let attr1 = ctx['o'].value;
let attr2 = bValue1 === ctx['o'].value; let attr2 = bValue1 === ctx['o'].value;
@@ -605,7 +586,7 @@ exports[`t-model directive t-model with dynamic values on select options in fore
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['options']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['options']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`v\`] = k_block2[i1]; ctx[\`v\`] = v_block2[i1];
const key1 = ctx['v']; const key1 = ctx['v'];
let attr1 = ctx['v']; let attr1 = ctx['v'];
let attr2 = bValue1 === ctx['v']; let attr2 = bValue1 === ctx['v'];
@@ -632,7 +613,7 @@ exports[`t-model directive t-model with radio button group in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['options']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['options']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`opt\`] = k_block2[i1]; ctx[\`opt\`] = v_block2[i1];
const key1 = ctx['opt']; const key1 = ctx['opt'];
let prop1 = new String((ctx['opt']) === 0 ? 0 : ((ctx['opt']) || \\"\\")); let prop1 = new String((ctx['opt']) === 0 ? 0 : ((ctx['opt']) || \\"\\"));
let attr1 = ctx['opt']; let attr1 = ctx['opt'];
@@ -659,7 +640,7 @@ exports[`t-model directive two inputs in a div alternating with a t-if 1`] = `
let block3 = createBlock(\`<input class=\\"b\\" block-property-0=\\"value\\" block-handler-1=\\"input\\"/>\`); let block3 = createBlock(\`<input class=\\"b\\" block-property-0=\\"value\\" block-handler-1=\\"input\\"/>\`);
return function template(ctx, node, key = \\"\\") { return function template(ctx, node, key = \\"\\") {
let b2, b3; let b2,b3;
if (ctx['state'].flag) { if (ctx['state'].flag) {
const bExpr1 = ctx['state']; const bExpr1 = ctx['state'];
const expr1 = 'text1'; const expr1 = 'text1';
@@ -16,7 +16,7 @@ exports[`t-on t-on expression captured in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['arr']);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['arr']);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
const key1 = ctx['val']; const key1 = ctx['val'];
const v1 = ctx['otherState']; const v1 = ctx['otherState'];
const v2 = ctx['iter']; const v2 = ctx['iter'];
@@ -43,7 +43,7 @@ exports[`t-on t-on expression in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
ctx[\`val_index\`] = i1; ctx[\`val_index\`] = i1;
const key1 = ctx['val']; const key1 = ctx['val'];
let txt1 = ctx['val_index']; let txt1 = ctx['val_index'];
@@ -75,7 +75,7 @@ exports[`t-on t-on expression in t-foreach with t-set 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
ctx[\`val_index\`] = i1; ctx[\`val_index\`] = i1;
const key1 = ctx['val']; const key1 = ctx['val'];
setContextValue(ctx, \\"bossa\\", ctx['bossa']+'_'+ctx['val_index']); setContextValue(ctx, \\"bossa\\", ctx['bossa']+'_'+ctx['val_index']);
@@ -106,7 +106,7 @@ exports[`t-on t-on method call in t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values);; const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values);;
for (let i1 = 0; i1 < l_block2; i1++) { for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`val\`] = k_block2[i1]; ctx[\`val\`] = v_block2[i1];
ctx[\`val_index\`] = i1; ctx[\`val_index\`] = i1;
const key1 = ctx['val']; const key1 = ctx['val'];
let txt1 = ctx['val_index']; let txt1 = ctx['val_index'];
@@ -196,7 +196,7 @@ exports[`t-on t-on on components and t-foreach 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(['John','Raoul','Gérald']);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(['John','Raoul','Gérald']);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`name\`] = k_block1[i1]; ctx[\`name\`] = v_block1[i1];
const key1 = ctx['name']; const key1 = ctx['name'];
const v1 = ctx['this']; const v1 = ctx['this'];
const v2 = ctx['name']; const v2 = ctx['name'];
@@ -493,7 +493,7 @@ exports[`t-on t-on when first component child is an empty component 2`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['props'].list);; const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['props'].list);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`c\`] = k_block1[i1]; ctx[\`c\`] = v_block1[i1];
ctx[\`c_index\`] = i1; ctx[\`c_index\`] = i1;
const key1 = ctx['c_index']; const key1 = ctx['c_index'];
let txt1 = ctx['c']; let txt1 = ctx['c'];
@@ -17,7 +17,7 @@ exports[`components in t-out simple list 1`] = `
ctx = Object.create(ctx); ctx = Object.create(ctx);
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1,2]);; const [k_block1, v_block1, l_block1, c_block1] = prepareList([1,2]);;
for (let i1 = 0; i1 < l_block1; i1++) { for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`n\`] = k_block1[i1]; ctx[\`n\`] = v_block1[i1];
const key1 = ctx['n']; const key1 = ctx['n'];
ctx[\`blabla\`] = new LazyValue(value1, ctx, this, node, key1); ctx[\`blabla\`] = new LazyValue(value1, ctx, this, node, key1);
c_block1[i1] = withKey(safeOutput(ctx['blabla']), key1); c_block1[i1] = withKey(safeOutput(ctx['blabla']), key1);
+33 -52
View File
@@ -5,7 +5,6 @@ import {
nextAppError, nextAppError,
nextTick, nextTick,
snapshotEverything, snapshotEverything,
steps,
useLogLifecycle, useLogLifecycle,
} from "../helpers"; } from "../helpers";
import { markup } from "../../src/runtime/utils"; import { markup } from "../../src/runtime/utils";
@@ -869,26 +868,19 @@ describe("basics", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(Object.keys(parent.__owl__.children).length).toStrictEqual(1); expect(Object.keys(parent.__owl__.children).length).toStrictEqual(1);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", ]).toBeLogged();
]
`);
parent.ifVar = false; parent.ifVar = false;
parent.render(); parent.render();
await nextTick(); await nextTick();
expect(Object.keys(parent.__owl__.children).length).toStrictEqual(0); expect(Object.keys(parent.__owl__.children).length).toStrictEqual(0);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Child:willUnmount", "Child:willDestroy"]).toBeLogged();
Array [
"Child:willUnmount",
"Child:willDestroy",
]
`);
}); });
test("component children doesn't leak (t-key case)", async () => { test("component children doesn't leak (t-key case)", async () => {
@@ -907,31 +899,27 @@ describe("basics", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(Object.keys(parent.__owl__.children).length).toStrictEqual(1); expect(Object.keys(parent.__owl__.children).length).toStrictEqual(1);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", ]).toBeLogged();
]
`);
parent.keyVar = 2; parent.keyVar = 2;
parent.render(); parent.render();
await nextTick(); await nextTick();
expect(Object.keys(parent.__owl__.children).length).toStrictEqual(1); expect(Object.keys(parent.__owl__.children).length).toStrictEqual(1);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Child:mounted",
"Child:mounted", ]).toBeLogged();
]
`);
}); });
test("GrandChild display is controlled by its GrandParent", async () => { test("GrandChild display is controlled by its GrandParent", async () => {
@@ -955,27 +943,20 @@ describe("basics", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("<div></div>"); expect(fixture.innerHTML).toBe("<div></div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "GrandChild:setup",
"GrandChild:setup", "GrandChild:willStart",
"GrandChild:willStart", "GrandChild:willRender",
"GrandChild:willRender", "GrandChild:rendered",
"GrandChild:rendered", "GrandChild:mounted",
"GrandChild:mounted", ]).toBeLogged();
]
`);
parent.displayGrandChild = false; parent.displayGrandChild = false;
parent.render(); parent.render();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe(""); expect(fixture.innerHTML).toBe("");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["GrandChild:willUnmount", "GrandChild:willDestroy"]).toBeLogged();
Array [
"GrandChild:willUnmount",
"GrandChild:willDestroy",
]
`);
}); });
}); });
@@ -1043,7 +1024,7 @@ describe("support svg components", () => {
await mount(Svg, fixture); await mount(Svg, fixture);
expect(fixture.innerHTML).toBe( expect(fixture.innerHTML).toBe(
'<svg xmlns="http://www.w3.org/2000/svg"><g xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"></circle></g></svg>' '<svg><g><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"></circle></g></svg>'
); );
}); });
}); });
File diff suppressed because it is too large Load Diff
+133 -217
View File
@@ -19,9 +19,8 @@ import {
snapshotEverything, snapshotEverything,
useLogLifecycle, useLogLifecycle,
nextAppError, nextAppError,
steps,
} from "../helpers"; } from "../helpers";
import { OwlError } from "../../src/common/owl_error"; import { OwlError } from "../../src/runtime/error_handling";
let fixture: HTMLElement; let fixture: HTMLElement;
@@ -144,66 +143,6 @@ describe("basics", () => {
); );
}); });
test("display a nice error if the root component template fails to compile", async () => {
// This is a special case: mount throws synchronously and we don't have any
// node which can handle the error, hence the different structure of this test
class Comp extends Component {
static template = xml`<div t-att-class="a b">test</div>`;
}
const app = new App(Comp);
let error: Error;
try {
await app.mount(fixture);
} catch (e) {
error = e as Error;
}
const expectedErrorMessage = `Failed to compile anonymous template: Unexpected identifier
generated code:
function(app, bdom, helpers) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div block-attribute-0="class">test</div>\`);
return function template(ctx, node, key = "") {
let attr1 = ctx['a']ctx['b'];
return block1([attr1]);
}
}`;
expect(error!).toBeDefined();
expect(error!.message).toBe(expectedErrorMessage);
});
test("display a nice error if a non-root component template fails to compile", async () => {
class Child extends Component {
static template = xml`<div t-att-class="a b">test</div>`;
}
class Parent extends Component {
static components = { Child };
static template = xml`<Child/>`;
}
const expectedErrorMessage = `Failed to compile anonymous template: Unexpected identifier
generated code:
function(app, bdom, helpers) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div block-attribute-0="class">test</div>\`);
return function template(ctx, node, key = "") {
let attr1 = ctx['a']ctx['b'];
return block1([attr1]);
}
}`;
const app = new App(Parent as typeof Component);
let error: Error;
const mountProm = app.mount(fixture).catch((e: Error) => (error = e));
await expect(nextAppError(app)).resolves.toThrow(expectedErrorMessage);
await mountProm;
expect(error!).toBeDefined();
expect(error!.message).toBe(expectedErrorMessage);
});
test("simple catchError", async () => { test("simple catchError", async () => {
class Boom extends Component { class Boom extends Component {
static template = xml`<div t-esc="a.b.c"/>`; static template = xml`<div t-esc="a.b.c"/>`;
@@ -949,28 +888,26 @@ describe("can catch errors", () => {
} }
await mount(Root, fixture); await mount(Root, fixture);
expect(fixture.innerHTML).toBe("<div><div>Error handled</div></div>"); expect(fixture.innerHTML).toBe("<div><div>Error handled</div></div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Root:setup",
"Root:setup", "Root:willStart",
"Root:willStart", "Root:willRender",
"Root:willRender", "ErrorBoundary:setup",
"ErrorBoundary:setup", "ErrorBoundary:willStart",
"ErrorBoundary:willStart", "Root:rendered",
"Root:rendered", "ErrorBoundary:willRender",
"ErrorBoundary:willRender", "ErrorComponent:setup",
"ErrorComponent:setup", "ErrorComponent:willStart",
"ErrorComponent:willStart", "ErrorBoundary:rendered",
"ErrorBoundary:rendered", "ErrorComponent:willRender",
"ErrorComponent:willRender", "ErrorComponent:rendered",
"ErrorComponent:rendered", "ErrorComponent:mounted",
"ErrorComponent:mounted", "boom",
"boom", "ErrorBoundary:willRender",
"ErrorBoundary:willRender", "ErrorBoundary:rendered",
"ErrorBoundary:rendered", "ErrorBoundary:mounted",
"ErrorBoundary:mounted", "Root:mounted",
"Root:mounted", ]).toBeLogged();
]
`);
expect(mockConsoleError).toBeCalledTimes(0); expect(mockConsoleError).toBeCalledTimes(0);
expect(mockConsoleWarn).toBeCalledTimes(0); expect(mockConsoleWarn).toBeCalledTimes(0);
}); });
@@ -1001,23 +938,21 @@ describe("can catch errors", () => {
} }
await mount(Root, fixture); await mount(Root, fixture);
expect(fixture.innerHTML).toBe("<div>Error handled</div>"); expect(fixture.innerHTML).toBe("<div>Error handled</div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Root:setup",
"Root:setup", "Root:willStart",
"Root:willStart", "Root:willRender",
"Root:willRender", "ErrorComponent:setup",
"ErrorComponent:setup", "ErrorComponent:willStart",
"ErrorComponent:willStart", "Root:rendered",
"Root:rendered", "ErrorComponent:willRender",
"ErrorComponent:willRender", "ErrorComponent:rendered",
"ErrorComponent:rendered", "ErrorComponent:mounted",
"ErrorComponent:mounted", "boom",
"boom", "Root:willRender",
"Root:willRender", "Root:rendered",
"Root:rendered", "Root:mounted",
"Root:mounted", ]).toBeLogged();
]
`);
expect(mockConsoleError).toBeCalledTimes(0); expect(mockConsoleError).toBeCalledTimes(0);
expect(mockConsoleWarn).toBeCalledTimes(0); expect(mockConsoleWarn).toBeCalledTimes(0);
}); });
@@ -1064,33 +999,31 @@ describe("can catch errors", () => {
} }
await mount(A, fixture); await mount(A, fixture);
expect(fixture.innerHTML).toBe("<div><div>Error handled</div></div>"); expect(fixture.innerHTML).toBe("<div><div>Error handled</div></div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "A:setup",
"A:setup", "A:willStart",
"A:willStart", "A:willRender",
"A:willRender", "B:setup",
"B:setup", "B:willStart",
"B:willStart", "A:rendered",
"A:rendered", "B:willRender",
"B:willRender", "C:setup",
"C:setup", "C:willStart",
"C:willStart", "B:rendered",
"B:rendered", "C:willRender",
"C:willRender", "Boom:setup",
"Boom:setup", "Boom:willStart",
"Boom:willStart", "C:rendered",
"C:rendered", "Boom:willRender",
"Boom:willRender", "Boom:rendered",
"Boom:rendered", "Boom:mounted",
"Boom:mounted", "boom",
"boom", "C:willRender",
"C:willRender", "C:rendered",
"C:rendered", "C:mounted",
"C:mounted", "B:mounted",
"B:mounted", "A:mounted",
"A:mounted", ]).toBeLogged();
]
`);
expect(mockConsoleError).toBeCalledTimes(0); expect(mockConsoleError).toBeCalledTimes(0);
expect(mockConsoleWarn).toBeCalledTimes(0); expect(mockConsoleWarn).toBeCalledTimes(0);
}); });
@@ -1137,33 +1070,31 @@ describe("can catch errors", () => {
} }
await mount(Root, fixture); await mount(Root, fixture);
expect(fixture.innerHTML).toBe("<div>OK<div>Error handled</div></div>"); expect(fixture.innerHTML).toBe("<div>OK<div>Error handled</div></div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Root:setup",
"Root:setup", "Root:willStart",
"Root:willStart", "Root:willRender",
"Root:willRender", "OK:setup",
"OK:setup", "OK:willStart",
"OK:willStart", "ErrorBoundary:setup",
"ErrorBoundary:setup", "ErrorBoundary:willStart",
"ErrorBoundary:willStart", "Root:rendered",
"Root:rendered", "OK:willRender",
"OK:willRender", "OK:rendered",
"OK:rendered", "ErrorBoundary:willRender",
"ErrorBoundary:willRender", "ErrorComponent:setup",
"ErrorComponent:setup", "ErrorComponent:willStart",
"ErrorComponent:willStart", "ErrorBoundary:rendered",
"ErrorBoundary:rendered", "ErrorComponent:willRender",
"ErrorComponent:willRender", "ErrorComponent:rendered",
"ErrorComponent:rendered", "ErrorComponent:mounted",
"ErrorComponent:mounted", "boom",
"boom", "ErrorBoundary:willRender",
"ErrorBoundary:willRender", "ErrorBoundary:rendered",
"ErrorBoundary:rendered", "ErrorBoundary:mounted",
"ErrorBoundary:mounted", "OK:mounted",
"OK:mounted", "Root:mounted",
"Root:mounted", ]).toBeLogged();
]
`);
expect(mockConsoleError).toBeCalledTimes(0); expect(mockConsoleError).toBeCalledTimes(0);
expect(mockConsoleWarn).toBeCalledTimes(0); expect(mockConsoleWarn).toBeCalledTimes(0);
}); });
@@ -1490,39 +1421,35 @@ describe("can catch errors", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("1<div>abc</div>"); expect(fixture.innerHTML).toBe("1<div>abc</div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = false; parent.state.hasChild = false;
await nextTick(); await nextTick();
await nextTick(); await nextTick();
await nextTick(); await nextTick();
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:patched",
"Parent:patched", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
expect(fixture.innerHTML).toBe("2"); expect(fixture.innerHTML).toBe("2");
}); });
@@ -1555,15 +1482,13 @@ describe("can catch errors", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("1"); expect(fixture.innerHTML).toBe("1");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = true; parent.state.hasChild = true;
await nextMicroTick(); await nextMicroTick();
@@ -1571,35 +1496,26 @@ describe("can catch errors", () => {
await nextMicroTick(); await nextMicroTick();
await nextMicroTick(); await nextMicroTick();
await nextMicroTick(); await nextMicroTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", ]).toBeLogged();
]
`);
parent.state.hasChild = false; parent.state.hasChild = false;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Child:willDestroy",
"Child:willDestroy", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", ]).toBeLogged();
]
`);
expect(fixture.innerHTML).toBe("1"); expect(fixture.innerHTML).toBe("1");
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Parent:willPatch", "Parent:patched"]).toBeLogged();
Array [
"Parent:willPatch",
"Parent:patched",
]
`);
expect(fixture.innerHTML).toBe("2"); expect(fixture.innerHTML).toBe("2");
}); });
}); });
-52
View File
@@ -641,56 +641,6 @@ describe("hooks", () => {
]); ]);
}); });
test("effect types are inferred from dependencies", async () => {
// @ts-ignore (declared but never used)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class MyComponent extends Component {
static template = xml`<div/>`;
setup() {
useEffect(
(a, b) => {
expectType<number>(a);
expectType<string>(b);
},
() => [3, "hello"]
);
}
}
});
test("effect type allows an effect with partial dependencies parameters", async () => {
// @ts-ignore (declared but never used)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class MyComponent extends Component {
static template = xml`<div/>`;
setup() {
useEffect(
(a) => {
expectType<number>(a);
},
() => [3, "hello"]
);
}
}
});
test("effect type allows an effect with no dependency parameter", async () => {
// @ts-ignore (declared but never used)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class MyComponent extends Component {
static template = xml`<div/>`;
setup() {
useEffect(
() => {},
() => [3, "hello"]
);
}
}
});
test("properly behaves when the effect function throws", async () => { test("properly behaves when the effect function throws", async () => {
let originalconsoleError = console.error; let originalconsoleError = console.error;
let originalconsoleWarn = console.warn; let originalconsoleWarn = console.warn;
@@ -723,5 +673,3 @@ describe("hooks", () => {
}); });
}); });
}); });
function expectType<T>(t: T) {}
+337 -430
View File
@@ -17,7 +17,6 @@ import {
nextMicroTick, nextMicroTick,
nextTick, nextTick,
snapshotEverything, snapshotEverything,
steps,
useLogLifecycle, useLogLifecycle,
} from "../helpers"; } from "../helpers";
@@ -456,51 +455,45 @@ describe("lifecycle hooks", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("<div><span>0</span></div>"); expect(fixture.innerHTML).toBe("<div><span>0</span></div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.increment(); parent.increment();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<div><span>1</span></div>"); expect(fixture.innerHTML).toBe("<div><span>1</span></div>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:willUpdateProps",
"Child:willUpdateProps", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willPatch",
"Child:willPatch", "Child:patched",
"Child:patched", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
parent.toggleSubWidget(); parent.toggleSubWidget();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe(""); expect(fixture.innerHTML).toBe("");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("hooks are called in proper order in widget creation/destruction", async () => { test("hooks are called in proper order in widget creation/destruction", async () => {
@@ -521,30 +514,26 @@ describe("lifecycle hooks", () => {
const app = new App(Parent); const app = new App(Parent);
await app.mount(fixture); await app.mount(fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
app.destroy(); app.destroy();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willUnmount",
"Parent:willUnmount", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:willDestroy",
"Parent:willDestroy", ]).toBeLogged();
]
`);
}); });
test("willUpdateProps hook is called", async () => { test("willUpdateProps hook is called", async () => {
@@ -643,30 +632,26 @@ describe("lifecycle hooks", () => {
const app = new App(Parent); const app = new App(Parent);
await app.mount(fixture); await app.mount(fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
app.destroy(); app.destroy();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willUnmount",
"Parent:willUnmount", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:willDestroy",
"Parent:willDestroy", ]).toBeLogged();
]
`);
}); });
test("lifecycle semantics, part 2", async () => { test("lifecycle semantics, part 2", async () => {
@@ -695,48 +680,42 @@ describe("lifecycle hooks", () => {
const app = new App(Parent); const app = new App(Parent);
const parent = await app.mount(fixture); const parent = await app.mount(fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = true; parent.state.hasChild = true;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "GrandChild:setup",
"GrandChild:setup", "GrandChild:willStart",
"GrandChild:willStart", "Child:rendered",
"Child:rendered", "GrandChild:willRender",
"GrandChild:willRender", "GrandChild:rendered",
"GrandChild:rendered", "Parent:willPatch",
"Parent:willPatch", "GrandChild:mounted",
"GrandChild:mounted", "Child:mounted",
"Child:mounted", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
app.destroy(); app.destroy();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willUnmount",
"Parent:willUnmount", "Child:willUnmount",
"Child:willUnmount", "GrandChild:willUnmount",
"GrandChild:willUnmount", "GrandChild:willDestroy",
"GrandChild:willDestroy", "Child:willDestroy",
"Child:willDestroy", "Parent:willDestroy",
"Parent:willDestroy", ]).toBeLogged();
]
`);
}); });
test("lifecycle semantics, part 3", async () => { test("lifecycle semantics, part 3", async () => {
@@ -765,26 +744,19 @@ describe("lifecycle hooks", () => {
const app = new App(Parent); const app = new App(Parent);
const parent = await app.mount(fixture); const parent = await app.mount(fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = true; parent.state.hasChild = true;
// immediately destroy everything // immediately destroy everything
app.destroy(); app.destroy();
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Parent:willUnmount", "Parent:willDestroy"]).toBeLogged();
Array [
"Parent:willUnmount",
"Parent:willDestroy",
]
`);
}); });
test("lifecycle semantics, part 4", async () => { test("lifecycle semantics, part 4", async () => {
@@ -817,40 +789,34 @@ describe("lifecycle hooks", () => {
const app = new App(Parent); const app = new App(Parent);
const parent = await app.mount(fixture); const parent = await app.mount(fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = true; parent.state.hasChild = true;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "GrandChild:setup",
"GrandChild:setup", "GrandChild:willStart",
"GrandChild:willStart", "Child:rendered",
"Child:rendered", ]).toBeLogged();
]
`);
app.destroy(); app.destroy();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willUnmount",
"Parent:willUnmount", "GrandChild:willDestroy",
"GrandChild:willDestroy", "Child:willDestroy",
"Child:willDestroy", "Parent:willDestroy",
"Parent:willDestroy", ]).toBeLogged();
]
`);
}); });
test("lifecycle semantics, part 5", async () => { test("lifecycle semantics, part 5", async () => {
@@ -871,33 +837,29 @@ describe("lifecycle hooks", () => {
} }
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = false; parent.state.hasChild = false;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("lifecycle semantics, part 6", async () => { test("lifecycle semantics, part 6", async () => {
@@ -918,36 +880,32 @@ describe("lifecycle hooks", () => {
} }
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.value = 2; parent.state.value = 2;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:willUpdateProps",
"Child:willUpdateProps", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willPatch",
"Child:willPatch", "Child:patched",
"Child:patched", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("onWillRender", async () => { test("onWillRender", async () => {
@@ -979,53 +937,43 @@ describe("lifecycle hooks", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("<button>1</button>"); expect(fixture.innerHTML).toBe("<button>1</button>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.value++; // to block child render parent.state.value++; // to block child render
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Parent:willRender", "Child:willUpdateProps", "Parent:rendered"]).toBeLogged();
Array [
"Parent:willRender",
"Child:willUpdateProps",
"Parent:rendered",
]
`);
fixture.querySelector("button")!.click(); fixture.querySelector("button")!.click();
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(`Array []`); expect([]).toBeLogged();
fixture.querySelector("button")!.click(); fixture.querySelector("button")!.click();
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(`Array []`); expect([]).toBeLogged();
expect(fixture.innerHTML).toBe("<button>1</button>"); expect(fixture.innerHTML).toBe("<button>1</button>");
def.resolve(); def.resolve();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<button>3</button>"); expect(fixture.innerHTML).toBe("<button>3</button>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willPatch",
"Child:willPatch", "Child:patched",
"Child:patched", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
// TODO: rename (remove? seems covered by lifecycle semantics) // TODO: rename (remove? seems covered by lifecycle semantics)
@@ -1106,54 +1054,50 @@ describe("lifecycle hooks", () => {
await mount(A, fixture); await mount(A, fixture);
expect(fixture.innerHTML).toBe(`<div>A<div>B</div><div>C<div>D</div><div>E</div></div></div>`); expect(fixture.innerHTML).toBe(`<div>A<div>B</div><div>C<div>D</div><div>E</div></div></div>`);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "A:setup",
"A:setup", "A:willStart",
"A:willStart", "A:willRender",
"A:willRender", "B:setup",
"B:setup", "B:willStart",
"B:willStart", "C:setup",
"C:setup", "C:willStart",
"C:willStart", "A:rendered",
"A:rendered", "B:willRender",
"B:willRender", "B:rendered",
"B:rendered", "C:willRender",
"C:willRender", "D:setup",
"D:setup", "D:willStart",
"D:willStart", "E:setup",
"E:setup", "E:willStart",
"E:willStart", "C:rendered",
"C:rendered", "D:willRender",
"D:willRender", "D:rendered",
"D:rendered", "E:willRender",
"E:willRender", "E:rendered",
"E:rendered", "E:mounted",
"E:mounted", "D:mounted",
"D:mounted", "C:mounted",
"C:mounted", "B:mounted",
"B:mounted", "A:mounted",
"A:mounted", ]).toBeLogged();
]
`);
// update // update
c!.state.flag = false; c!.state.flag = false;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "C:willRender",
"C:willRender", "F:setup",
"F:setup", "F:willStart",
"F:willStart", "C:rendered",
"C:rendered", "F:willRender",
"F:willRender", "F:rendered",
"F:rendered", "C:willPatch",
"C:willPatch", "E:willUnmount",
"E:willUnmount", "E:willDestroy",
"E:willDestroy", "F:mounted",
"F:mounted", "C:patched",
"C:patched", ]).toBeLogged();
]
`);
}); });
test("mounted hook is called on every mount, not just the first one", async () => { test("mounted hook is called on every mount, not just the first one", async () => {
@@ -1174,49 +1118,43 @@ describe("lifecycle hooks", () => {
} }
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.hasChild = false; parent.state.hasChild = false;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
parent.state.hasChild = true; parent.state.hasChild = true;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:mounted",
"Child:mounted", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("render in mounted", async () => { test("render in mounted", async () => {
@@ -1234,26 +1172,19 @@ describe("lifecycle hooks", () => {
await mount(Parent, fixture); await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("<span></span>"); expect(fixture.innerHTML).toBe("<span></span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", ]).toBeLogged();
]
`);
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<span>Patched</span>"); expect(fixture.innerHTML).toBe("<span>Patched</span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Parent:willPatch", "Parent:patched"]).toBeLogged();
Array [
"Parent:willPatch",
"Parent:patched",
]
`);
}); });
test("render in patched", async () => { test("render in patched", async () => {
@@ -1274,38 +1205,29 @@ describe("lifecycle hooks", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("<span></span>"); expect(fixture.innerHTML).toBe("<span></span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.render(); parent.render();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<span></span>"); expect(fixture.innerHTML).toBe("<span></span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", ]).toBeLogged();
]
`);
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<span>Patched</span>"); expect(fixture.innerHTML).toBe("<span>Patched</span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Parent:willPatch", "Parent:patched"]).toBeLogged();
Array [
"Parent:willPatch",
"Parent:patched",
]
`);
}); });
test("render in willPatch", async () => { test("render in willPatch", async () => {
@@ -1326,38 +1248,29 @@ describe("lifecycle hooks", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("<span></span>"); expect(fixture.innerHTML).toBe("<span></span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.render(); parent.render();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<span></span>"); expect(fixture.innerHTML).toBe("<span></span>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", ]).toBeLogged();
]
`);
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Parent:willPatch", "Parent:patched"]).toBeLogged();
Array [
"Parent:willPatch",
"Parent:patched",
]
`);
expect(fixture.innerHTML).toBe("<span>Patched</span>"); expect(fixture.innerHTML).toBe("<span>Patched</span>");
}); });
@@ -1400,21 +1313,19 @@ describe("lifecycle hooks", () => {
await nextTick(); await nextTick();
app.destroy(); app.destroy();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "onWillStart",
"onWillStart", "onWillRender",
"onWillRender", "onRendered",
"onRendered", "onMounted",
"onMounted", "onWillUpdateProps",
"onWillUpdateProps", "onWillRender",
"onWillRender", "onRendered",
"onRendered", "onWillPatch",
"onWillPatch", "onPatched",
"onPatched", "onWillUnmount",
"onWillUnmount", "onWillDestroy",
"onWillDestroy", ]).toBeLogged();
]
`);
}); });
test("destroy new children before being mountged", async () => { test("destroy new children before being mountged", async () => {
@@ -1446,30 +1357,26 @@ describe("lifecycle hooks", () => {
const app = new App(Parent); const app = new App(Parent);
const parent = await app.mount(fixture); const parent = await app.mount(fixture);
expect(fixture.innerHTML).toBe("beforeafter"); expect(fixture.innerHTML).toBe("beforeafter");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.flag = true; parent.state.flag = true;
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe(""); expect(fixture.innerHTML).toBe("");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Parent:willUnmount",
"Parent:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:willDestroy",
"Parent:willDestroy", ]).toBeLogged();
]
`);
}); });
}); });
+64 -76
View File
@@ -1,5 +1,5 @@
import { Component, mount, onWillUpdateProps, useState, xml } from "../../src"; import { Component, mount, onWillUpdateProps, useState, xml } from "../../src";
import { makeTestFixture, nextTick, snapshotEverything, steps, useLogLifecycle } from "../helpers"; import { makeTestFixture, nextTick, snapshotEverything, useLogLifecycle } from "../helpers";
let fixture: HTMLElement; let fixture: HTMLElement;
@@ -272,30 +272,26 @@ test("bound functions are considered 'alike'", async () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("1child"); expect(fixture.innerHTML).toBe("1child");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.val = 3; parent.state.val = 3;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
expect(fixture.innerHTML).toBe("3child"); expect(fixture.innerHTML).toBe("3child");
}); });
@@ -334,33 +330,29 @@ test(".alike suffix in a simple case", async () => {
} }
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
expect(fixture.innerHTML).toBe("01"); expect(fixture.innerHTML).toBe("01");
parent.state.counter++; parent.state.counter++;
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("11"); expect(fixture.innerHTML).toBe("11");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test(".alike suffix in a list", async () => { test(".alike suffix in a list", async () => {
@@ -396,40 +388,36 @@ test(".alike suffix in a list", async () => {
} }
await mount(Parent, fixture); await mount(Parent, fixture);
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Todo:setup",
"Todo:setup", "Todo:willStart",
"Todo:willStart", "Todo:setup",
"Todo:setup", "Todo:willStart",
"Todo:willStart", "Parent:rendered",
"Parent:rendered", "Todo:willRender",
"Todo:willRender", "Todo:rendered",
"Todo:rendered", "Todo:willRender",
"Todo:willRender", "Todo:rendered",
"Todo:rendered", "Todo:mounted",
"Todo:mounted", "Todo:mounted",
"Todo:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
expect(fixture.innerHTML).toBe("<button>1</button><button>2V</button>"); expect(fixture.innerHTML).toBe("<button>1</button><button>2V</button>");
fixture.querySelector("button")?.click(); fixture.querySelector("button")?.click();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<button>1V</button><button>2V</button>"); expect(fixture.innerHTML).toBe("<button>1V</button><button>2V</button>");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Todo:willRender",
"Todo:willRender", "Todo:rendered",
"Todo:rendered", "Todo:willPatch",
"Todo:willPatch", "Todo:patched",
"Todo:patched", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
+2 -2
View File
@@ -594,7 +594,7 @@ describe("props validation", () => {
test("props: can be defined with a boolean", async () => { test("props: can be defined with a boolean", async () => {
class SubComp extends Component { class SubComp extends Component {
static props = { message: true } as const; static props = { message: true };
} }
expect(() => { expect(() => {
validateProps(SubComp as any, {}); validateProps(SubComp as any, {});
@@ -636,7 +636,7 @@ describe("props validation", () => {
test("props: extra props cause an error, part 2", async () => { test("props: extra props cause an error, part 2", async () => {
class SubComp extends Component { class SubComp extends Component {
static props = { message: true } as const; static props = { message: true };
} }
expect(() => { expect(() => {
validateProps(SubComp as any, { message: 1, flag: true }); validateProps(SubComp as any, { message: 1, flag: true });
+21 -25
View File
@@ -9,7 +9,7 @@ import {
xml, xml,
toRaw, toRaw,
} from "../../src"; } from "../../src";
import { makeTestFixture, nextTick, snapshotEverything, steps, useLogLifecycle } from "../helpers"; import { makeTestFixture, nextTick, snapshotEverything, useLogLifecycle } from "../helpers";
let fixture: HTMLElement; let fixture: HTMLElement;
@@ -175,34 +175,30 @@ describe("reactivity in lifecycle", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("2"); expect(fixture.innerHTML).toBe("2");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.content = null; parent.state.content = null;
parent.state.renderChild = false; parent.state.renderChild = false;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willUnmount",
"Child:willUnmount", "Child:willDestroy",
"Child:willDestroy", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("Component is automatically subscribed to reactive object received as prop", async () => { test("Component is automatically subscribed to reactive object received as prop", async () => {
+162 -217
View File
@@ -6,7 +6,6 @@ import {
useLogLifecycle, useLogLifecycle,
makeDeferred, makeDeferred,
nextMicroTick, nextMicroTick,
steps,
} from "../helpers"; } from "../helpers";
let fixture: HTMLElement; let fixture: HTMLElement;
@@ -42,32 +41,28 @@ describe("rendering semantics", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("Achild"); expect(fixture.innerHTML).toBe("Achild");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.value = "B"; parent.state.value = "B";
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("Bchild"); expect(fixture.innerHTML).toBe("Bchild");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("can force a render to update sub tree", async () => { test("can force a render to update sub tree", async () => {
@@ -172,20 +167,18 @@ describe("rendering semantics", () => {
const parent = await mount(Parent, fixture, { env }); const parent = await mount(Parent, fixture, { env });
expect(fixture.innerHTML).toBe("parentAchild3"); expect(fixture.innerHTML).toBe("parentAchild3");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
value = 4; value = 4;
parent.render(true); parent.render(true);
@@ -194,34 +187,30 @@ describe("rendering semantics", () => {
await nextMicroTick(); await nextMicroTick();
await nextMicroTick(); await nextMicroTick();
await nextMicroTick(); await nextMicroTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:willUpdateProps",
"Child:willUpdateProps", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", ]).toBeLogged();
]
`);
parent.state.value = "B"; parent.state.value = "B";
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("parentBchild4"); expect(fixture.innerHTML).toBe("parentBchild4");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Child:willUpdateProps",
"Child:willUpdateProps", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Parent:willPatch",
"Parent:willPatch", "Child:willPatch",
"Child:willPatch", "Child:patched",
"Child:patched", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
test("props are reactive", async () => { test("props are reactive", async () => {
@@ -246,32 +235,23 @@ describe("rendering semantics", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("1"); expect(fixture.innerHTML).toBe("1");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.b = 3; parent.state.b = 3;
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("3"); expect(fixture.innerHTML).toBe("3");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Child:willRender", "Child:rendered", "Child:willPatch", "Child:patched"]).toBeLogged();
Array [
"Child:willRender",
"Child:rendered",
"Child:willPatch",
"Child:patched",
]
`);
}); });
test("props are reactive (nested prop)", async () => { test("props are reactive (nested prop)", async () => {
@@ -298,48 +278,37 @@ describe("rendering semantics", () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("1"); expect(fixture.innerHTML).toBe("1");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.b.c = 3; // parent is now subscribed to 'b' key parent.state.b.c = 3; // parent is now subscribed to 'b' key
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("3"); expect(fixture.innerHTML).toBe("3");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["Child:willRender", "Child:rendered", "Child:willPatch", "Child:patched"]).toBeLogged();
Array [
"Child:willRender",
"Child:rendered",
"Child:willPatch",
"Child:patched",
]
`);
parent.state.b = { c: 444 }; // triggers a parent and a child render parent.state.b = { c: 444 }; // triggers a parent and a child render
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("444"); expect(fixture.innerHTML).toBe("444");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", "Child:willPatch",
"Child:willPatch", "Child:patched",
"Child:patched", ]).toBeLogged();
]
`);
}); });
test("works as expected for dynamic number of props", async () => { test("works as expected for dynamic number of props", async () => {
@@ -397,45 +366,41 @@ describe("rendering semantics", () => {
const parent = await mount(A, fixture); const parent = await mount(A, fixture);
expect(fixture.innerHTML).toBe("11"); expect(fixture.innerHTML).toBe("11");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "A:setup",
"A:setup", "A:willStart",
"A:willStart", "A:willRender",
"A:willRender", "B:setup",
"B:setup", "B:willStart",
"B:willStart", "A:rendered",
"A:rendered", "B:willRender",
"B:willRender", "C:setup",
"C:setup", "C:willStart",
"C:willStart", "B:rendered",
"B:rendered", "C:willRender",
"C:willRender", "C:rendered",
"C:rendered", "C:mounted",
"C:mounted", "B:mounted",
"B:mounted", "A:mounted",
"A:mounted", ]).toBeLogged();
]
`);
parent.state.obj.val = 3; parent.state.obj.val = 3;
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("33"); expect(fixture.innerHTML).toBe("33");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "A:willRender",
"A:willRender", "A:rendered",
"A:rendered", "C:willRender",
"C:willRender", "C:rendered",
"C:rendered", "A:willPatch",
"A:willPatch", "A:patched",
"A:patched", "C:willPatch",
"C:willPatch", "C:patched",
"C:patched", ]).toBeLogged();
]
`);
def.resolve(); def.resolve();
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(`Array []`); expect([]).toBeLogged();
}); });
}); });
@@ -466,67 +431,51 @@ test("force render in case of existing render", async () => {
} }
const parent = await mount(A, fixture); const parent = await mount(A, fixture);
expect(fixture.innerHTML).toBe("C1"); expect(fixture.innerHTML).toBe("C1");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "A:setup",
"A:setup", "A:willStart",
"A:willStart", "A:willRender",
"A:willRender", "B:setup",
"B:setup", "B:willStart",
"B:willStart", "A:rendered",
"A:rendered", "B:willRender",
"B:willRender", "C:setup",
"C:setup", "C:willStart",
"C:willStart", "B:rendered",
"B:rendered", "C:willRender",
"C:willRender", "C:rendered",
"C:rendered", "C:mounted",
"C:mounted", "B:mounted",
"B:mounted", "A:mounted",
"A:mounted", ]).toBeLogged();
]
`);
// trigger a new rendering, blocked in B // trigger a new rendering, blocked in B
parent.state.val = 2; parent.state.val = 2;
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
Array [
"A:willRender",
"B:willUpdateProps",
"A:rendered",
]
`);
// initiate a new render with deep=true. it should cancel the current render // initiate a new render with deep=true. it should cancel the current render
// and also be blocked in B // and also be blocked in B
parent.render(true); parent.render(true);
await nextTick(); await nextTick();
expect(steps.splice(0)).toMatchInlineSnapshot(` expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
Array [
"A:willRender",
"B:willUpdateProps",
"A:rendered",
]
`);
def.resolve(); def.resolve();
await nextTick(); await nextTick();
// we check here that the render reaches C (so, that it was properly forced) // we check here that the render reaches C (so, that it was properly forced)
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "B:willRender",
"B:willRender", "C:willUpdateProps",
"C:willUpdateProps", "B:rendered",
"B:rendered", "C:willRender",
"C:willRender", "C:rendered",
"C:rendered", "A:willPatch",
"A:willPatch", "B:willPatch",
"B:willPatch", "C:willPatch",
"C:willPatch", "C:patched",
"C:patched", "B:patched",
"B:patched", "A:patched",
"A:patched", ]).toBeLogged();
]
`);
}); });
test("children, default props and renderings", async () => { test("children, default props and renderings", async () => {
@@ -554,30 +503,26 @@ test("children, default props and renderings", async () => {
const parent = await mount(Parent, fixture); const parent = await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("Achild"); expect(fixture.innerHTML).toBe("Achild");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:setup",
"Parent:setup", "Parent:willStart",
"Parent:willStart", "Parent:willRender",
"Parent:willRender", "Child:setup",
"Child:setup", "Child:willStart",
"Child:willStart", "Parent:rendered",
"Parent:rendered", "Child:willRender",
"Child:willRender", "Child:rendered",
"Child:rendered", "Child:mounted",
"Child:mounted", "Parent:mounted",
"Parent:mounted", ]).toBeLogged();
]
`);
parent.state.value = "B"; parent.state.value = "B";
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("Bchild"); expect(fixture.innerHTML).toBe("Bchild");
expect(steps.splice(0)).toMatchInlineSnapshot(` expect([
Array [ "Parent:willRender",
"Parent:willRender", "Parent:rendered",
"Parent:rendered", "Parent:willPatch",
"Parent:willPatch", "Parent:patched",
"Parent:patched", ]).toBeLogged();
]
`);
}); });
-25
View File
@@ -1673,31 +1673,6 @@ describe("slots", () => {
expect(fixture.innerHTML).toBe("<div><div><p>Ablip</p><div><p>Bblip</p></div></div></div>"); expect(fixture.innerHTML).toBe("<div><div><p>Ablip</p><div><p>Bblip</p></div></div></div>");
}); });
test("named slot inside named slot in t-component", async () => {
class Child extends Component {
static template = xml`<t t-slot="brol"/>`;
}
class Parent extends Component {
static template = xml`
<Child>
<t t-set-slot="brol">
outer
<t t-component="Child">
<t t-set-slot="brol">
<t t-esc="value"/>
</t>
</t>
</t>
</Child>`;
static components = { Child };
Child = Child;
value = "inner";
}
await mount(Parent, fixture);
expect(fixture.innerHTML).toBe(" outer inner");
});
test("can render only empty slot", async () => { test("can render only empty slot", async () => {
class Parent extends Component { class Parent extends Component {
static template = xml`<t t-slot="default"/>`; static template = xml`<t t-slot="default"/>`;
+1 -1
View File
@@ -1,4 +1,4 @@
import { OwlError } from "../../src/common/owl_error"; import { OwlError } from "../../src/runtime/error_handling";
import { App, Component, mount, onMounted, useState, xml } from "../../src"; import { App, Component, mount, onMounted, useState, xml } from "../../src";
import { makeTestFixture, nextAppError, nextTick, snapshotEverything } from "../helpers"; import { makeTestFixture, nextAppError, nextTick, snapshotEverything } from "../helpers";

Some files were not shown because too many files have changed in this diff Show More