mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] qweb: rename Context into CompilationContext
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { QWeb } from "../qweb/index";
|
import { QWeb } from "../qweb/index";
|
||||||
import { INTERP_REGEXP } from "../qweb/context";
|
import { INTERP_REGEXP } from "../qweb/compilation_context";
|
||||||
import { MODS_CODE } from "../qweb/extensions";
|
import { MODS_CODE } from "../qweb/extensions";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Context } from "./context";
|
import { CompilationContext } from "./compilation_context";
|
||||||
import { QWebExprVar } from "./expression_parser";
|
import { QWebExprVar } from "./expression_parser";
|
||||||
import { QWeb } from "./qweb";
|
import { QWeb } from "./qweb";
|
||||||
import { htmlToVDOM } from "../vdom/html_to_vdom";
|
import { htmlToVDOM } from "../vdom/html_to_vdom";
|
||||||
@@ -28,7 +28,7 @@ QWeb.utils.getFragment = function(str: string): DocumentFragment {
|
|||||||
|
|
||||||
QWeb.utils.htmlToVDOM = htmlToVDOM;
|
QWeb.utils.htmlToVDOM = htmlToVDOM;
|
||||||
|
|
||||||
function compileValueNode(value: any, node: Element, qweb: QWeb, ctx: Context) {
|
function compileValueNode(value: any, node: Element, qweb: QWeb, ctx: CompilationContext) {
|
||||||
if (value === "0" && ctx.caller) {
|
if (value === "0" && ctx.caller) {
|
||||||
qweb._compileNode(ctx.caller, ctx);
|
qweb._compileNode(ctx.caller, ctx);
|
||||||
return;
|
return;
|
||||||
@@ -187,7 +187,7 @@ QWeb.addDirective({
|
|||||||
nodeCopy.removeAttribute("t-call");
|
nodeCopy.removeAttribute("t-call");
|
||||||
|
|
||||||
// extract variables from nodecopy
|
// extract variables from nodecopy
|
||||||
const tempCtx = new Context();
|
const tempCtx = new CompilationContext();
|
||||||
tempCtx.nextID = ctx.rootContext.nextID;
|
tempCtx.nextID = ctx.rootContext.nextID;
|
||||||
tempCtx.allowMultipleRoots = true;
|
tempCtx.allowMultipleRoots = true;
|
||||||
qweb._compileNode(nodeCopy, tempCtx);
|
qweb._compileNode(nodeCopy, tempCtx);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export const INTERP_REGEXP = /\{\{.*?\}\}/g;
|
|||||||
// Compilation Context
|
// Compilation Context
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
export class Context {
|
export class CompilationContext {
|
||||||
nextID: number = 1;
|
nextID: number = 1;
|
||||||
code: string[] = [];
|
code: string[] = [];
|
||||||
variables: { [key: string]: QWebVar } = {};
|
variables: { [key: string]: QWebVar } = {};
|
||||||
@@ -14,7 +14,7 @@ export class Context {
|
|||||||
parentTextNode: number | null = null;
|
parentTextNode: number | null = null;
|
||||||
rootNode: number | null = null;
|
rootNode: number | null = null;
|
||||||
indentLevel: number = 0;
|
indentLevel: number = 0;
|
||||||
rootContext: Context;
|
rootContext: CompilationContext;
|
||||||
caller: Element | undefined;
|
caller: Element | undefined;
|
||||||
shouldDefineOwner: boolean = false;
|
shouldDefineOwner: boolean = false;
|
||||||
shouldDefineParent: boolean = false;
|
shouldDefineParent: boolean = false;
|
||||||
@@ -87,7 +87,7 @@ export class Context {
|
|||||||
return this.code;
|
return this.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
withParent(node: number): Context {
|
withParent(node: number): CompilationContext {
|
||||||
if (
|
if (
|
||||||
!this.allowMultipleRoots &&
|
!this.allowMultipleRoots &&
|
||||||
this === this.rootContext &&
|
this === this.rootContext &&
|
||||||
@@ -104,7 +104,7 @@ export class Context {
|
|||||||
return this.subContext("parentNode", node);
|
return this.subContext("parentNode", node);
|
||||||
}
|
}
|
||||||
|
|
||||||
subContext(key: keyof Context, value: any): Context {
|
subContext(key: keyof CompilationContext, value: any): CompilationContext {
|
||||||
const newContext = Object.create(this);
|
const newContext = Object.create(this);
|
||||||
newContext[key] = value;
|
newContext[key] = value;
|
||||||
return newContext;
|
return newContext;
|
||||||
+7
-7
@@ -1,6 +1,6 @@
|
|||||||
import { EventBus } from "../core/event_bus";
|
import { EventBus } from "../core/event_bus";
|
||||||
import { h, patch, VNode } from "../vdom/index";
|
import { h, patch, VNode } from "../vdom/index";
|
||||||
import { Context } from "./context";
|
import { CompilationContext } from "./compilation_context";
|
||||||
import { shallowEqual } from "../utils";
|
import { shallowEqual } from "../utils";
|
||||||
import { addNS } from "../vdom/vdom";
|
import { addNS } from "../vdom/vdom";
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ interface Template {
|
|||||||
interface CompilationInfo {
|
interface CompilationInfo {
|
||||||
node: Element;
|
node: Element;
|
||||||
qweb: QWeb;
|
qweb: QWeb;
|
||||||
ctx: Context;
|
ctx: CompilationContext;
|
||||||
fullName: string;
|
fullName: string;
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
@@ -343,9 +343,9 @@ export class QWeb extends EventBus {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_compile(name: string, elem: Element, parentContext?: Context): CompiledTemplate {
|
_compile(name: string, elem: Element, parentContext?: CompilationContext): CompiledTemplate {
|
||||||
const isDebug = elem.attributes.hasOwnProperty("t-debug");
|
const isDebug = elem.attributes.hasOwnProperty("t-debug");
|
||||||
const ctx = new Context(name);
|
const ctx = new CompilationContext(name);
|
||||||
if (elem.tagName !== "t") {
|
if (elem.tagName !== "t") {
|
||||||
ctx.shouldDefineResult = false;
|
ctx.shouldDefineResult = false;
|
||||||
}
|
}
|
||||||
@@ -410,7 +410,7 @@ export class QWeb extends EventBus {
|
|||||||
* Generate code from an xml node
|
* Generate code from an xml node
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
_compileNode(node: ChildNode, ctx: Context) {
|
_compileNode(node: ChildNode, ctx: CompilationContext) {
|
||||||
if (!(node instanceof Element)) {
|
if (!(node instanceof Element)) {
|
||||||
// this is a text node, there are no directive to apply
|
// this is a text node, there are no directive to apply
|
||||||
let text = node.textContent!;
|
let text = node.textContent!;
|
||||||
@@ -569,7 +569,7 @@ export class QWeb extends EventBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_compileGenericNode(node: ChildNode, ctx: Context, withHandlers: boolean = true): number {
|
_compileGenericNode(node: ChildNode, ctx: CompilationContext, withHandlers: boolean = true): number {
|
||||||
// nodeType 1 is generic tag
|
// nodeType 1 is generic tag
|
||||||
if (node.nodeType !== 1) {
|
if (node.nodeType !== 1) {
|
||||||
throw new Error("unsupported node type");
|
throw new Error("unsupported node type");
|
||||||
@@ -732,7 +732,7 @@ export class QWeb extends EventBus {
|
|||||||
return nodeID;
|
return nodeID;
|
||||||
}
|
}
|
||||||
|
|
||||||
_compileChildren(node: ChildNode, ctx: Context) {
|
_compileChildren(node: ChildNode, ctx: CompilationContext) {
|
||||||
if (node.childNodes.length > 0) {
|
if (node.childNodes.length > 0) {
|
||||||
for (let child of Array.from(node.childNodes)) {
|
for (let child of Array.from(node.childNodes)) {
|
||||||
this._compileNode(child, ctx);
|
this._compileNode(child, ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user