Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1ff7ac6a4 |
@@ -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
|
|
||||||
|
|||||||
@@ -47,4 +47,3 @@ Utility/helpers:
|
|||||||
- [`status`](reference/component.md#status-helper): utility function to get the status of a component (new, mounted or destroyed)
|
- [`status`](reference/component.md#status-helper): utility function to get the status of a component (new, mounted or destroyed)
|
||||||
- [`validate`](reference/utils.md#validate): validates if an object satisfies a specified schema
|
- [`validate`](reference/utils.md#validate): validates if an object satisfies a specified schema
|
||||||
- [`whenReady`](reference/utils.md#whenready): utility function to execute code when DOM is ready
|
- [`whenReady`](reference/utils.md#whenready): utility function to execute code when DOM is ready
|
||||||
- [`batched`](reference/utils.md#batched): utility function to batch function calls
|
|
||||||
|
|||||||
@@ -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).
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -451,6 +451,5 @@ console.log(status(component));
|
|||||||
// logs either:
|
// logs either:
|
||||||
// - 'new', if the component is new and has not been mounted yet
|
// - 'new', if the component is new and has not been mounted yet
|
||||||
// - 'mounted', if the component is currently mounted
|
// - 'mounted', if the component is currently mounted
|
||||||
// - 'cancelled', if the component has not been mounted yet but will be destroyed soon
|
|
||||||
// - 'destroyed' if the component is currently destroyed
|
// - 'destroyed' if the component is currently destroyed
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|||||||
@@ -140,28 +140,6 @@ class SomeComponent extends Component {
|
|||||||
The `.bind` suffix also implies `.alike`, so these props will not cause additional
|
The `.bind` suffix also implies `.alike`, so these props will not cause additional
|
||||||
renderings.
|
renderings.
|
||||||
|
|
||||||
## Translatable props
|
|
||||||
|
|
||||||
When you need to pass a user-facing string to a subcomponent, you likely want it
|
|
||||||
to be translated. Unfortunately, because props are arbitrary expressions, it wouldn't
|
|
||||||
be practical for Owl to find out which parts of the expression are strings and translate
|
|
||||||
them, and it also makes it difficult for tooling to extract these strings to generate
|
|
||||||
terms to translate. While you can work around this issue by doing the translation in
|
|
||||||
JavaScript, or by using `t-set` with a body (the body of `t-set` is translated),
|
|
||||||
and passing the variable as a prop, this is a sufficiently common use case that Owl
|
|
||||||
provides a suffix for this purpose: `.translate`.
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<t t-name="ParentComponent">
|
|
||||||
<Child someProp.translate="some message"/>
|
|
||||||
</t>
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that the content of this attribute is _NOT_ treated as a JavaScript expression:
|
|
||||||
it is treated as a string, as if it was an attribute on an HTML element, and translated
|
|
||||||
before being passed to the component. If you need to interpolate some data into the
|
|
||||||
string, you will still have to do this in JavaScript.
|
|
||||||
|
|
||||||
## Dynamic Props
|
## Dynamic Props
|
||||||
|
|
||||||
The `t-props` directive can be used to specify totally dynamic props:
|
The `t-props` directive can be used to specify totally dynamic props:
|
||||||
@@ -260,7 +238,7 @@ class ComponentB extends owl.Component {
|
|||||||
count: {type: Number},
|
count: {type: Number},
|
||||||
messages: {
|
messages: {
|
||||||
type: Array,
|
type: Array,
|
||||||
element: {type: Object, shape: {id: Boolean, text: String }}
|
element: {type: Object, shape: {id: Boolean, text: String }
|
||||||
},
|
},
|
||||||
date: Date,
|
date: Date,
|
||||||
combinedVal: [Number, Boolean],
|
combinedVal: [Number, Boolean],
|
||||||
@@ -298,8 +276,7 @@ class ComponentB extends owl.Component {
|
|||||||
id: Number,
|
id: Number,
|
||||||
name: {type: String, optional: true},
|
name: {type: String, optional: true},
|
||||||
url: String
|
url: String
|
||||||
}
|
]}, // object, with keys id (number), name (string, optional) and url (string)
|
||||||
}, // object, with keys id (number), name (string, optional) and url (string)
|
|
||||||
someObj3: {
|
someObj3: {
|
||||||
type: Object,
|
type: Object,
|
||||||
values: { type: Array, element: String },
|
values: { type: Array, element: String },
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -193,7 +193,7 @@ to be able to opt out of creating them in the first place. This is the purpose o
|
|||||||
### `markRaw`
|
### `markRaw`
|
||||||
|
|
||||||
Marks an object so that it is ignored by the reactivity system, meaning that if this object is ever
|
Marks an object so that it is ignored by the reactivity system, meaning that if this object is ever
|
||||||
part of a reactive object, it will be returned as is, and no keys in that object will be
|
part of a of a reactive object, it will be returned as is, and no keys in that object will be
|
||||||
observed.
|
observed.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ Slots can define a default content, in case the parent did not define them:
|
|||||||
## Dynamic Slots
|
## Dynamic Slots
|
||||||
|
|
||||||
The `t-slot` directive is actually able to use any expressions, using string
|
The `t-slot` directive is actually able to use any expressions, using string
|
||||||
interpolation:
|
interplolation:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<t t-slot="{{current}}" />
|
<t t-slot="{{current}}" />
|
||||||
@@ -201,17 +201,16 @@ use this `Notebook` component:
|
|||||||
|
|
||||||
```xml
|
```xml
|
||||||
<Notebook>
|
<Notebook>
|
||||||
<t t-set-slot="page1" title.translate="Page 1">
|
<t t-set-slot="page1" title="'Page 1'">
|
||||||
<div>this is in the page 1</div>
|
<div>this is in the page 1</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-set-slot="page2" title.translate="Page 2" hidden="somevalue">
|
<t t-set-slot="page2" title="'Page 2'" hidden="somevalue">
|
||||||
<div>this is in the page 2</div>
|
<div>this is in the page 2</div>
|
||||||
</t>
|
</t>
|
||||||
</Notebook>
|
</Notebook>
|
||||||
```
|
```
|
||||||
|
|
||||||
Slot params works like normal props, so one can use suffixes like `.translate`
|
Slot params works like normal props, so one can use the `.bind` suffix to
|
||||||
when a prop is a user facing string and should be translated, or `.bind` to
|
|
||||||
bind a function if needed.
|
bind a function if needed.
|
||||||
|
|
||||||
## Slot scopes
|
## Slot scopes
|
||||||
|
|||||||
@@ -376,16 +376,15 @@ An important difference should be made with the usual `QWeb` behaviour: Owl
|
|||||||
requires the presence of a `t-key` directive, to be able to properly reconcile
|
requires the presence of a `t-key` directive, to be able to properly reconcile
|
||||||
renderings.
|
renderings.
|
||||||
|
|
||||||
`t-foreach` can iterate on any iterable, and also has special support for objects
|
`t-foreach` can iterate on an array (the current item will be the current value)
|
||||||
and maps, it will expose the key of the current iteration as the contents of the
|
or an object (the current item will be the current key).
|
||||||
`t-as`, and the corresponding value with the same name and the suffix `_value`.
|
|
||||||
|
|
||||||
In addition to the name passed via t-as, `t-foreach` provides a few other useful
|
In addition to the name passed via t-as, `t-foreach` provides a few other
|
||||||
variables (note: `$as` will be replaced with the name passed to `t-as`):
|
variables for various data points (note: `$as` will be replaced with the name
|
||||||
|
passed to `t-as`):
|
||||||
|
|
||||||
- `$as_value`: the current iteration value, identical to `$as` for arrays and
|
- `$as_value`: the current iteration value, identical to `$as` for lists and
|
||||||
other iterables, but for objects and maps, it provides the value (where `$as`
|
integers, but for objects, it provides the value (where `$as` provides the key)
|
||||||
provides the key)
|
|
||||||
- `$as_index`: the current iteration index (the first item of the iteration has index 0)
|
- `$as_index`: the current iteration index (the first item of the iteration has index 0)
|
||||||
- `$as_first`: whether the current item is the first of the iteration
|
- `$as_first`: whether the current item is the first of the iteration
|
||||||
(equivalent to `$as_index == 0`)
|
(equivalent to `$as_index == 0`)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ functions are all available in the `owl.utils` namespace.
|
|||||||
- [`loadFile`](#loadfile): loading a file (useful for templates)
|
- [`loadFile`](#loadfile): loading a file (useful for templates)
|
||||||
- [`EventBus`](#eventbus): a simple EventBus
|
- [`EventBus`](#eventbus): a simple EventBus
|
||||||
- [`validate`](#validate): a validation function
|
- [`validate`](#validate): a validation function
|
||||||
- [`batched`](#batched): batch function calls
|
|
||||||
|
|
||||||
## `whenReady`
|
## `whenReady`
|
||||||
|
|
||||||
@@ -79,22 +78,3 @@ validate(
|
|||||||
// - 'id' is missing (should be a number),
|
// - 'id' is missing (should be a number),
|
||||||
// - 'url' is missing (should be a boolean or list of numbers),
|
// - 'url' is missing (should be a boolean or list of numbers),
|
||||||
```
|
```
|
||||||
|
|
||||||
## `batched`
|
|
||||||
|
|
||||||
The `batched` function creates a batched version of a callback so that multiple calls to it within the same microtick will only result in a single invocation of the original callback.
|
|
||||||
|
|
||||||
```js
|
|
||||||
function hello() {
|
|
||||||
console.log("hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
const batchedHello = batched(hello);
|
|
||||||
batchedHello();
|
|
||||||
// Nothing is logged
|
|
||||||
batchedHello();
|
|
||||||
// Still not logged
|
|
||||||
|
|
||||||
await Promise.resolve(); // Await the next microtick
|
|
||||||
// "hello" is logged only once
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 545 KiB After Width: | Height: | Size: 333 KiB |
|
Before Width: | Height: | Size: 387 KiB After Width: | Height: | Size: 210 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 266 KiB After Width: | Height: | Size: 197 KiB |
|
Before Width: | Height: | Size: 320 KiB After Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 329 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 536 KiB After Width: | Height: | Size: 311 KiB |
|
Before Width: | Height: | Size: 488 KiB After Width: | Height: | Size: 336 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 146 KiB |
@@ -41,6 +41,9 @@ const loadFile = (path) => {
|
|||||||
* Make an iframe, with all the js, css and xml properly injected.
|
* Make an iframe, with all the js, css and xml properly injected.
|
||||||
*/
|
*/
|
||||||
function makeCodeIframe(js, css, xml) {
|
function makeCodeIframe(js, css, xml) {
|
||||||
|
// escape backticks in the xml so they don't close the template string
|
||||||
|
const escapedXml = xml.replace(/`/g, '\\\`');
|
||||||
|
|
||||||
const iframe = document.createElement("iframe");
|
const iframe = document.createElement("iframe");
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
const doc = iframe.contentDocument;
|
const doc = iframe.contentDocument;
|
||||||
@@ -52,8 +55,6 @@ function makeCodeIframe(js, css, xml) {
|
|||||||
|
|
||||||
const script = doc.createElement("script");
|
const script = doc.createElement("script");
|
||||||
script.type = "module";
|
script.type = "module";
|
||||||
// escape characters with special meaning in template literals
|
|
||||||
const escapedXml = xml.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/, "\\${");
|
|
||||||
script.textContent = `const TEMPLATES = \`${escapedXml}\`\n${js}`;
|
script.textContent = `const TEMPLATES = \`${escapedXml}\`\n${js}`;
|
||||||
doc.body.appendChild(script);
|
doc.body.appendChild(script);
|
||||||
|
|
||||||
@@ -99,11 +100,6 @@ const SAMPLES = [
|
|||||||
folder: "todo_app",
|
folder: "todo_app",
|
||||||
code: ["js", "xml", "css"],
|
code: ["js", "xml", "css"],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
description: "Tic-Tac-Toe (with reactivity)",
|
|
||||||
folder: "tic_tac_toe",
|
|
||||||
code: ["js", "xml", "css"],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
description: "Responsive app",
|
description: "Responsive app",
|
||||||
folder: "responsive_app",
|
folder: "responsive_app",
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
.square {
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid #999;
|
|
||||||
float: left;
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: bold;
|
|
||||||
line-height: 34px;
|
|
||||||
height: 34px;
|
|
||||||
margin-right: -1px;
|
|
||||||
margin-top: -1px;
|
|
||||||
padding: 0;
|
|
||||||
text-align: center;
|
|
||||||
width: 34px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.board-row:after {
|
|
||||||
clear: both;
|
|
||||||
content: '';
|
|
||||||
display: table;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.game {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
}
|
|
||||||
|
|
||||||
.game-info {
|
|
||||||
margin-left: 20px;
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
// This example is an implementation of the Tic-Tac-Toe game, from
|
|
||||||
// https://react.dev/learn/tutorial-tic-tac-toe. This is an easy application to start learning owl
|
|
||||||
// with some interesting user interactions.
|
|
||||||
//
|
|
||||||
// In this implementation, we use the owl reactivity mechanism.
|
|
||||||
import { Component, useState, mount } from "@odoo/owl";
|
|
||||||
|
|
||||||
|
|
||||||
class Square extends Component {
|
|
||||||
static template = "Square";
|
|
||||||
}
|
|
||||||
|
|
||||||
class Board extends Component {
|
|
||||||
static template = "Board"
|
|
||||||
static components = { Square };
|
|
||||||
|
|
||||||
handleClick(i) {
|
|
||||||
if (this.calculateWinner(this.props.squares) || this.props.squares[i]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const nextSquares = this.props.squares.slice();
|
|
||||||
if (this.props.xIsNext) {
|
|
||||||
nextSquares[i] = 'X';
|
|
||||||
} else {
|
|
||||||
nextSquares[i] = 'O';
|
|
||||||
}
|
|
||||||
this.props.onPlay(nextSquares);
|
|
||||||
}
|
|
||||||
|
|
||||||
get status(){
|
|
||||||
const winner = this.calculateWinner(this.props.squares);
|
|
||||||
if (winner) {
|
|
||||||
return 'Winner: ' + winner;
|
|
||||||
} else {
|
|
||||||
if (Object.values(this.props.squares).filter((v) => v === null).length > 0)
|
|
||||||
return 'Next player: ' + (this.props.xIsNext ? 'X' : 'O');
|
|
||||||
else
|
|
||||||
return 'Draw';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
calculateWinner(squares) {
|
|
||||||
const lines = [
|
|
||||||
[0, 1, 2],
|
|
||||||
[3, 4, 5],
|
|
||||||
[6, 7, 8],
|
|
||||||
[0, 3, 6],
|
|
||||||
[1, 4, 7],
|
|
||||||
[2, 5, 8],
|
|
||||||
[0, 4, 8],
|
|
||||||
[2, 4, 6],
|
|
||||||
];
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
|
||||||
const [a, b, c] = lines[i];
|
|
||||||
if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
|
|
||||||
return squares[a];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Game extends Component {
|
|
||||||
static template = "Game"
|
|
||||||
static components = { Board };
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
this.state = useState({
|
|
||||||
currentMove: 0,
|
|
||||||
history: [Array(9).fill(null)],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get currentSquares() {
|
|
||||||
return this.state.history[this.state.currentMove];
|
|
||||||
}
|
|
||||||
|
|
||||||
get xIsNext() {
|
|
||||||
return this.state.currentMove % 2 === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
jumpTo(nextMove) {
|
|
||||||
this.state.currentMove = nextMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
handlePlay(nextSquares) {
|
|
||||||
const nextHistory = [...this.state.history.slice(0, this.state.currentMove + 1), nextSquares];
|
|
||||||
this.state.history = nextHistory;
|
|
||||||
this.state.currentMove = this.state.history.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
get moves() {
|
|
||||||
return this.state.history.map((_squares, move) => {
|
|
||||||
if (move > 0) {
|
|
||||||
return {id: move, description: 'Go to move #' + move};
|
|
||||||
} else {
|
|
||||||
return {id: move, description: 'Go to game start'};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Application setup
|
|
||||||
mount(Game, document.body, { templates: TEMPLATES, dev: true});
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<templates>
|
|
||||||
<button t-name="Square" class="square" t-on-click="props.onSquareClick">
|
|
||||||
<t t-esc="props.value"/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<t t-name="Board">
|
|
||||||
<div class="status">
|
|
||||||
<t t-esc="status"/>
|
|
||||||
</div>
|
|
||||||
<div class="board-row">
|
|
||||||
<Square value="props.squares[0]" onSquareClick="() => this.handleClick(0)" />
|
|
||||||
<Square value="props.squares[1]" onSquareClick="() => this.handleClick(1)" />
|
|
||||||
<Square value="props.squares[2]" onSquareClick="() => this.handleClick(2)" />
|
|
||||||
</div>
|
|
||||||
<div class="board-row">
|
|
||||||
<Square value="props.squares[3]" onSquareClick="() => this.handleClick(3)" />
|
|
||||||
<Square value="props.squares[4]" onSquareClick="() => this.handleClick(4)" />
|
|
||||||
<Square value="props.squares[5]" onSquareClick="() => this.handleClick(5)" />
|
|
||||||
</div>
|
|
||||||
<div class="board-row">
|
|
||||||
<Square value="props.squares[6]" onSquareClick="() => this.handleClick(6)" />
|
|
||||||
<Square value="props.squares[7]" onSquareClick="() => this.handleClick(7)" />
|
|
||||||
<Square value="props.squares[8]" onSquareClick="() => this.handleClick(8)" />
|
|
||||||
</div>
|
|
||||||
</t>
|
|
||||||
|
|
||||||
<div t-name="Game" class="game">
|
|
||||||
<div class="game-board">
|
|
||||||
<Board xIsNext="xIsNext" squares="currentSquares" onPlay.bind="handlePlay" />
|
|
||||||
</div>
|
|
||||||
<div class="game-info">
|
|
||||||
<ol>
|
|
||||||
<t t-foreach="moves" t-as="move" t-key="move.id">
|
|
||||||
<li>
|
|
||||||
<button t-on-click="() => this.jumpTo(move.id)">
|
|
||||||
<t t-esc="move.description"/>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</t>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</templates>
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.3.0",
|
"version": "2.1.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.3.0",
|
"version": "2.1.3",
|
||||||
"description": "Odoo Web Library (OWL)",
|
"description": "Odoo Web Library (OWL)",
|
||||||
"main": "dist/owl.cjs.js",
|
"main": "dist/owl.cjs.js",
|
||||||
"module": "dist/owl.es.js",
|
"module": "dist/owl.es.js",
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
// Custom error class that wraps error that happen in the owl lifecycle
|
|
||||||
export class OwlError extends Error {
|
|
||||||
cause?: any;
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
@@ -82,14 +82,6 @@ function isProp(tag: string, key: string): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a template literal that evaluates to str. You can add interpolation
|
|
||||||
* sigils into the string if required
|
|
||||||
*/
|
|
||||||
function toStringExpression(str: string) {
|
|
||||||
return `\`${str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/, "\\${")}\``;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// BlockDescription
|
// BlockDescription
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -168,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;
|
||||||
@@ -319,13 +312,14 @@ export class CodeGenerator {
|
|||||||
mainCode.push(``);
|
mainCode.push(``);
|
||||||
for (let block of this.blocks) {
|
for (let block of this.blocks) {
|
||||||
if (block.dom) {
|
if (block.dom) {
|
||||||
let xmlString = toStringExpression(block.asXmlString());
|
let xmlString = block.asXmlString();
|
||||||
|
xmlString = xmlString.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
||||||
if (block.dynamicTagName) {
|
if (block.dynamicTagName) {
|
||||||
xmlString = xmlString.replace(/^`<\w+/, `\`<\${tag || '${block.dom.nodeName}'}`);
|
xmlString = xmlString.replace(/^<\w+/, `<\${tag || '${block.dom.nodeName}'}`);
|
||||||
xmlString = xmlString.replace(/\w+>`$/, `\${tag || '${block.dom.nodeName}'}>\``);
|
xmlString = xmlString.replace(/\w+>$/, `\${tag || '${block.dom.nodeName}'}>`);
|
||||||
mainCode.push(`let ${block.blockName} = tag => createBlock(${xmlString});`);
|
mainCode.push(`let ${block.blockName} = tag => createBlock(\`${xmlString}\`);`);
|
||||||
} else {
|
} else {
|
||||||
mainCode.push(`let ${block.blockName} = createBlock(${xmlString});`);
|
mainCode.push(`let ${block.blockName} = createBlock(\`${xmlString}\`);`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,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;
|
||||||
}
|
}
|
||||||
@@ -409,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);
|
||||||
}
|
}
|
||||||
@@ -522,7 +516,7 @@ export class CodeGenerator {
|
|||||||
const isNewBlock = !block || forceNewBlock;
|
const isNewBlock = !block || forceNewBlock;
|
||||||
if (isNewBlock) {
|
if (isNewBlock) {
|
||||||
block = this.createBlock(block, "comment", ctx);
|
block = this.createBlock(block, "comment", ctx);
|
||||||
this.insertBlock(`comment(${toStringExpression(ast.value)})`, block, {
|
this.insertBlock(`comment(\`${ast.value}\`)`, block, {
|
||||||
...ctx,
|
...ctx,
|
||||||
forceNewBlock: forceNewBlock && !block,
|
forceNewBlock: forceNewBlock && !block,
|
||||||
});
|
});
|
||||||
@@ -546,7 +540,7 @@ export class CodeGenerator {
|
|||||||
|
|
||||||
if (!block || forceNewBlock) {
|
if (!block || forceNewBlock) {
|
||||||
block = this.createBlock(block, "text", ctx);
|
block = this.createBlock(block, "text", ctx);
|
||||||
this.insertBlock(`text(${toStringExpression(value)})`, block, {
|
this.insertBlock(`text(\`${value}\`)`, block, {
|
||||||
...ctx,
|
...ctx,
|
||||||
forceNewBlock: forceNewBlock && !block,
|
forceNewBlock: forceNewBlock && !block,
|
||||||
});
|
});
|
||||||
@@ -592,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;
|
||||||
@@ -720,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);
|
||||||
@@ -765,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;
|
||||||
@@ -781,8 +777,7 @@ export class CodeGenerator {
|
|||||||
expr = compileExpr(ast.expr);
|
expr = compileExpr(ast.expr);
|
||||||
if (ast.defaultValue) {
|
if (ast.defaultValue) {
|
||||||
this.helpers.add("withDefault");
|
this.helpers.add("withDefault");
|
||||||
// FIXME: defaultValue is not translated
|
expr = `withDefault(${expr}, \`${ast.defaultValue}\`)`;
|
||||||
expr = `withDefault(${expr}, ${toStringExpression(ast.defaultValue)})`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!block || forceNewBlock) {
|
if (!block || forceNewBlock) {
|
||||||
@@ -868,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:
|
||||||
@@ -899,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) {
|
||||||
@@ -994,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);
|
||||||
@@ -1002,7 +998,8 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isNewBlock) {
|
if (isNewBlock) {
|
||||||
if (block!.hasDynamicChildren && block!.children.length) {
|
if (block!.hasDynamicChildren) {
|
||||||
|
if (block!.children.length) {
|
||||||
const code = this.target.code;
|
const code = this.target.code;
|
||||||
const children = block!.children.slice();
|
const children = block!.children.slice();
|
||||||
let current = children.shift();
|
let current = children.shift();
|
||||||
@@ -1013,7 +1010,8 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = block!.children.map((c) => c.varName).join(", ");
|
const args = block!.children.map((c) => c.varName).join(", ");
|
||||||
@@ -1029,31 +1027,32 @@ 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 key = this.generateComponentKey();
|
const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`";
|
||||||
|
if (block) {
|
||||||
|
if (!forceNewBlock) {
|
||||||
|
this.insertAnchor(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const key = `key + \`${this.generateComponentKey()}\``;
|
||||||
if (isDynamic) {
|
if (isDynamic) {
|
||||||
const templateVar = generateId("template");
|
const templateVar = generateId("template");
|
||||||
if (!this.staticDefs.find((d) => d.id === "call")) {
|
if (!this.staticDefs.find((d) => d.id === "call")) {
|
||||||
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,
|
||||||
@@ -1061,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,
|
||||||
@@ -1099,13 +1099,11 @@ export class CodeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
let value: string;
|
let value: string;
|
||||||
if (ast.defaultValue) {
|
if (ast.defaultValue) {
|
||||||
const defaultValue = toStringExpression(
|
const defaultValue = ctx.translate ? this.translate(ast.defaultValue) : ast.defaultValue;
|
||||||
ctx.translate ? this.translate(ast.defaultValue) : ast.defaultValue
|
|
||||||
);
|
|
||||||
if (ast.value) {
|
if (ast.value) {
|
||||||
value = `withDefault(${expr}, ${defaultValue})`;
|
value = `withDefault(${expr}, \`${defaultValue}\`)`;
|
||||||
} else {
|
} else {
|
||||||
value = defaultValue;
|
value = `\`${defaultValue}\``;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = expr;
|
value = expr;
|
||||||
@@ -1116,12 +1114,12 @@ export class CodeGenerator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateComponentKey(currentKey: string = "key") {
|
generateComponentKey() {
|
||||||
const parts = [generateId("__")];
|
const parts = [generateId("__")];
|
||||||
for (let i = 0; i < this.target.loopLevel; i++) {
|
for (let i = 0; i < this.target.loopLevel; i++) {
|
||||||
parts.push(`\${key${i + 1}}`);
|
parts.push(`\${key${i + 1}}`);
|
||||||
}
|
}
|
||||||
return `${currentKey} + \`${parts.join("__")}\``;
|
return parts.join("__");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1136,11 +1134,7 @@ export class CodeGenerator {
|
|||||||
* "onClick.bind" "onClick" "onClick: bind(ctx, ctx['onClick'])"
|
* "onClick.bind" "onClick" "onClick: bind(ctx, ctx['onClick'])"
|
||||||
*/
|
*/
|
||||||
formatProp(name: string, value: string): string {
|
formatProp(name: string, value: string): string {
|
||||||
if (name.endsWith(".translate")) {
|
|
||||||
value = toStringExpression(this.translateFn(value));
|
|
||||||
} else {
|
|
||||||
value = this.captureExpression(value);
|
value = this.captureExpression(value);
|
||||||
}
|
|
||||||
if (name.includes(".")) {
|
if (name.includes(".")) {
|
||||||
let [_name, suffix] = name.split(".");
|
let [_name, suffix] = name.split(".");
|
||||||
name = _name;
|
name = _name;
|
||||||
@@ -1149,7 +1143,6 @@ export class CodeGenerator {
|
|||||||
value = `(${value}).bind(this)`;
|
value = `(${value}).bind(this)`;
|
||||||
break;
|
break;
|
||||||
case "alike":
|
case "alike":
|
||||||
case "translate":
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new OwlError("Invalid prop suffix");
|
throw new OwlError("Invalid prop suffix");
|
||||||
@@ -1229,6 +1222,7 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cmap key
|
// cmap key
|
||||||
|
const key = this.generateComponentKey();
|
||||||
let expr: string;
|
let expr: string;
|
||||||
if (ast.isDynamic) {
|
if (ast.isDynamic) {
|
||||||
expr = generateId("Comp");
|
expr = generateId("Comp");
|
||||||
@@ -1246,7 +1240,7 @@ export class CodeGenerator {
|
|||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyArg = this.generateComponentKey();
|
let keyArg = `key + \`${key}\``;
|
||||||
if (ctx.tKeyExpr) {
|
if (ctx.tKeyExpr) {
|
||||||
keyArg = `${ctx.tKeyExpr} + ${keyArg}`;
|
keyArg = `${ctx.tKeyExpr} + ${keyArg}`;
|
||||||
}
|
}
|
||||||
@@ -1325,7 +1319,7 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
let key = this.target.loopLevel ? `key${this.target.loopLevel}` : "key";
|
let key = this.target.loopLevel ? `key${this.target.loopLevel}` : "key";
|
||||||
if (isMultiple) {
|
if (isMultiple) {
|
||||||
key = this.generateComponentKey(key);
|
key = `${key} + \`${this.generateComponentKey()}\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = ast.attrs ? this.formatPropObject(ast.attrs) : [];
|
const props = ast.attrs ? this.formatPropObject(ast.attrs) : [];
|
||||||
@@ -1368,6 +1362,7 @@ export class CodeGenerator {
|
|||||||
|
|
||||||
let { block } = ctx;
|
let { block } = ctx;
|
||||||
const name = this.compileInNewTarget("slot", ast.content, ctx);
|
const name = this.compileInNewTarget("slot", ast.content, ctx);
|
||||||
|
const key = this.generateComponentKey();
|
||||||
let ctxStr = "ctx";
|
let ctxStr = "ctx";
|
||||||
if (this.target.loopLevel || !this.hasSafeContext) {
|
if (this.target.loopLevel || !this.hasSafeContext) {
|
||||||
ctxStr = generateId("ctx");
|
ctxStr = generateId("ctx");
|
||||||
@@ -1381,8 +1376,7 @@ export class CodeGenerator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const target = compileExpr(ast.target);
|
const target = compileExpr(ast.target);
|
||||||
const key = this.generateComponentKey();
|
const blockString = `${id}({target: ${target},slots: {'default': {__render: ${name}.bind(this), __ctx: ${ctxStr}}}}, key + \`${key}\`, node, ctx, Portal)`;
|
||||||
const blockString = `${id}({target: ${target},slots: {'default': {__render: ${name}.bind(this), __ctx: ${ctxStr}}}}, ${key}, node, ctx, Portal)`;
|
|
||||||
if (block) {
|
if (block) {
|
||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,4 +1,4 @@
|
|||||||
import { OwlError } from "../common/owl_error";
|
import { OwlError } from "../runtime/error_handling";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owl QWeb Expression Parser
|
* Owl QWeb Expression Parser
|
||||||
@@ -268,7 +268,7 @@ export function compileExprToArray(expr: string): Token[] {
|
|||||||
const localVars = new Set<string>();
|
const localVars = new Set<string>();
|
||||||
const tokens = tokenize(expr);
|
const tokens = tokenize(expr);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let stack = []; // to track last opening (, [ or {
|
let stack = []; // to track last opening [ or {
|
||||||
|
|
||||||
while (i < tokens.length) {
|
while (i < tokens.length) {
|
||||||
let token = tokens[i];
|
let token = tokens[i];
|
||||||
@@ -279,12 +279,10 @@ export function compileExprToArray(expr: string): Token[] {
|
|||||||
switch (token.type) {
|
switch (token.type) {
|
||||||
case "LEFT_BRACE":
|
case "LEFT_BRACE":
|
||||||
case "LEFT_BRACKET":
|
case "LEFT_BRACKET":
|
||||||
case "LEFT_PAREN":
|
|
||||||
stack.push(token.type);
|
stack.push(token.type);
|
||||||
break;
|
break;
|
||||||
case "RIGHT_BRACE":
|
case "RIGHT_BRACE":
|
||||||
case "RIGHT_BRACKET":
|
case "RIGHT_BRACKET":
|
||||||
case "RIGHT_PAREN":
|
|
||||||
stack.pop();
|
stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -236,10 +235,10 @@ function parseNode(node: Node, ctx: ParsingContext): AST | null {
|
|||||||
parseTCall(node, ctx) ||
|
parseTCall(node, ctx) ||
|
||||||
parseTCallBlock(node, ctx) ||
|
parseTCallBlock(node, ctx) ||
|
||||||
parseTEscNode(node, ctx) ||
|
parseTEscNode(node, ctx) ||
|
||||||
parseTOutNode(node, ctx) ||
|
|
||||||
parseTKey(node, ctx) ||
|
parseTKey(node, ctx) ||
|
||||||
parseTTranslation(node, ctx) ||
|
parseTTranslation(node, ctx) ||
|
||||||
parseTSlot(node, ctx) ||
|
parseTSlot(node, ctx) ||
|
||||||
|
parseTOutNode(node, ctx) ||
|
||||||
parseComponent(node, ctx) ||
|
parseComponent(node, ctx) ||
|
||||||
parseDOMNode(node, ctx) ||
|
parseDOMNode(node, ctx) ||
|
||||||
parseTSetNode(node, ctx) ||
|
parseTSetNode(node, ctx) ||
|
||||||
@@ -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");
|
||||||
|
|
||||||
@@ -365,11 +365,13 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const typeAttr = node.getAttribute("type");
|
const typeAttr = node.getAttribute("type");
|
||||||
const isInput = tagName === "input";
|
const isInput = tagName === "input";
|
||||||
const isSelect = tagName === "select";
|
const isSelect = tagName === "select";
|
||||||
|
const isTextarea = tagName === "textarea";
|
||||||
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 isOtherInput = isInput && !isCheckboxInput && !isRadioInput;
|
||||||
const hasLazyMod = hasTrimMod || attr.includes(".lazy");
|
const hasLazyMod = 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 = {
|
||||||
@@ -379,8 +381,8 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
||||||
eventType,
|
eventType,
|
||||||
hasDynamicChildren: false,
|
hasDynamicChildren: false,
|
||||||
shouldTrim: hasTrimMod,
|
shouldTrim: hasTrimMod && (isOtherInput || isTextarea),
|
||||||
shouldNumberize: hasNumberMod,
|
shouldNumberize: hasNumberMod && (isOtherInput || isTextarea),
|
||||||
};
|
};
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
// don't pollute the original ctx
|
// don't pollute the original ctx
|
||||||
@@ -389,8 +391,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 +403,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 {
|
||||||
@@ -449,6 +446,9 @@ function parseTEscNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
content: [tesc],
|
content: [tesc],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (ast.type === ASTType.TComponent) {
|
||||||
|
throw new OwlError("t-esc is not supported on Component nodes");
|
||||||
|
}
|
||||||
return tesc;
|
return tesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,14 +741,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -943,25 +943,23 @@ function normalizeTIf(el: Element) {
|
|||||||
*
|
*
|
||||||
* @param el the element containing the tree that should be normalized
|
* @param el the element containing the tree that should be normalized
|
||||||
*/
|
*/
|
||||||
function normalizeTEscTOut(el: Element) {
|
function normalizeTEsc(el: Element) {
|
||||||
for (const d of ["t-esc", "t-out"]) {
|
const elements = [...el.querySelectorAll("[t-esc]")].filter(
|
||||||
const elements = [...el.querySelectorAll(`[${d}]`)].filter(
|
|
||||||
(el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component")
|
(el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component")
|
||||||
);
|
);
|
||||||
for (const el of elements) {
|
for (const el of elements) {
|
||||||
if (el.childNodes.length) {
|
if (el.childNodes.length) {
|
||||||
throw new OwlError(`Cannot have ${d} on a component that already has content`);
|
throw new OwlError("Cannot have t-esc on a component that already has content");
|
||||||
}
|
}
|
||||||
const value = el.getAttribute(d);
|
const value = el.getAttribute("t-esc");
|
||||||
el.removeAttribute(d);
|
el.removeAttribute("t-esc");
|
||||||
const t = el.ownerDocument.createElement("t");
|
const t = el.ownerDocument.createElement("t");
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
t.setAttribute(d, value);
|
t.setAttribute("t-esc", value);
|
||||||
}
|
}
|
||||||
el.appendChild(t);
|
el.appendChild(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalizes the tree inside a given element and do some preliminary validation
|
* Normalizes the tree inside a given element and do some preliminary validation
|
||||||
@@ -971,5 +969,42 @@ function normalizeTEscTOut(el: Element) {
|
|||||||
*/
|
*/
|
||||||
function normalizeXML(el: Element) {
|
function normalizeXML(el: Element) {
|
||||||
normalizeTIf(el);
|
normalizeTIf(el);
|
||||||
normalizeTEscTOut(el);
|
normalizeTEsc(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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>(
|
||||||
|
|||||||
@@ -36,21 +36,13 @@ export function createAttrUpdater(attr: string): Setter<HTMLElement> {
|
|||||||
|
|
||||||
export function attrsSetter(this: HTMLElement, attrs: any) {
|
export function attrsSetter(this: HTMLElement, attrs: any) {
|
||||||
if (isArray(attrs)) {
|
if (isArray(attrs)) {
|
||||||
if (attrs[0] === "class") {
|
|
||||||
setClass.call(this, attrs[1]);
|
|
||||||
} else {
|
|
||||||
setAttribute.call(this, attrs[0], attrs[1]);
|
setAttribute.call(this, attrs[0], attrs[1]);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (let k in attrs) {
|
for (let k in attrs) {
|
||||||
if (k === "class") {
|
|
||||||
setClass.call(this, attrs[k]);
|
|
||||||
} else {
|
|
||||||
setAttribute.call(this, k, attrs[k]);
|
setAttribute.call(this, k, attrs[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function attrsUpdater(this: HTMLElement, attrs: any, oldAttrs: any) {
|
export function attrsUpdater(this: HTMLElement, attrs: any, oldAttrs: any) {
|
||||||
if (isArray(attrs)) {
|
if (isArray(attrs)) {
|
||||||
@@ -60,11 +52,7 @@ export function attrsUpdater(this: HTMLElement, attrs: any, oldAttrs: any) {
|
|||||||
if (val === oldAttrs[1]) {
|
if (val === oldAttrs[1]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (name === "class") {
|
|
||||||
updateClass.call(this, val, oldAttrs[1]);
|
|
||||||
} else {
|
|
||||||
setAttribute.call(this, name, val);
|
setAttribute.call(this, name, val);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
removeAttribute.call(this, oldAttrs[0]);
|
removeAttribute.call(this, oldAttrs[0]);
|
||||||
setAttribute.call(this, name, val);
|
setAttribute.call(this, name, val);
|
||||||
@@ -72,25 +60,17 @@ export function attrsUpdater(this: HTMLElement, attrs: any, oldAttrs: any) {
|
|||||||
} else {
|
} else {
|
||||||
for (let k in oldAttrs) {
|
for (let k in oldAttrs) {
|
||||||
if (!(k in attrs)) {
|
if (!(k in attrs)) {
|
||||||
if (k === "class") {
|
|
||||||
updateClass.call(this, "", oldAttrs[k]);
|
|
||||||
} else {
|
|
||||||
removeAttribute.call(this, k);
|
removeAttribute.call(this, k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (let k in attrs) {
|
for (let k in attrs) {
|
||||||
const val = attrs[k];
|
const val = attrs[k];
|
||||||
if (val !== oldAttrs[k]) {
|
if (val !== oldAttrs[k]) {
|
||||||
if (k === "class") {
|
|
||||||
updateClass.call(this, val, oldAttrs[k]);
|
|
||||||
} else {
|
|
||||||
setAttribute.call(this, k, val);
|
setAttribute.call(this, k, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function toClassObj(expr: string | number | { [c: string]: any }) {
|
function toClassObj(expr: string | number | { [c: string]: any }) {
|
||||||
const result: { [c: string]: any } = {};
|
const result: { [c: string]: any } = {};
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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,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";
|
||||||
@@ -146,9 +145,6 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
async render(deep: boolean) {
|
async render(deep: boolean) {
|
||||||
if (this.status >= STATUS.CANCELLED) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let current = this.fiber;
|
let current = this.fiber;
|
||||||
if (current && (current.root!.locked || (current as any).bdom === true)) {
|
if (current && (current.root!.locked || (current as any).bdom === true)) {
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
@@ -175,7 +171,7 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
|||||||
|
|
||||||
this.app.scheduler.addFiber(fiber);
|
this.app.scheduler.addFiber(fiber);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (this.status >= STATUS.CANCELLED) {
|
if (this.status === STATUS.DESTROYED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only want to actually render the component if the following two
|
// We only want to actually render the component if the following two
|
||||||
@@ -194,20 +190,6 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel() {
|
|
||||||
this._cancel();
|
|
||||||
delete this.parent!.children[this.parentKey!];
|
|
||||||
this.app.scheduler.scheduleDestroy(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
_cancel() {
|
|
||||||
this.status = STATUS.CANCELLED;
|
|
||||||
const children = this.children;
|
|
||||||
for (let childKey in children) {
|
|
||||||
children[childKey]._cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
let shouldRemove = this.status === STATUS.MOUNTED;
|
let shouldRemove = this.status === STATUS.MOUNTED;
|
||||||
this._destroy();
|
this._destroy();
|
||||||
|
|||||||
@@ -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();
|
||||||
@@ -47,9 +51,8 @@ export function handleError(params: ErrorParams) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const node = "node" in params ? params.node : params.fiber.node;
|
const node = "node" in params ? params.node : params.fiber.node;
|
||||||
const fiber = "fiber" in params ? params.fiber : node.fiber;
|
const fiber = "fiber" in params ? params.fiber : node.fiber!;
|
||||||
|
|
||||||
if (fiber) {
|
|
||||||
// resets the fibers on components if possible. This is important so that
|
// resets the fibers on components if possible. This is important so that
|
||||||
// new renderings can be properly included in the initial one, if any.
|
// new renderings can be properly included in the initial one, if any.
|
||||||
let current: Fiber | null = fiber;
|
let current: Fiber | null = fiber;
|
||||||
@@ -59,7 +62,6 @@ export function handleError(params: ErrorParams) {
|
|||||||
} while (current);
|
} while (current);
|
||||||
|
|
||||||
fibersInError.set(fiber.root!, error);
|
fibersInError.set(fiber.root!, error);
|
||||||
}
|
|
||||||
|
|
||||||
const handled = _handleError(node, error);
|
const handled = _handleError(node, error);
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
|
|||||||
@@ -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,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 {
|
||||||
@@ -56,7 +55,8 @@ function cancelFibers(fibers: Fiber[]): number {
|
|||||||
let node = fiber.node;
|
let node = fiber.node;
|
||||||
fiber.render = throwOnRender;
|
fiber.render = throwOnRender;
|
||||||
if (node.status === STATUS.NEW) {
|
if (node.status === STATUS.NEW) {
|
||||||
node.cancel();
|
node.destroy();
|
||||||
|
delete node.parent!.children[node.parentKey!];
|
||||||
}
|
}
|
||||||
node.fiber = null;
|
node.fiber = null;
|
||||||
if (fiber.bdom) {
|
if (fiber.bdom) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export { useComponent, useState } from "./component_node";
|
|||||||
export { status } from "./status";
|
export { status } from "./status";
|
||||||
export { reactive, markRaw, toRaw } from "./reactivity";
|
export { reactive, markRaw, toRaw } from "./reactivity";
|
||||||
export { useEffect, useEnv, useExternalListener, useRef, useChildSubEnv, useSubEnv } from "./hooks";
|
export { useEffect, useEnv, useExternalListener, useRef, useChildSubEnv, useSubEnv } from "./hooks";
|
||||||
export { batched, EventBus, whenReady, loadFile, markup } from "./utils";
|
export { EventBus, whenReady, loadFile, markup } from "./utils";
|
||||||
export {
|
export {
|
||||||
onWillStart,
|
onWillStart,
|
||||||
onMounted,
|
onMounted,
|
||||||
@@ -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,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) {
|
||||||
@@ -28,7 +27,7 @@ function wrapError(fn: (...args: any[]) => any, hookName: string) {
|
|||||||
result.catch(() => {}),
|
result.catch(() => {}),
|
||||||
new Promise((resolve) => setTimeout(() => resolve(TIMEOUT), 3000)),
|
new Promise((resolve) => setTimeout(() => resolve(TIMEOUT), 3000)),
|
||||||
]).then((res) => {
|
]).then((res) => {
|
||||||
if (res === TIMEOUT && node.fiber === fiber && node.status <= 2) {
|
if (res === TIMEOUT && node.fiber === fiber) {
|
||||||
console.warn(timeoutError);
|
console.warn(timeoutError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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__;
|
||||||
|
|||||||
@@ -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,7 +220,7 @@ 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>;
|
||||||
@@ -250,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);
|
||||||
}
|
}
|
||||||
@@ -369,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;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { ComponentNode } from "./component_node";
|
|
||||||
import { fibersInError } from "./error_handling";
|
import { fibersInError } from "./error_handling";
|
||||||
import { Fiber, RootFiber } from "./fibers";
|
import { Fiber, RootFiber } from "./fibers";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
@@ -15,7 +14,6 @@ export class Scheduler {
|
|||||||
requestAnimationFrame: Window["requestAnimationFrame"];
|
requestAnimationFrame: Window["requestAnimationFrame"];
|
||||||
frame: number = 0;
|
frame: number = 0;
|
||||||
delayedRenders: Fiber[] = [];
|
delayedRenders: Fiber[] = [];
|
||||||
cancelledNodes: Set<ComponentNode> = new Set();
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
||||||
@@ -25,13 +23,6 @@ export class Scheduler {
|
|||||||
this.tasks.add(fiber.root!);
|
this.tasks.add(fiber.root!);
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleDestroy(node: ComponentNode) {
|
|
||||||
this.cancelledNodes.add(node);
|
|
||||||
if (this.frame === 0) {
|
|
||||||
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process all current tasks. This only applies to the fibers that are ready.
|
* Process all current tasks. This only applies to the fibers that are ready.
|
||||||
* Other tasks are left unchanged.
|
* Other tasks are left unchanged.
|
||||||
@@ -48,24 +39,16 @@ export class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.frame === 0) {
|
if (this.frame === 0) {
|
||||||
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
this.frame = this.requestAnimationFrame(() => {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processTasks() {
|
|
||||||
this.frame = 0;
|
this.frame = 0;
|
||||||
for (let node of this.cancelledNodes) {
|
this.tasks.forEach((fiber) => this.processFiber(fiber));
|
||||||
node._destroy();
|
|
||||||
}
|
|
||||||
this.cancelledNodes.clear();
|
|
||||||
for (let task of this.tasks) {
|
|
||||||
this.processFiber(task);
|
|
||||||
}
|
|
||||||
for (let task of this.tasks) {
|
for (let task of this.tasks) {
|
||||||
if (task.node.status === STATUS.DESTROYED) {
|
if (task.node.status === STATUS.DESTROYED) {
|
||||||
this.tasks.delete(task);
|
this.tasks.delete(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processFiber(fiber: RootFiber) {
|
processFiber(fiber: RootFiber) {
|
||||||
|
|||||||
@@ -7,20 +7,15 @@ import type { Component } from "./component";
|
|||||||
export const enum STATUS {
|
export const enum STATUS {
|
||||||
NEW,
|
NEW,
|
||||||
MOUNTED, // is ready, and in DOM. It has a valid el
|
MOUNTED, // is ready, and in DOM. It has a valid el
|
||||||
// component has been created, but has been replaced by a newer component before being mounted
|
|
||||||
// it is cancelled until the next animation frame where it will be destroyed
|
|
||||||
CANCELLED,
|
|
||||||
DESTROYED,
|
DESTROYED,
|
||||||
}
|
}
|
||||||
|
|
||||||
type STATUS_DESCR = "new" | "mounted" | "cancelled" | "destroyed";
|
type STATUS_DESCR = "new" | "mounted" | "destroyed";
|
||||||
|
|
||||||
export function status(component: Component): STATUS_DESCR {
|
export function status(component: Component): STATUS_DESCR {
|
||||||
switch (component.__owl__.status) {
|
switch (component.__owl__.status) {
|
||||||
case STATUS.NEW:
|
case STATUS.NEW:
|
||||||
return "new";
|
return "new";
|
||||||
case STATUS.CANCELLED:
|
|
||||||
return "cancelled";
|
|
||||||
case STATUS.MOUNTED:
|
case STATUS.MOUNTED:
|
||||||
return "mounted";
|
return "mounted";
|
||||||
case STATUS.DESTROYED:
|
case STATUS.DESTROYED:
|
||||||
|
|||||||
@@ -4,10 +4,16 @@ 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;
|
||||||
|
const ObjectGetPrototypeOf = Object.getPrototypeOf;
|
||||||
|
const ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
|
||||||
|
const ObjectDefineProperty = Object.defineProperty;
|
||||||
|
const ObjectEntries = Object.entries;
|
||||||
|
const hasOwnProperty = (obj: Object, prop: PropertyKey) =>
|
||||||
|
Object.prototype.hasOwnProperty.call(obj, prop);
|
||||||
/**
|
/**
|
||||||
* This file contains utility functions that will be injected in each template,
|
* This file contains utility functions that will be injected in each template,
|
||||||
* to perform various useful tasks in the compiled code.
|
* to perform various useful tasks in the compiled code.
|
||||||
@@ -49,8 +55,14 @@ function callSlot(
|
|||||||
|
|
||||||
function capture(ctx: any): any {
|
function capture(ctx: any): any {
|
||||||
const result = ObjectCreate(ctx);
|
const result = ObjectCreate(ctx);
|
||||||
for (let k in ctx) {
|
let current = ctx;
|
||||||
result[k] = ctx[k];
|
while (current && current !== Object.prototype) {
|
||||||
|
for (const [key, descriptor] of ObjectEntries(ObjectGetOwnPropertyDescriptors(current))) {
|
||||||
|
if (!hasOwnProperty(result, key) && "value" in descriptor) {
|
||||||
|
ObjectDefineProperty(result, key, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current = ObjectGetPrototypeOf(current);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -60,24 +72,18 @@ function withKey(elem: any, k: string) {
|
|||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareList(collection: unknown): [unknown[], unknown[], number, undefined[]] {
|
function prepareList(collection: any): [any[], any[], number, any[]] {
|
||||||
let keys: unknown[];
|
let keys: any[];
|
||||||
let values: unknown[];
|
let values: any[];
|
||||||
|
|
||||||
if (Array.isArray(collection)) {
|
if (Array.isArray(collection)) {
|
||||||
keys = collection;
|
keys = collection;
|
||||||
values = collection;
|
values = collection;
|
||||||
} else if (collection instanceof Map) {
|
} else if (collection) {
|
||||||
keys = [...collection.keys()];
|
values = Object.keys(collection);
|
||||||
values = [...collection.values()];
|
keys = Object.values(collection);
|
||||||
} else if (Symbol.iterator in Object(collection)) {
|
|
||||||
keys = [...(<Iterable<unknown>>collection)];
|
|
||||||
values = keys;
|
|
||||||
} else if (collection && typeof collection === "object") {
|
|
||||||
values = Object.values(collection);
|
|
||||||
keys = Object.keys(collection);
|
|
||||||
} else {
|
} else {
|
||||||
throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`);
|
throw new OwlError("Invalid loop expression");
|
||||||
}
|
}
|
||||||
const n = values.length;
|
const n = values.length;
|
||||||
return [keys, values, n, new Array(n)];
|
return [keys, values, n, new Array(n)];
|
||||||
|
|||||||
@@ -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,4 +1,4 @@
|
|||||||
import { OwlError } from "../common/owl_error";
|
import { OwlError } from "./error_handling";
|
||||||
export type Callback = () => void;
|
export type Callback = () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,13 +9,20 @@ export type Callback = () => void;
|
|||||||
* @returns a batched version of the original callback
|
* @returns a batched version of the original callback
|
||||||
*/
|
*/
|
||||||
export function batched(callback: Callback): Callback {
|
export function batched(callback: Callback): Callback {
|
||||||
let scheduled = false;
|
let called = false;
|
||||||
return async (...args) => {
|
return async () => {
|
||||||
if (!scheduled) {
|
// This await blocks all calls to the callback here, then releases them sequentially
|
||||||
scheduled = true;
|
// in the next microtick. This line decides the granularity of the batch.
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
scheduled = false;
|
if (!called) {
|
||||||
callback(...args);
|
called = true;
|
||||||
|
// wait for all calls in this microtick to fall through before resetting "called"
|
||||||
|
// so that only the first call to the batched function calls the original callback.
|
||||||
|
// Schedule this before calling the callback so that calls to the batched function
|
||||||
|
// within the callback will proceed only after resetting called to false, and have
|
||||||
|
// a chance to execute the callback again
|
||||||
|
Promise.resolve().then(() => (called = false));
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
import { OwlError } from "../common/owl_error";
|
import { OwlError } from "./error_handling";
|
||||||
import { toRaw } from "./reactivity";
|
import { toRaw } from "./reactivity";
|
||||||
|
|
||||||
type BaseType = { new (...args: any[]): any } | true | "*";
|
type BaseType =
|
||||||
|
| typeof String
|
||||||
|
| typeof Boolean
|
||||||
|
| typeof Number
|
||||||
|
| typeof Date
|
||||||
|
| typeof Object
|
||||||
|
| typeof Array
|
||||||
|
| true
|
||||||
|
| "*";
|
||||||
|
|
||||||
interface TypeInfo {
|
interface TypeInfo {
|
||||||
type?: TypeDescription;
|
type?: TypeDescription;
|
||||||
|
|||||||
@@ -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.3.0";
|
export const version = "2.1.3";
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -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"]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
@@ -145,34 +145,3 @@ test("class attribute (with a preexisting value", async () => {
|
|||||||
patch(tree, block([""]));
|
patch(tree, block([""]));
|
||||||
expect(fixture.innerHTML).toBe(`<div class="tomato"></div>`);
|
expect(fixture.innerHTML).toBe(`<div class="tomato"></div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("block-class attributes with preexisting class attribute", async () => {
|
|
||||||
const block = createBlock('<div block-attributes="0" class="owl"></div>');
|
|
||||||
const tree = block([{ class: "eagle" }]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl eagle"></div>`);
|
|
||||||
|
|
||||||
patch(tree, block([{ class: "falcon" }]));
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl falcon"></div>`);
|
|
||||||
|
|
||||||
patch(tree, block([{}]));
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl"></div>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("block-class attributes (array syntax) with preexisting class attribute", async () => {
|
|
||||||
const block = createBlock('<div block-attributes="0" class="owl"></div>');
|
|
||||||
const tree = block([["class", "eagle"]]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl eagle"></div>`);
|
|
||||||
|
|
||||||
patch(tree, block([["class", "falcon"]]));
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl falcon"></div>`);
|
|
||||||
|
|
||||||
patch(tree, block([["class", ""]]));
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl"></div>`);
|
|
||||||
|
|
||||||
patch(tree, block([["class", "buzzard"]]));
|
|
||||||
expect(fixture.innerHTML).toBe(`<div class="owl buzzard"></div>`);
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -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!;
|
||||||
|
|||||||
@@ -707,123 +707,6 @@ exports[`attributes updating classes (with obj notation) 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\" class=\\"c\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {class:'a'};
|
|
||||||
return block1([attr1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\" block-attribute-1=\\"class\\" class=\\"c\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {class:'a'};
|
|
||||||
let attr2 = {'b':true};
|
|
||||||
return block1([attr1, attr2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 3`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\" class=\\"c\\" block-attribute-1=\\"class\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {class:'a'};
|
|
||||||
let attr2 = {'b':true};
|
|
||||||
return block1([attr1, attr2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 4`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"c\\" block-attributes=\\"0\\" block-attribute-1=\\"class\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {class:'a'};
|
|
||||||
let attr2 = {'b':true};
|
|
||||||
return block1([attr1, attr2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 5`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"c\\" block-attribute-0=\\"class\\" block-attributes=\\"1\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {'b':true};
|
|
||||||
let attr2 = {class:'a'};
|
|
||||||
return block1([attr1, attr2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 6`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"c\\" block-attribute-0=\\"class\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {'b':true};
|
|
||||||
return block1([attr1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 7`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"c\\" block-attribute-0=\\"class\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = ('b');
|
|
||||||
return block1([attr1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various combinations of class, t-att-class, and t-att 8`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\" block-attribute-1=\\"class\\">content</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let attr1 = {class:'a'};
|
|
||||||
let attr2 = {'b':true};
|
|
||||||
return block1([attr1, attr2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`attributes various escapes 1`] = `
|
exports[`attributes various escapes 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,38 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`comments comment node with backslash at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return comment(\` \\\\\\\\ \`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`comments comment node with backtick at top-level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return comment(\` \\\\\` \`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`comments comment node with interpolation sigil at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return comment(\` \\\\\${very cool} \`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`comments only a comment 1`] = `
|
exports[`comments only a comment 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -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'];
|
||||||
|
|||||||
@@ -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,7 +51,7 @@ 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}\`;
|
||||||
@@ -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);
|
||||||
@@ -223,7 +223,7 @@ exports[`misc other complex template 1`] = `
|
|||||||
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;
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -341,39 +341,6 @@ exports[`simple templates, mostly static template with t tag with multiple conte
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static text node with backslash at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(\`\\\\\\\\\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`simple templates, mostly static text node with backtick at top-level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(\`\\\\\`\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`simple templates, mostly static text node with interpolation sigil at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(\`\\\\\${very cool}\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`simple templates, mostly static two t-escs next to each other 1`] = `
|
exports[`simple templates, mostly static two t-escs next to each other 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -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\`);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -1,41 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-esc default with backslash at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { withDefault } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(withDefault(undefined, \`\\\\\\\\\`));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-esc default with backtick at top-level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { withDefault } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(withDefault(undefined, \`\\\\\`\`));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-esc default with interpolation sigil at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { withDefault } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(withDefault(undefined, \`\\\\\${very cool}\`));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-esc div with falsy values 1`] = `
|
exports[`t-esc div with falsy values 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -216,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']);
|
||||||
@@ -77,62 +77,6 @@ exports[`t-foreach iterate on items 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate, Map 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(ctx['value']);;
|
|
||||||
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 iterate, Set 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(ctx['value']);;
|
|
||||||
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 iterate, dict param 1`] = `
|
exports[`t-foreach iterate, dict param 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -145,9 +89,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']);
|
||||||
@@ -164,62 +108,6 @@ exports[`t-foreach iterate, dict param 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate, generator 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(ctx['gen']());;
|
|
||||||
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 iterate, iterable 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(ctx['map'].values());;
|
|
||||||
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 iterate, position 1`] = `
|
exports[`t-foreach iterate, position 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -232,9 +120,9 @@ 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;
|
||||||
@@ -256,34 +144,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 +156,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 +176,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 +198,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 +227,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 +296,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 +363,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 +397,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 +424,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 +452,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 +475,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 +502,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];;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -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'];
|
||||||
|
|||||||
@@ -1,50 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-set body with backslash at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", \`\\\\\\\\\`);
|
|
||||||
return text(ctx['value']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set body with backtick at top-level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", \`\\\\\`\`);
|
|
||||||
return text(ctx['value']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set body with interpolation sigil at top level 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", \`\\\\\${very cool}\`);
|
|
||||||
return text(ctx['value']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set evaluate value expression 1`] = `
|
exports[`t-set evaluate value expression 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -396,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);
|
||||||
@@ -426,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);
|
||||||
@@ -456,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);
|
||||||
@@ -486,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();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -371,33 +371,4 @@ describe("attributes", () => {
|
|||||||
// not sure about this. maybe we want to remove the attribute?
|
// not sure about this. maybe we want to remove the attribute?
|
||||||
expect(fixture.innerHTML).toBe('<div class="hoy a b"></div>');
|
expect(fixture.innerHTML).toBe('<div class="hoy a b"></div>');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("various combinations of class, t-att-class, and t-att", () => {
|
|
||||||
const template1 = `<div t-att="{ class: 'a' }" class="c">content</div>`;
|
|
||||||
expect(renderToString(template1)).toBe('<div class="c a">content</div>');
|
|
||||||
|
|
||||||
const template2 = `<div t-att="{ class: 'a' }" t-att-class="{'b': true}" class="c">content</div>`;
|
|
||||||
expect(renderToString(template2)).toBe('<div class="c a b">content</div>');
|
|
||||||
|
|
||||||
const template3 = `<div t-att="{ class: 'a' }" class="c" t-att-class="{'b': true}">content</div>`;
|
|
||||||
expect(renderToString(template3)).toBe('<div class="c a b">content</div>');
|
|
||||||
|
|
||||||
const template4 = `<div class="c" t-att="{ class: 'a' }" t-att-class="{'b': true}">content</div>`;
|
|
||||||
expect(renderToString(template4)).toBe('<div class="c a b">content</div>');
|
|
||||||
|
|
||||||
const template5 = `<div class="c" t-att-class="{'b': true}" t-att="{ class: 'a' }">content</div>`;
|
|
||||||
expect(renderToString(template5)).toBe('<div class="c b a">content</div>');
|
|
||||||
|
|
||||||
const template6 = `<div class="c" t-att-class="{'b': true}">content</div>`;
|
|
||||||
expect(renderToString(template6)).toBe('<div class="c b">content</div>');
|
|
||||||
|
|
||||||
const template7 = `<div class="c" t-attf-class="{{'b'}}">content</div>`;
|
|
||||||
expect(renderToString(template7)).toBe('<div class="c b">content</div>');
|
|
||||||
|
|
||||||
const template8 = `<div t-att="{ class: 'a' }" class="c" t-att-class="{'b': true}">content</div>`;
|
|
||||||
expect(renderToString(template8)).toBe('<div class="c a b">content</div>');
|
|
||||||
|
|
||||||
const template9 = `<div t-att="{ class: 'a' }" t-att-class="{'b': true}">content</div>`;
|
|
||||||
expect(renderToString(template9)).toBe('<div class="a b">content</div>');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,19 +26,4 @@ describe("comments", () => {
|
|||||||
</div>`;
|
</div>`;
|
||||||
expect(renderToString(template)).toBe("<div><span>true</span></div>");
|
expect(renderToString(template)).toBe("<div><span>true</span></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("comment node with backslash at top level", () => {
|
|
||||||
const template = "<!-- \\ -->";
|
|
||||||
expect(renderToString(template)).toBe("<!-- \\ -->");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("comment node with backtick at top-level", () => {
|
|
||||||
const template = "<!-- ` -->";
|
|
||||||
expect(renderToString(template)).toBe("<!-- ` -->");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("comment node with interpolation sigil at top level", () => {
|
|
||||||
const template = "<!-- ${very cool} -->";
|
|
||||||
expect(renderToString(template)).toBe("<!-- ${very cool} -->");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -174,9 +174,6 @@ describe("expression evaluation", () => {
|
|||||||
expect(compileExpr("list.data.map((data) => data)")).toBe(
|
expect(compileExpr("list.data.map((data) => data)")).toBe(
|
||||||
"ctx['list'].data.map((_data)=>_data)"
|
"ctx['list'].data.map((_data)=>_data)"
|
||||||
);
|
);
|
||||||
expect(compileExpr("(ev) => { myFunc(v1, v2, ev.target.value); }")).toBe(
|
|
||||||
"(_ev)=>{ctx['myFunc'](ctx['v1'],ctx['v2'],_ev.target.value);}"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
test.skip("arrow functions: not yet supported", () => {
|
test.skip("arrow functions: not yet supported", () => {
|
||||||
// e is added to localvars in inline_expression but not removed after the arrow func body
|
// e is added to localvars in inline_expression but not removed after the arrow func body
|
||||||
|
|||||||
@@ -1569,12 +1569,6 @@ describe("qweb parser", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("component with t-out", async () => {
|
|
||||||
expect(parse(`<MyComponent t-out="someValue"/>`)).toEqual(
|
|
||||||
parse(`<MyComponent><t t-out="someValue"/></MyComponent>`)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("component with t-esc and content", async () => {
|
test("component with t-esc and content", async () => {
|
||||||
expect(() => parse(`<MyComponent t-esc="someValue">Some content</MyComponent>`)).toThrow(
|
expect(() => parse(`<MyComponent t-esc="someValue">Some content</MyComponent>`)).toThrow(
|
||||||
"Cannot have t-esc on a component that already has content"
|
"Cannot have t-esc on a component that already has content"
|
||||||
@@ -1997,8 +1991,8 @@ describe("qweb parser", () => {
|
|||||||
baseExpr: "state",
|
baseExpr: "state",
|
||||||
expr: "'stuff'",
|
expr: "'stuff'",
|
||||||
eventType: "click",
|
eventType: "click",
|
||||||
shouldNumberize: true,
|
shouldNumberize: false,
|
||||||
shouldTrim: true,
|
shouldTrim: false,
|
||||||
targetAttr: "value",
|
targetAttr: "value",
|
||||||
hasDynamicChildren: false,
|
hasDynamicChildren: false,
|
||||||
specialInitTargetAttr: "checked",
|
specialInitTargetAttr: "checked",
|
||||||
|
|||||||
@@ -154,19 +154,4 @@ describe("simple templates, mostly static", () => {
|
|||||||
</div>`;
|
</div>`;
|
||||||
expect(renderToString(template, { a: "a", b: "b", c: "c" })).toBe("<div>abLoadingc</div>");
|
expect(renderToString(template, { a: "a", b: "b", c: "c" })).toBe("<div>abLoadingc</div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("text node with backslash at top level", () => {
|
|
||||||
const template = "\\";
|
|
||||||
expect(renderToString(template)).toBe("\\");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("text node with backtick at top-level", () => {
|
|
||||||
const template = "`";
|
|
||||||
expect(renderToString(template)).toBe("`");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("text node with interpolation sigil at top level", () => {
|
|
||||||
const template = "${very cool}";
|
|
||||||
expect(renderToString(template)).toBe("${very cool}");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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>`;
|
||||||
|
|||||||
@@ -121,19 +121,4 @@ describe("t-esc", () => {
|
|||||||
mount(bdom, fixture);
|
mount(bdom, fixture);
|
||||||
expect(fixture.querySelector("span")!.textContent).toBe("<p>escaped</p>");
|
expect(fixture.querySelector("span")!.textContent).toBe("<p>escaped</p>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("default with backslash at top level", () => {
|
|
||||||
const template = '<t t-esc="undefined">\\</t>';
|
|
||||||
expect(renderToString(template)).toBe("\\");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("default with backtick at top-level", () => {
|
|
||||||
const template = '<t t-esc="undefined">`</t>';
|
|
||||||
expect(renderToString(template)).toBe("`");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("default with interpolation sigil at top level", () => {
|
|
||||||
const template = '<t t-esc="undefined">${very cool}</t>';
|
|
||||||
expect(renderToString(template)).toBe("${very cool}");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -105,73 +105,6 @@ describe("t-foreach", () => {
|
|||||||
expect(renderToString(template, context)).toBe(expected);
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("iterate, Map param", () => {
|
|
||||||
const template = `
|
|
||||||
<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>`;
|
|
||||||
const expected = ` [0: a 1] [1: b 2] [2: c 3] `;
|
|
||||||
const context = {
|
|
||||||
value: new Map([
|
|
||||||
["a", 1],
|
|
||||||
["b", 2],
|
|
||||||
["c", 3],
|
|
||||||
]),
|
|
||||||
};
|
|
||||||
expect(renderToString(template, context)).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("iterate, Set param", () => {
|
|
||||||
const template = `
|
|
||||||
<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>`;
|
|
||||||
const expected = ` [0: 1 1] [1: 2 2] [2: 3 3] `;
|
|
||||||
const context = { value: new Set([1, 2, 3]) };
|
|
||||||
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", () => {
|
|
||||||
const template = `
|
|
||||||
<t t-foreach="map.values()" 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: 1 1] [1: 2 2] [2: 3 3] `;
|
|
||||||
const context = {
|
|
||||||
map: new Map([
|
|
||||||
["a", 1],
|
|
||||||
["b", 2],
|
|
||||||
["c", 3],
|
|
||||||
]),
|
|
||||||
};
|
|
||||||
expect(renderToString(template, context)).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("iterate, generator param", () => {
|
|
||||||
const template = `
|
|
||||||
<t t-foreach="gen()" 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: 1 1] [1: 2 2] [2: 3 3] `;
|
|
||||||
const context = {
|
|
||||||
*gen() {
|
|
||||||
yield 1;
|
|
||||||
yield 2;
|
|
||||||
yield 3;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
expect(renderToString(template, context)).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("does not pollute the rendering context", () => {
|
test("does not pollute the rendering context", () => {
|
||||||
const template = `
|
const template = `
|
||||||
<div>
|
<div>
|
||||||
@@ -260,9 +193,7 @@ describe("t-foreach", () => {
|
|||||||
|
|
||||||
test("throws error if invalid loop expression", () => {
|
test("throws error if invalid loop expression", () => {
|
||||||
const test = `<div><t t-foreach="abc" t-as="item" t-key="item"><span t-key="item_index"/></t></div>`;
|
const test = `<div><t t-foreach="abc" t-as="item" t-key="item"><span t-key="item_index"/></t></div>`;
|
||||||
expect(() => renderToString(test)).toThrow(
|
expect(() => renderToString(test)).toThrow("Invalid loop expression");
|
||||||
'Invalid loop expression: "undefined" is not iterable'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("t-foreach with t-if inside", () => {
|
test("t-foreach with t-if inside", () => {
|
||||||
|
|||||||
@@ -54,21 +54,6 @@ describe("t-set", () => {
|
|||||||
expect(renderToString(template)).toBe("ok");
|
expect(renderToString(template)).toBe("ok");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("body with backslash at top level", () => {
|
|
||||||
const template = '<t t-set="value">\\</t><t t-esc="value"/>';
|
|
||||||
expect(renderToString(template)).toBe("\\");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("body with backtick at top-level", () => {
|
|
||||||
const template = '<t t-set="value">`</t><t t-esc="value"/>';
|
|
||||||
expect(renderToString(template)).toBe("`");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("body with interpolation sigil at top level", () => {
|
|
||||||
const template = '<t t-set="value">${very cool}</t><t t-esc="value"/>';
|
|
||||||
expect(renderToString(template)).toBe("${very cool}");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("set from body literal (with t-if/t-else", () => {
|
test("set from body literal (with t-if/t-else", () => {
|
||||||
const template = `
|
const template = `
|
||||||
<t>
|
<t>
|
||||||
|
|||||||
@@ -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>");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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]);
|
|
||||||
}
|
|
||||||
}`);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
@@ -212,73 +212,6 @@ exports[`changing state before first render does not trigger a render 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`component destroyed just after render 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 = \\"\\") {
|
|
||||||
return comp1({}, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`component destroyed just after render 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const b2 = text(\`B\`);
|
|
||||||
const b3 = text(ctx['state'].value);
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`components are not destroyed between animation frame 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'].flag) {
|
|
||||||
b3 = comp1({}, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`components are not destroyed between animation frame 3`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
const comp1 = app.createComponent(\`C\`, true, false, false, []);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const b2 = text(\`B\`);
|
|
||||||
const b3 = comp1({}, key + \`__1\`, node, this, null);
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`components are not destroyed between animation frame 5`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(\`C\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`concurrent renderings scenario 1 1`] = `
|
exports[`concurrent renderings scenario 1 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -748,7 +681,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;
|
||||||
@@ -993,7 +926,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;
|
||||||
@@ -1024,7 +957,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 +971,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;
|
||||||
@@ -1085,7 +1018,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;
|
||||||
@@ -1133,7 +1066,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 +1241,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;
|
||||||
@@ -1617,7 +1550,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 +1561,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;
|
||||||
@@ -1656,7 +1589,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 +1618,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 +1720,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;
|
||||||
@@ -1901,7 +1834,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
|
||||||
) {
|
) {
|
||||||
@@ -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;
|
||||||
@@ -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'];
|
||||||
|
|||||||
@@ -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'];
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -683,19 +683,6 @@ exports[`lifecycle hooks sub widget (inside sub node): hooks are correctly calle
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`lifecycle hooks timeout in onWillStart doesn't emit a warning if app is destroyed 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks timeout in onWillStart emits a warning 1`] = `
|
exports[`lifecycle hooks timeout in onWillStart emits a warning 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -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'];
|
||||||
@@ -66,29 +66,6 @@ exports[`.alike suffix in a simple case 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`.translate props are translated 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({message: \`translated message\`}, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`.translate props are translated 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(ctx['props'].message);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics accept ES6-like syntax for props (with getters) 1`] = `
|
exports[`basics accept ES6-like syntax for props (with getters) 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -129,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'];
|
||||||
@@ -435,29 +412,6 @@ exports[`can bind function prop with bind suffix 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`can use .translate suffix 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({message: \`some message\`}, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can use .translate suffix 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(ctx['props'].message);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`do not crash when binding anonymous function prop with bind suffix 1`] = `
|
exports[`do not crash when binding anonymous function prop with bind suffix 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -167,45 +167,6 @@ exports[`props validation can specify that additional props are allowed (object)
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`props validation can use custom class as type 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"customObj\\"]);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {customObj: ctx['customObj']};
|
|
||||||
helpers.validateProps(\`Child\`, props1, this);
|
|
||||||
return comp1(props1, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can use custom class as type 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(ctx['props'].customObj.val);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can use custom class as type: validation failure 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"customObj\\"]);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {customObj: ctx['customObj']};
|
|
||||||
helpers.validateProps(\`Child\`, props1, this);
|
|
||||||
return comp1(props1, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate a prop with multiple types 1`] = `
|
exports[`props validation can validate a prop with multiple types 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,30 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`slots .translate slot props are translated 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { capture, markRaw } = helpers;
|
|
||||||
const comp1 = app.createComponent(\`Child\`, true, true, false, []);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const ctx1 = capture(ctx);
|
|
||||||
return comp1({slots: markRaw({'default': {message: \`translated message\`}})}, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`slots .translate slot props are translated 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(ctx['props'].slots.default.message);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`slots can define a default content 1`] = `
|
exports[`slots can define a default content 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -226,31 +201,6 @@ exports[`slots can render only empty slot 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`slots can use .translate suffix on slot props 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { capture, markRaw } = helpers;
|
|
||||||
const comp1 = app.createComponent(\`Child\`, true, true, false, []);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const ctx1 = capture(ctx);
|
|
||||||
return comp1({slots: markRaw({'default': {message: \`some message\`}})}, key + \`__1\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`slots can use .translate suffix on slot props 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(ctx['props'].slots.default.message);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`slots can use component in default-content of t-slot 1`] = `
|
exports[`slots can use component in default-content of t-slot 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -1116,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
|
||||||
) {
|
) {
|
||||||
@@ -2229,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'];
|
||||||
@@ -2519,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);
|
||||||
@@ -2567,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);
|
||||||
@@ -2714,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);
|
||||||
@@ -2763,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);
|
||||||
@@ -2820,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']);
|
||||||
@@ -2970,11 +2881,11 @@ 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) {
|
||||||
|
|||||||