mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] move app and compiler code around
This commit is contained in:
committed by
Aaron Bohy
parent
9b8c582b32
commit
8c16790471
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
|
||||
interface CompileOptions extends Config {
|
||||
name?: string;
|
||||
}
|
||||
export function compile(template: string, options: CompileOptions = {}): TemplateFunction {
|
||||
// parsing
|
||||
const ast = parse(template);
|
||||
|
||||
// some work
|
||||
const hasSafeContext = !template.includes("t-set") && !template.includes("t-call");
|
||||
const name = options.name || (template.length > 250 ? template.slice(0, 250) + "..." : template);
|
||||
|
||||
// code generation
|
||||
const codeGenerator = new CodeGenerator(name, ast, { ...options, hasSafeContext });
|
||||
const code = codeGenerator.generateCode();
|
||||
|
||||
// template function
|
||||
return new Function("bdom, helpers", code) as TemplateFunction;
|
||||
}
|
||||
Reference in New Issue
Block a user