mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c72e0a143 | |||
| 382e3e4010 | |||
| 76c389a7a8 | |||
| b9ba0abf41 | |||
| 4ca37be7f3 | |||
| d6667ddf2e | |||
| 6f86beeaf3 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.0.0-beta-10",
|
"version": "2.0.0-beta-12",
|
||||||
"description": "Odoo Web Library (OWL)",
|
"description": "Odoo Web Library (OWL)",
|
||||||
"main": "dist/owl.cjs.js",
|
"main": "dist/owl.cjs.js",
|
||||||
"browser": "dist/owl.iife.js",
|
"browser": "dist/owl.iife.js",
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ interface Context {
|
|||||||
ctxVar?: string;
|
ctxVar?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createContext(parentCtx: Context, params?: Partial<Context>) {
|
function createContext(parentCtx: Context, params?: Partial<Context>): Context {
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{
|
{
|
||||||
block: null,
|
block: null,
|
||||||
@@ -334,8 +334,8 @@ export class CodeGenerator {
|
|||||||
this.addLine(`const ${varName} = ${expr};`);
|
this.addLine(`const ${varName} = ${expr};`);
|
||||||
}
|
}
|
||||||
|
|
||||||
insertAnchor(block: BlockDescription) {
|
insertAnchor(block: BlockDescription, index: number = block.children.length) {
|
||||||
const tag = `block-child-${block.children.length}`;
|
const tag = `block-child-${index}`;
|
||||||
const anchor = xmlDoc.createElement(tag);
|
const anchor = xmlDoc.createElement(tag);
|
||||||
block.insert(anchor);
|
block.insert(anchor);
|
||||||
}
|
}
|
||||||
@@ -692,7 +692,7 @@ export class CodeGenerator {
|
|||||||
const children = ast.content;
|
const children = ast.content;
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
const child = ast.content[i];
|
const child = ast.content[i];
|
||||||
const subCtx: Context = createContext(ctx, {
|
const subCtx = createContext(ctx, {
|
||||||
block,
|
block,
|
||||||
index: block!.childNumber,
|
index: block!.childNumber,
|
||||||
forceNewBlock: false,
|
forceNewBlock: false,
|
||||||
@@ -754,21 +754,37 @@ export class CodeGenerator {
|
|||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
}
|
}
|
||||||
block = this.createBlock(block, "html", ctx);
|
block = this.createBlock(block, "html", ctx);
|
||||||
this.helpers.add(ast.expr === "0" ? "zero" : "safeOutput");
|
let blockStr;
|
||||||
let expr = ast.expr === "0" ? "ctx[zero]" : `safeOutput(${compileExpr(ast.expr)})`;
|
if (ast.expr === "0") {
|
||||||
if (ast.body) {
|
this.helpers.add("zero");
|
||||||
const nextId = BlockDescription.nextBlockId;
|
blockStr = `ctx[zero]`;
|
||||||
const subCtx: Context = createContext(ctx);
|
} else if (ast.body) {
|
||||||
|
let bodyValue = null;
|
||||||
|
bodyValue = BlockDescription.nextBlockId;
|
||||||
|
const subCtx = createContext(ctx);
|
||||||
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
||||||
this.helpers.add("withDefault");
|
this.helpers.add("safeOutput");
|
||||||
expr = `withDefault(${expr}, b${nextId})`;
|
blockStr = `safeOutput(${compileExpr(ast.expr)}, b${bodyValue})`;
|
||||||
|
} else {
|
||||||
|
this.helpers.add("safeOutput");
|
||||||
|
blockStr = `safeOutput(${compileExpr(ast.expr)})`;
|
||||||
}
|
}
|
||||||
this.insertBlock(`${expr}`, block, ctx);
|
this.insertBlock(blockStr, block, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
compileTIfBranch(content: AST, block: BlockDescription, ctx: Context) {
|
||||||
|
this.target.indentLevel++;
|
||||||
|
let childN = block.children.length;
|
||||||
|
this.compileAST(content, createContext(ctx, { block, index: ctx.index }));
|
||||||
|
if (block.children.length > childN) {
|
||||||
|
// we have some content => need to insert an anchor at correct index
|
||||||
|
this.insertAnchor(block!, childN);
|
||||||
|
}
|
||||||
|
this.target.indentLevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTIf(ast: ASTTif, ctx: Context, nextNode?: ASTDomNode) {
|
compileTIf(ast: ASTTif, ctx: Context, nextNode?: ASTDomNode) {
|
||||||
let { block, forceNewBlock, index } = ctx;
|
let { block, forceNewBlock } = ctx;
|
||||||
let currentIndex = index;
|
|
||||||
const codeIdx = this.target.code.length;
|
const codeIdx = this.target.code.length;
|
||||||
const isNewBlock = !block || (block.type !== "multi" && forceNewBlock);
|
const isNewBlock = !block || (block.type !== "multi" && forceNewBlock);
|
||||||
if (block) {
|
if (block) {
|
||||||
@@ -778,28 +794,16 @@ export class CodeGenerator {
|
|||||||
block = this.createBlock(block, "multi", ctx);
|
block = this.createBlock(block, "multi", ctx);
|
||||||
}
|
}
|
||||||
this.addLine(`if (${compileExpr(ast.condition)}) {`);
|
this.addLine(`if (${compileExpr(ast.condition)}) {`);
|
||||||
this.target.indentLevel++;
|
this.compileTIfBranch(ast.content, block, ctx);
|
||||||
this.insertAnchor(block!);
|
|
||||||
const subCtx: Context = createContext(ctx, { block, index: currentIndex });
|
|
||||||
this.compileAST(ast.content, subCtx);
|
|
||||||
this.target.indentLevel--;
|
|
||||||
if (ast.tElif) {
|
if (ast.tElif) {
|
||||||
for (let clause of ast.tElif) {
|
for (let clause of ast.tElif) {
|
||||||
this.addLine(`} else if (${compileExpr(clause.condition)}) {`);
|
this.addLine(`} else if (${compileExpr(clause.condition)}) {`);
|
||||||
this.target.indentLevel++;
|
this.compileTIfBranch(clause.content, block, ctx);
|
||||||
this.insertAnchor(block);
|
|
||||||
const subCtx: Context = createContext(ctx, { block, index: currentIndex });
|
|
||||||
this.compileAST(clause.content, subCtx);
|
|
||||||
this.target.indentLevel--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ast.tElse) {
|
if (ast.tElse) {
|
||||||
this.addLine(`} else {`);
|
this.addLine(`} else {`);
|
||||||
this.target.indentLevel++;
|
this.compileTIfBranch(ast.tElse, block, ctx);
|
||||||
this.insertAnchor(block);
|
|
||||||
const subCtx: Context = createContext(ctx, { block, index: currentIndex });
|
|
||||||
this.compileAST(ast.tElse, subCtx);
|
|
||||||
this.target.indentLevel--;
|
|
||||||
}
|
}
|
||||||
this.addLine("}");
|
this.addLine("}");
|
||||||
if (isNewBlock) {
|
if (isNewBlock) {
|
||||||
@@ -885,7 +889,7 @@ export class CodeGenerator {
|
|||||||
this.addLine("}");
|
this.addLine("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
const subCtx: Context = createContext(ctx, { block, index: loopVar });
|
const subCtx = createContext(ctx, { block, index: loopVar });
|
||||||
this.compileAST(ast.body, subCtx);
|
this.compileAST(ast.body, subCtx);
|
||||||
if (ast.memo) {
|
if (ast.memo) {
|
||||||
this.addLine(
|
this.addLine(
|
||||||
@@ -932,7 +936,7 @@ export class CodeGenerator {
|
|||||||
for (let i = 0, l = ast.content.length; i < l; i++) {
|
for (let i = 0, l = ast.content.length; i < l; i++) {
|
||||||
const child = ast.content[i];
|
const child = ast.content[i];
|
||||||
const isTSet = child.type === ASTType.TSet;
|
const isTSet = child.type === ASTType.TSet;
|
||||||
const subCtx: Context = createContext(ctx, {
|
const subCtx = createContext(ctx, {
|
||||||
block,
|
block,
|
||||||
index,
|
index,
|
||||||
forceNewBlock: !isTSet,
|
forceNewBlock: !isTSet,
|
||||||
@@ -978,7 +982,7 @@ export class CodeGenerator {
|
|||||||
this.addLine(`${ctxVar}[isBoundary] = 1;`);
|
this.addLine(`${ctxVar}[isBoundary] = 1;`);
|
||||||
this.helpers.add("isBoundary");
|
this.helpers.add("isBoundary");
|
||||||
const nextId = BlockDescription.nextBlockId;
|
const nextId = BlockDescription.nextBlockId;
|
||||||
const subCtx: Context = createContext(ctx, { preventRoot: true, ctxVar });
|
const subCtx = createContext(ctx, { preventRoot: true, ctxVar });
|
||||||
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
||||||
if (nextId !== BlockDescription.nextBlockId) {
|
if (nextId !== BlockDescription.nextBlockId) {
|
||||||
this.helpers.add("zero");
|
this.helpers.add("zero");
|
||||||
|
|||||||
+1
-5
@@ -3,7 +3,6 @@ import { ComponentNode } from "./component_node";
|
|||||||
import { nodeErrorHandlers } from "./error_handling";
|
import { nodeErrorHandlers } from "./error_handling";
|
||||||
import { Fiber, MountOptions } from "./fibers";
|
import { Fiber, MountOptions } from "./fibers";
|
||||||
import { Scheduler } from "./scheduler";
|
import { Scheduler } from "./scheduler";
|
||||||
import { STATUS } from "./status";
|
|
||||||
import { validateProps } from "./template_helpers";
|
import { validateProps } from "./template_helpers";
|
||||||
import { TemplateSet, TemplateSetConfig } from "./template_set";
|
import { TemplateSet, TemplateSetConfig } from "./template_set";
|
||||||
import { validateTarget } from "./utils";
|
import { validateTarget } from "./utils";
|
||||||
@@ -141,10 +140,7 @@ export class App<
|
|||||||
return (props: P, key: string, ctx: ComponentNode, parent: any, C: any) => {
|
return (props: P, key: string, ctx: ComponentNode, parent: any, C: any) => {
|
||||||
let children = ctx.children;
|
let children = ctx.children;
|
||||||
let node: any = children[key];
|
let node: any = children[key];
|
||||||
if (
|
if (isDynamic && node && node.component.constructor !== C) {
|
||||||
node &&
|
|
||||||
(node.status === STATUS.DESTROYED || (isDynamic && node.component.constructor !== C))
|
|
||||||
) {
|
|
||||||
node = undefined;
|
node = undefined;
|
||||||
}
|
}
|
||||||
const parentFiber = ctx.fiber!;
|
const parentFiber = ctx.fiber!;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ function cancelFibers(fibers: Fiber[]): number {
|
|||||||
fiber.render = throwOnRender;
|
fiber.render = throwOnRender;
|
||||||
if (node.status === STATUS.NEW) {
|
if (node.status === STATUS.NEW) {
|
||||||
node.destroy();
|
node.destroy();
|
||||||
|
delete node.parent!.children[node.parentKey!];
|
||||||
}
|
}
|
||||||
node.fiber = null;
|
node.fiber = null;
|
||||||
if (fiber.bdom) {
|
if (fiber.bdom) {
|
||||||
|
|||||||
@@ -129,9 +129,9 @@ class LazyValue {
|
|||||||
/*
|
/*
|
||||||
* Safely outputs `value` as a block depending on the nature of `value`
|
* Safely outputs `value` as a block depending on the nature of `value`
|
||||||
*/
|
*/
|
||||||
export function safeOutput(value: any): ReturnType<typeof toggler> {
|
export function safeOutput(value: any, defaultValue?: any): ReturnType<typeof toggler> {
|
||||||
if (!value) {
|
if (value === undefined) {
|
||||||
return value;
|
return defaultValue ? toggler("default", defaultValue) : toggler("undefined", text(""));
|
||||||
}
|
}
|
||||||
let safeKey;
|
let safeKey;
|
||||||
let block;
|
let block;
|
||||||
|
|||||||
@@ -166,13 +166,13 @@ exports[`misc global 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;
|
||||||
let { safeOutput, withDefault } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const b3 = text(\`toto default\`);
|
const b3 = text(\`toto default\`);
|
||||||
const b2 = withDefault(safeOutput(ctx['toto']), b3);
|
const b2 = safeOutput(ctx['toto'], b3);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -133,6 +133,31 @@ exports[`t-esc t-esc is escaped 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-esc t-esc with the 0 number 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-esc t-esc with the 0 number, in a p 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['var'];
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-esc t-esc work with spread operator 1`] = `
|
exports[`t-esc t-esc work with spread operator 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -183,6 +208,17 @@ exports[`t-esc t-esc=0 is escaped 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-esc top level t-esc with undefined 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-esc variable 1`] = `
|
exports[`t-esc variable 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -217,13 +217,13 @@ exports[`t-out t-out on a node with a body, as a default 1`] = `
|
|||||||
"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;
|
||||||
let { safeOutput, withDefault } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const b3 = text(\`nope\`);
|
const b3 = text(\`nope\`);
|
||||||
const b2 = withDefault(safeOutput(ctx['var']), b3);
|
const b2 = safeOutput(ctx['var'], b3);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
@@ -233,14 +233,14 @@ exports[`t-out t-out on a node with a dom node in body, as a default 1`] = `
|
|||||||
"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;
|
||||||
let { safeOutput, withDefault } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
let block3 = createBlock(\`<div>nope</div>\`);
|
let block3 = createBlock(\`<div>nope</div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const b3 = block3();
|
const b3 = block3();
|
||||||
const b2 = withDefault(safeOutput(ctx['var']), b3);
|
const b2 = safeOutput(ctx['var'], b3);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
@@ -407,6 +407,45 @@ exports[`t-out t-out with just a t-set t-value in body 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-out t-out with the 0 number 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return safeOutput(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out t-out with the 0 number, in a p 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = safeOutput(ctx['var']);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out top level t-out with undefined 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return safeOutput(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-out variable 1`] = `
|
exports[`t-out variable 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -534,13 +534,36 @@ exports[`t-set t-set with t-value (truthy) and body 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-set t-set, multiple t-ifs, and a specific configuration 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><div><span>First div</span></div><div><block-child-0/></div></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
let b2;
|
||||||
|
if (ctx['flag']) {
|
||||||
|
setContextValue(ctx, \\"bouh\\", 2);
|
||||||
|
}
|
||||||
|
if (!ctx['flag']) {
|
||||||
|
b2 = text(\`Second\`);
|
||||||
|
}
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 1 1`] = `
|
exports[`t-set t-set, t-if, and mix of expression/body lookup, 1 1`] = `
|
||||||
"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;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
@@ -562,7 +585,7 @@ exports[`t-set t-set, t-if, and mix of expression/body lookup, 2 1`] = `
|
|||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
|
|||||||
@@ -67,6 +67,21 @@ describe("t-esc", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-esc with the 0 number", () => {
|
||||||
|
const template = `<t t-esc="var"/>`;
|
||||||
|
expect(renderToString(template, { var: 0 })).toBe("0");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-esc with the 0 number, in a p", () => {
|
||||||
|
const template = `<p><t t-esc="var"/></p>`;
|
||||||
|
expect(renderToString(template, { var: 0 })).toBe("<p>0</p>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("top level t-esc with undefined", () => {
|
||||||
|
const template = `<t t-esc="var"/>`;
|
||||||
|
expect(renderToString(template, { var: undefined })).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
test("falsy values in text nodes", () => {
|
test("falsy values in text nodes", () => {
|
||||||
const template = `
|
const template = `
|
||||||
<t t-esc="v1"/>:<t t-esc="v2"/>:<t t-esc="v3"/>:<t t-esc="v4"/>:<t t-esc="v5"/>`;
|
<t t-esc="v1"/>:<t t-esc="v2"/>:<t t-esc="v3"/>:<t t-esc="v4"/>:<t t-esc="v5"/>`;
|
||||||
|
|||||||
@@ -47,6 +47,21 @@ describe("t-out", () => {
|
|||||||
expect(renderToString(template, { var: new String("ok") })).toBe("<span>ok</span>");
|
expect(renderToString(template, { var: new String("ok") })).toBe("<span>ok</span>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-out with the 0 number", () => {
|
||||||
|
const template = `<t t-out="var"/>`;
|
||||||
|
expect(renderToString(template, { var: 0 })).toBe("0");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-out with the 0 number, in a p", () => {
|
||||||
|
const template = `<p><t t-out="var"/></p>`;
|
||||||
|
expect(renderToString(template, { var: 0 })).toBe("<p>0</p>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("top level t-out with undefined", () => {
|
||||||
|
const template = `<t t-out="var"/>`;
|
||||||
|
expect(renderToString(template, { var: undefined })).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
test("with an extended String class", () => {
|
test("with an extended String class", () => {
|
||||||
class LoveString extends String {
|
class LoveString extends String {
|
||||||
valueOf(): string {
|
valueOf(): string {
|
||||||
|
|||||||
@@ -33,6 +33,22 @@ describe("t-set", () => {
|
|||||||
expect(renderToString(template, { value: "ok" })).toBe("<div>grimbergen</div>");
|
expect(renderToString(template, { value: "ok" })).toBe("<div>grimbergen</div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set, multiple t-ifs, and a specific configuration", () => {
|
||||||
|
const template = `
|
||||||
|
<p>
|
||||||
|
<div>
|
||||||
|
<t t-if="flag" t-set="bouh" t-value="2"/>
|
||||||
|
<span>First div</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<t t-if="!flag">Second</t>
|
||||||
|
</div>
|
||||||
|
</p>`;
|
||||||
|
expect(renderToString(template)).toBe(
|
||||||
|
"<p><div><span>First div</span></div><div>Second</div></p>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("set from body literal", () => {
|
test("set from body literal", () => {
|
||||||
const template = `<t><t t-set="value">ok</t><t t-esc="value"/></t>`;
|
const template = `<t><t t-set="value">ok</t><t t-esc="value"/></t>`;
|
||||||
expect(renderToString(template)).toBe("ok");
|
expect(renderToString(template)).toBe("ok");
|
||||||
|
|||||||
@@ -1308,6 +1308,18 @@ exports[`t-out in components can switch the contents of two t-out repeatedly 1`]
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-out in components t-out and updating falsy values, 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return safeOutput(ctx['state'].a);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-out in components update properly on state changes 1`] = `
|
exports[`t-out in components update properly on state changes 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ exports[`t-set t-set in t-if 1`] = `
|
|||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-child-0/><p><block-text-0/></p></div>\`);
|
let block1 = createBlock(\`<div><p><block-text-0/></p></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
@@ -307,7 +307,7 @@ exports[`t-set t-set outside modified in t-if 1`] = `
|
|||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-child-0/><p><block-text-0/></p></div>\`);
|
let block1 = createBlock(\`<div><p><block-text-0/></p></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
|
|||||||
@@ -1084,4 +1084,25 @@ describe("t-out in components", () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div>1</div><div>2</div>");
|
expect(fixture.innerHTML).toBe("<div>1</div><div>2</div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-out and updating falsy values, ", async () => {
|
||||||
|
class Test extends Component {
|
||||||
|
static template = xml`<t t-out="state.a"/>`;
|
||||||
|
state: any = useState({ a: 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const comp = await mount(Test, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("0");
|
||||||
|
comp.state.a = undefined;
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("");
|
||||||
|
|
||||||
|
comp.state.a = "hello";
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("hello");
|
||||||
|
|
||||||
|
comp.state.a = false;
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("false");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user