diff --git a/src/app/app.ts b/src/app/app.ts index b1a93777..8f8b806e 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -5,6 +5,7 @@ import { Scheduler } from "../component/scheduler"; import { TemplateSet, TemplateSetConfig } from "./template_set"; import { nodeErrorHandlers } from "../component/error_handling"; import { validateTarget } from "../utils"; +import { validateProps } from "./template_helpers"; // reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f @@ -64,7 +65,7 @@ export class App< mount(target: HTMLElement, options?: MountOptions): Promise & InstanceType> { App.validateTarget(target); if (this.dev) { - this.helpers.validateProps(this.Root, this.props, { __owl__: { app: this } }); + validateProps(this.Root, this.props, { __owl__: { app: this } }); } const node = this.makeNode(this.Root, this.props); const prom = this.mountNode(node, target, options); diff --git a/src/app/template_helpers.ts b/src/app/template_helpers.ts index ddac172c..02933bb0 100644 --- a/src/app/template_helpers.ts +++ b/src/app/template_helpers.ts @@ -2,7 +2,8 @@ import { BDom, multi, text, toggler, createCatcher } from "../blockdom"; import { Markup } from "../utils"; import { html } from "../blockdom/index"; import { isOptional, validateSchema } from "../validation"; -import { ComponentConstructor } from "../component/component"; +import type { ComponentConstructor } from "../component/component"; +import { markRaw } from "../reactivity"; /** * This file contains utility functions that will be injected in each template, @@ -246,4 +247,5 @@ export const helpers = { safeOutput, bind, createCatcher, + markRaw, }; diff --git a/src/app/template_set.ts b/src/app/template_set.ts index a7e5e394..f905f64b 100644 --- a/src/app/template_set.ts +++ b/src/app/template_set.ts @@ -1,6 +1,5 @@ import { createBlock, html, list, multi, text, toggler, comment } from "../blockdom"; import { compile, Template } from "../compiler"; -import { markRaw } from "../reactivity"; import { Portal } from "../portal"; import { component, getCurrent } from "../component/component_node"; import { helpers } from "./template_helpers"; @@ -38,22 +37,6 @@ function parseXML(xml: string): Document { return doc; } -/** - * Returns the helpers object that will be injected in each template closure - * function - */ -function makeHelpers(getTemplate: (name: string) => Template): any { - return Object.assign({}, helpers, { - Portal, - markRaw, - getTemplate, - call: (owner: any, subTemplate: string, ctx: any, parent: any, key: any) => { - const template = getTemplate(subTemplate); - return toggler(subTemplate, template.call(owner, ctx, parent, key)); - }, - }); -} - export interface TemplateSetConfig { dev?: boolean; translatableAttributes?: string[]; @@ -67,7 +50,7 @@ export class TemplateSet { templates: { [name: string]: Template } = {}; translateFn?: (s: string) => string; translatableAttributes?: string[]; - helpers: any; + Portal = Portal; constructor(config: TemplateSetConfig = {}) { this.dev = config.dev || false; @@ -76,7 +59,6 @@ export class TemplateSet { if (config.templates) { this.addTemplates(config.templates); } - this.helpers = makeHelpers(this.getTemplate.bind(this)); } addTemplate(name: string, template: string | Element) { @@ -122,7 +104,7 @@ export class TemplateSet { this.templates[name] = function (context, parent) { return templates[name].call(this, context, parent); }; - const template = templateFn(bdom, this.helpers); + const template = templateFn(this, bdom, helpers); this.templates[name] = template; } return this.templates[name]; @@ -136,4 +118,9 @@ export class TemplateSet { translatableAttributes: this.translatableAttributes, }); } + + callTemplate(owner: any, subTemplate: string, ctx: any, parent: any, key: any): any { + const template = this.getTemplate(subTemplate); + return toggler(subTemplate, template.call(owner, ctx, parent, key)); + } } diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts index 4ae9dc4d..958ef0e4 100644 --- a/src/compiler/code_generator.ts +++ b/src/compiler/code_generator.ts @@ -987,17 +987,18 @@ export class CodeGenerator { const key = `key + \`${this.generateComponentKey()}\``; if (isDynamic) { const templateVar = generateId("template"); + if (!this.staticDefs.find((d) => d.id === "call")) { + this.staticDefs.push({ id: "call", expr: `app.callTemplate.bind(app)` }); + } this.define(templateVar, subTemplate); block = this.createBlock(block, "multi", ctx); - this.helpers.add("call"); this.insertBlock(`call(this, ${templateVar}, ctx, node, ${key})`, block!, { ...ctx, forceNewBlock: !block, }); } else { const id = generateId(`callTemplate_`); - this.helpers.add("getTemplate"); - this.staticDefs.push({ id, expr: `getTemplate(${subTemplate})` }); + this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` }); block = this.createBlock(block, "multi", ctx); this.insertBlock(`${id}.call(this, ctx, node, ${key})`, block!, { ...ctx, @@ -1254,7 +1255,9 @@ export class CodeGenerator { } } compileTPortal(ast: ASTTPortal, ctx: Context) { - this.helpers.add("Portal"); + if (!this.staticDefs.find((d) => d.id === "Portal")) { + this.staticDefs.push({ id: "Portal", expr: `app.Portal` }); + } let { block } = ctx; const name = this.compileInNewTarget("slot", ast.content, ctx); diff --git a/src/compiler/index.ts b/src/compiler/index.ts index a3f5d84d..74e8530b 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -1,10 +1,11 @@ +import type { TemplateSet } from "../app/template_set"; import type { BDom } from "../blockdom"; import { CodeGenerator, Config } from "./code_generator"; import { parse } from "./parser"; export type Template = (context: any, vnode: any, key?: string) => BDom; -export type TemplateFunction = (blocks: any, utils: any) => Template; +export type TemplateFunction = (app: TemplateSet, bdom: any, helpers: any) => Template; interface CompileOptions extends Config { name?: string; @@ -26,5 +27,5 @@ export function compile( const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext }); const code = codeGenerator.generateCode(); // template function - return new Function("bdom, helpers", code) as TemplateFunction; + return new Function("app, bdom, helpers", code) as TemplateFunction; } diff --git a/tests/__snapshots__/reactivity.test.ts.snap b/tests/__snapshots__/reactivity.test.ts.snap index 64d37552..830cf371 100644 --- a/tests/__snapshots__/reactivity.test.ts.snap +++ b/tests/__snapshots__/reactivity.test.ts.snap @@ -47,7 +47,7 @@ exports[`Reactivity: useState concurrent renderings 3`] = ` `; exports[`Reactivity: useState destroyed component before being mounted is inactive 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -64,7 +64,7 @@ exports[`Reactivity: useState destroyed component before being mounted is inacti `; exports[`Reactivity: useState destroyed component before being mounted is inactive 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -78,7 +78,7 @@ exports[`Reactivity: useState destroyed component before being mounted is inacti `; exports[`Reactivity: useState destroyed component is inactive 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -95,7 +95,7 @@ exports[`Reactivity: useState destroyed component is inactive 1`] = ` `; exports[`Reactivity: useState destroyed component is inactive 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -109,7 +109,7 @@ exports[`Reactivity: useState destroyed component is inactive 2`] = ` `; exports[`Reactivity: useState one components can subscribe twice to same context 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -124,7 +124,7 @@ exports[`Reactivity: useState one components can subscribe twice to same context `; exports[`Reactivity: useState parent and children subscribed to same context 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -139,7 +139,7 @@ exports[`Reactivity: useState parent and children subscribed to same context 1`] `; exports[`Reactivity: useState parent and children subscribed to same context 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -216,7 +216,7 @@ exports[`Reactivity: useState several nodes on different level use same context `; exports[`Reactivity: useState two components are updated in parallel 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -231,7 +231,7 @@ exports[`Reactivity: useState two components are updated in parallel 1`] = ` `; exports[`Reactivity: useState two components are updated in parallel 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -245,7 +245,7 @@ exports[`Reactivity: useState two components are updated in parallel 2`] = ` `; exports[`Reactivity: useState two components can subscribe to same context 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -260,7 +260,7 @@ exports[`Reactivity: useState two components can subscribe to same context 1`] = `; exports[`Reactivity: useState two components can subscribe to same context 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -274,7 +274,7 @@ exports[`Reactivity: useState two components can subscribe to same context 2`] = `; exports[`Reactivity: useState two independent components on different levels are updated in parallel 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -289,7 +289,7 @@ exports[`Reactivity: useState two independent components on different levels are `; exports[`Reactivity: useState two independent components on different levels are updated in parallel 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -303,7 +303,7 @@ exports[`Reactivity: useState two independent components on different levels are `; exports[`Reactivity: useState two independent components on different levels are updated in parallel 3`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -317,7 +317,7 @@ exports[`Reactivity: useState two independent components on different levels are `; exports[`Reactivity: useState useContext=useState hook is reactive, for one component 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -331,7 +331,7 @@ exports[`Reactivity: useState useContext=useState hook is reactive, for one comp `; exports[`Reactivity: useState useless atoms should be deleted 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { prepareList, withKey } = helpers; @@ -356,7 +356,7 @@ exports[`Reactivity: useState useless atoms should be deleted 1`] = ` `; exports[`Reactivity: useState useless atoms should be deleted 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -370,7 +370,7 @@ exports[`Reactivity: useState useless atoms should be deleted 2`] = ` `; exports[`Reactivity: useState very simple use, with initial value 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; diff --git a/tests/app/__snapshots__/app.test.ts.snap b/tests/app/__snapshots__/app.test.ts.snap index 6945d47a..55aa6434 100644 --- a/tests/app/__snapshots__/app.test.ts.snap +++ b/tests/app/__snapshots__/app.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`app App supports env with getters/setters 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -16,7 +16,7 @@ exports[`app App supports env with getters/setters 1`] = ` `; exports[`app can configure an app with props 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -30,7 +30,7 @@ exports[`app can configure an app with props 1`] = ` `; exports[`app destroy remove the widget from the DOM 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -43,7 +43,7 @@ exports[`app destroy remove the widget from the DOM 1`] = ` `; exports[`app warnIfNoStaticProps works as expected 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; diff --git a/tests/compiler/__snapshots__/attributes.test.ts.snap b/tests/compiler/__snapshots__/attributes.test.ts.snap index f45678ad..381886e8 100644 --- a/tests/compiler/__snapshots__/attributes.test.ts.snap +++ b/tests/compiler/__snapshots__/attributes.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`attributes changing a class with t-att-class (preexisting class 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -15,7 +15,7 @@ exports[`attributes changing a class with t-att-class (preexisting class 1`] = ` `; exports[`attributes changing a class with t-att-class 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -29,7 +29,7 @@ exports[`attributes changing a class with t-att-class 1`] = ` `; exports[`attributes changing an attribute with t-att- 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -43,7 +43,7 @@ exports[`attributes changing an attribute with t-att- 1`] = ` `; exports[`attributes class and t-att-class should combine together 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -57,7 +57,7 @@ exports[`attributes class and t-att-class should combine together 1`] = ` `; exports[`attributes class and t-attf-class with ternary operation 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -71,7 +71,7 @@ exports[`attributes class and t-attf-class with ternary operation 1`] = ` `; exports[`attributes dynamic attribute evaluating to 0 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -85,7 +85,7 @@ exports[`attributes dynamic attribute evaluating to 0 1`] = ` `; exports[`attributes dynamic attribute falsy variable 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -99,7 +99,7 @@ exports[`attributes dynamic attribute falsy variable 1`] = ` `; exports[`attributes dynamic attribute with a dash 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -113,7 +113,7 @@ exports[`attributes dynamic attribute with a dash 1`] = ` `; exports[`attributes dynamic attributes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -127,7 +127,7 @@ exports[`attributes dynamic attributes 1`] = ` `; exports[`attributes dynamic class attribute 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -141,7 +141,7 @@ exports[`attributes dynamic class attribute 1`] = ` `; exports[`attributes dynamic class attribute evaluating to 0 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -155,7 +155,7 @@ exports[`attributes dynamic class attribute evaluating to 0 1`] = ` `; exports[`attributes dynamic empty class attribute 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -169,7 +169,7 @@ exports[`attributes dynamic empty class attribute 1`] = ` `; exports[`attributes dynamic formatted attributes with a dash 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -183,7 +183,7 @@ exports[`attributes dynamic formatted attributes with a dash 1`] = ` `; exports[`attributes dynamic undefined class attribute 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -197,7 +197,7 @@ exports[`attributes dynamic undefined class attribute 1`] = ` `; exports[`attributes dynamic undefined generic attribute 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -211,7 +211,7 @@ exports[`attributes dynamic undefined generic attribute 1`] = ` `; exports[`attributes fixed variable 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -225,7 +225,7 @@ exports[`attributes fixed variable 1`] = ` `; exports[`attributes format expression 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -239,7 +239,7 @@ exports[`attributes format expression 1`] = ` `; exports[`attributes format literal 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -253,7 +253,7 @@ exports[`attributes format literal 1`] = ` `; exports[`attributes format multiple 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -267,7 +267,7 @@ exports[`attributes format multiple 1`] = ` `; exports[`attributes format value 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -281,7 +281,7 @@ exports[`attributes format value 1`] = ` `; exports[`attributes from object variables set previously 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { isBoundary, withDefault, setContextValue } = helpers; @@ -299,7 +299,7 @@ exports[`attributes from object variables set previously 1`] = ` `; exports[`attributes from variables set previously (no external node) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { isBoundary, withDefault, setContextValue } = helpers; @@ -317,7 +317,7 @@ exports[`attributes from variables set previously (no external node) 1`] = ` `; exports[`attributes from variables set previously 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { isBoundary, withDefault, setContextValue } = helpers; @@ -335,7 +335,7 @@ exports[`attributes from variables set previously 1`] = ` `; exports[`attributes object 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -349,7 +349,7 @@ exports[`attributes object 1`] = ` `; exports[`attributes static attributes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -362,7 +362,7 @@ exports[`attributes static attributes 1`] = ` `; exports[`attributes static attributes on void elements 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -375,7 +375,7 @@ exports[`attributes static attributes on void elements 1`] = ` `; exports[`attributes static attributes with dashes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -388,7 +388,7 @@ exports[`attributes static attributes with dashes 1`] = ` `; exports[`attributes t-att-class and class should combine together 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -402,7 +402,7 @@ exports[`attributes t-att-class and class should combine together 1`] = ` `; exports[`attributes t-att-class with multiple classes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -416,7 +416,7 @@ exports[`attributes t-att-class with multiple classes 1`] = ` `; exports[`attributes t-att-class with multiple classes 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -430,7 +430,7 @@ exports[`attributes t-att-class with multiple classes 2`] = ` `; exports[`attributes t-att-class with multiple classes, some of which are duplicate 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -444,7 +444,7 @@ exports[`attributes t-att-class with multiple classes, some of which are duplica `; exports[`attributes t-att-class with object 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -458,7 +458,7 @@ exports[`attributes t-att-class with object 1`] = ` `; exports[`attributes t-attf-class 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -472,7 +472,7 @@ exports[`attributes t-attf-class 1`] = ` `; exports[`attributes t-attf-class should combine with class 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -486,7 +486,7 @@ exports[`attributes t-attf-class should combine with class 1`] = ` `; exports[`attributes t-attf-class with multiple classes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -500,7 +500,7 @@ exports[`attributes t-attf-class with multiple classes 1`] = ` `; exports[`attributes t-attf-class with multiple classes separated by multiple spaces 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -514,7 +514,7 @@ exports[`attributes t-attf-class with multiple classes separated by multiple spa `; exports[`attributes tuple literal 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -528,7 +528,7 @@ exports[`attributes tuple literal 1`] = ` `; exports[`attributes tuple variable 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -542,7 +542,7 @@ exports[`attributes tuple variable 1`] = ` `; exports[`attributes two classes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -555,7 +555,7 @@ exports[`attributes two classes 1`] = ` `; exports[`attributes two dynamic attributes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -570,7 +570,7 @@ exports[`attributes two dynamic attributes 1`] = ` `; exports[`attributes updating classes (with obj notation) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -584,7 +584,7 @@ exports[`attributes updating classes (with obj notation) 1`] = ` `; exports[`attributes various escapes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -600,7 +600,7 @@ exports[`attributes various escapes 1`] = ` `; exports[`attributes various escapes 2 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -613,7 +613,7 @@ exports[`attributes various escapes 2 1`] = ` `; exports[`special cases for some specific html attributes/properties input of type checkbox with t-att-indeterminate 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -627,7 +627,7 @@ exports[`special cases for some specific html attributes/properties input of typ `; exports[`special cases for some specific html attributes/properties input type= checkbox, with t-att-checked 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -641,7 +641,7 @@ exports[`special cases for some specific html attributes/properties input type= `; exports[`special cases for some specific html attributes/properties input with t-att-value 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -655,7 +655,7 @@ exports[`special cases for some specific html attributes/properties input with t `; exports[`special cases for some specific html attributes/properties select with t-att-value 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -669,7 +669,7 @@ exports[`special cases for some specific html attributes/properties select with `; exports[`special cases for some specific html attributes/properties textarea with t-att-value 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -683,7 +683,7 @@ exports[`special cases for some specific html attributes/properties textarea wit `; exports[`special cases for some specific html attributes/properties various boolean html attributes 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; diff --git a/tests/compiler/__snapshots__/comments.test.ts.snap b/tests/compiler/__snapshots__/comments.test.ts.snap index 962026b2..2256a692 100644 --- a/tests/compiler/__snapshots__/comments.test.ts.snap +++ b/tests/compiler/__snapshots__/comments.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`comments only a comment 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -12,7 +12,7 @@ exports[`comments only a comment 1`] = ` `; exports[`comments properly handle comments 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -25,7 +25,7 @@ exports[`comments properly handle comments 1`] = ` `; exports[`comments properly handle comments between t-if/t-else 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; diff --git a/tests/compiler/__snapshots__/event_handling.test.ts.snap b/tests/compiler/__snapshots__/event_handling.test.ts.snap index cb43eb5d..dcf4dd4f 100644 --- a/tests/compiler/__snapshots__/event_handling.test.ts.snap +++ b/tests/compiler/__snapshots__/event_handling.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`t-on can bind event handler 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -15,7 +15,7 @@ exports[`t-on can bind event handler 1`] = ` `; exports[`t-on can bind handlers with arguments 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -30,7 +30,7 @@ exports[`t-on can bind handlers with arguments 1`] = ` `; exports[`t-on can bind handlers with empty object 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -45,7 +45,7 @@ exports[`t-on can bind handlers with empty object 1`] = ` `; exports[`t-on can bind handlers with empty object (with non empty inner string) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -60,7 +60,7 @@ exports[`t-on can bind handlers with empty object (with non empty inner string) `; exports[`t-on can bind handlers with empty object (with non empty inner string) 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { prepareList, withKey } = helpers; @@ -87,7 +87,7 @@ exports[`t-on can bind handlers with empty object (with non empty inner string) `; exports[`t-on can bind handlers with object arguments 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -102,7 +102,7 @@ exports[`t-on can bind handlers with object arguments 1`] = ` `; exports[`t-on can bind two event handlers 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -117,7 +117,7 @@ exports[`t-on can bind two event handlers 1`] = ` `; exports[`t-on handler is bound to proper owner 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -131,7 +131,7 @@ exports[`t-on handler is bound to proper owner 1`] = ` `; exports[`t-on handler is bound to proper owner, part 2 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { prepareList, withKey } = helpers; @@ -153,11 +153,10 @@ exports[`t-on handler is bound to proper owner, part 2 1`] = ` `; exports[`t-on handler is bound to proper owner, part 3 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; - let { getTemplate } = helpers; - const callTemplate_1 = getTemplate(\`sub\`); + const callTemplate_1 = app.getTemplate(\`sub\`); return function template(ctx, node, key = \\"\\") { return callTemplate_1.call(this, ctx, node, key + \`__1\`); @@ -166,7 +165,7 @@ exports[`t-on handler is bound to proper owner, part 3 1`] = ` `; exports[`t-on handler is bound to proper owner, part 3 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -180,11 +179,11 @@ exports[`t-on handler is bound to proper owner, part 3 2`] = ` `; exports[`t-on handler is bound to proper owner, part 4 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; - let { prepareList, getTemplate, withKey } = helpers; - const callTemplate_1 = getTemplate(\`sub\`); + let { prepareList, withKey } = helpers; + const callTemplate_1 = app.getTemplate(\`sub\`); return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); @@ -204,7 +203,7 @@ exports[`t-on handler is bound to proper owner, part 4 1`] = ` `; exports[`t-on handler is bound to proper owner, part 4 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -218,7 +217,7 @@ exports[`t-on handler is bound to proper owner, part 4 2`] = ` `; exports[`t-on receive event in first argument 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -232,7 +231,7 @@ exports[`t-on receive event in first argument 1`] = ` `; exports[`t-on t-on modifiers (native listener) basic support for native listener 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -247,7 +246,7 @@ exports[`t-on t-on modifiers (native listener) basic support for native listener `; exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -262,7 +261,7 @@ exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = ` `; exports[`t-on t-on modifiers (native listener) t-on combined with t-out 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { safeOutput } = helpers; @@ -278,7 +277,7 @@ exports[`t-on t-on modifiers (native listener) t-on combined with t-out 1`] = ` `; exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -293,7 +292,7 @@ exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] = `; exports[`t-on t-on modifiers (native listener) t-on with empty handler (only modifiers) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -307,7 +306,7 @@ exports[`t-on t-on modifiers (native listener) t-on with empty handler (only mod `; exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifiers (order matters) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -321,7 +320,7 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifi `; exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop modifiers 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -337,7 +336,7 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop mod `; exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-foreach 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { prepareList, withKey } = helpers; @@ -364,7 +363,7 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-f `; exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifiers (order matters) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -378,7 +377,7 @@ exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifi `; exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -393,7 +392,7 @@ exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = ` `; exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -408,7 +407,7 @@ exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1` `; exports[`t-on t-on with inline statement (function call) 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -423,7 +422,7 @@ exports[`t-on t-on with inline statement (function call) 1`] = ` `; exports[`t-on t-on with inline statement 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -438,7 +437,7 @@ exports[`t-on t-on with inline statement 1`] = ` `; exports[`t-on t-on with inline statement, part 2 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -453,7 +452,7 @@ exports[`t-on t-on with inline statement, part 2 1`] = ` `; exports[`t-on t-on with inline statement, part 3 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -469,11 +468,10 @@ exports[`t-on t-on with inline statement, part 3 1`] = ` `; exports[`t-on t-on with t-call 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; - let { getTemplate } = helpers; - const callTemplate_1 = getTemplate(\`sub\`); + const callTemplate_1 = app.getTemplate(\`sub\`); let block1 = createBlock(\`
\`); @@ -485,7 +483,7 @@ exports[`t-on t-on with t-call 1`] = ` `; exports[`t-on t-on with t-call 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; @@ -499,11 +497,10 @@ exports[`t-on t-on with t-call 2`] = ` `; exports[`t-on t-on, with arguments and t-call 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; - let { getTemplate } = helpers; - const callTemplate_1 = getTemplate(\`sub\`); + const callTemplate_1 = app.getTemplate(\`sub\`); let block1 = createBlock(\`
\`); @@ -515,7 +512,7 @@ exports[`t-on t-on, with arguments and t-call 1`] = ` `; exports[`t-on t-on, with arguments and t-call 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; diff --git a/tests/compiler/__snapshots__/misc.test.ts.snap b/tests/compiler/__snapshots__/misc.test.ts.snap index 7c414086..cfe471f0 100644 --- a/tests/compiler/__snapshots__/misc.test.ts.snap +++ b/tests/compiler/__snapshots__/misc.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`misc complex template 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { prepareList, withKey } = helpers; @@ -79,15 +79,15 @@ exports[`misc complex template 1`] = ` `; exports[`misc global 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; - let { prepareList, isBoundary, withDefault, setContextValue, getTemplate, zero, withKey } = helpers; - const callTemplate_1 = getTemplate(\`_callee-uses-foo\`); - const callTemplate_2 = getTemplate(\`_callee-uses-foo\`); - const callTemplate_3 = getTemplate(\`_callee-uses-foo\`); - const callTemplate_4 = getTemplate(\`_callee-asc\`); - const callTemplate_5 = getTemplate(\`_callee-asc-toto\`); + let { prepareList, isBoundary, withDefault, setContextValue, zero, withKey } = helpers; + const callTemplate_1 = app.getTemplate(\`_callee-uses-foo\`); + const callTemplate_2 = app.getTemplate(\`_callee-uses-foo\`); + const callTemplate_3 = app.getTemplate(\`_callee-uses-foo\`); + const callTemplate_4 = app.getTemplate(\`_callee-asc\`); + const callTemplate_5 = app.getTemplate(\`_callee-asc-toto\`); let block1 = createBlock(\`
\`); let block4 = createBlock(\`\`); @@ -131,7 +131,7 @@ exports[`misc global 1`] = ` `; exports[`misc global 2`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { withDefault } = helpers; @@ -146,7 +146,7 @@ exports[`misc global 2`] = ` `; exports[`misc global 3`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { zero } = helpers; @@ -162,7 +162,7 @@ exports[`misc global 3`] = ` `; exports[`misc global 4`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; let { safeOutput, withDefault } = helpers; @@ -178,11 +178,11 @@ exports[`misc global 4`] = ` `; exports[`misc other complex template 1`] = ` -"function anonymous(bdom, helpers +"function anonymous(app, bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; - let { prepareList, withKey, getTemplate } = helpers; - const callTemplate_1 = getTemplate(\`LOAD_INFOS_TEMPLATE\`); + let { prepareList, withKey } = helpers; + const callTemplate_1 = app.getTemplate(\`LOAD_INFOS_TEMPLATE\`); let block1 = createBlock(\`