[FIX] t-call-context: fix capture making component available in ctx

Previously, when using a component with a slot within a t-call with
t-call-context, the component would become available again inside the
slot despite the t-call-context. This was caused by the fact that the
capture helper function creates an object with the component as its
prototype which is incorrect. It should just use the previous context as
its prototype.
This commit is contained in:
Samuel Degueldre
2023-01-04 13:45:18 +01:00
committed by Géry Debongnie
parent 39329f80b2
commit 3d40533de1
11 changed files with 136 additions and 62 deletions
+2 -2
View File
@@ -1140,7 +1140,7 @@ export class CodeGenerator {
if (this.target.loopLevel || !this.hasSafeContext) {
ctxStr = generateId("ctx");
this.helpers.add("capture");
this.define(ctxStr, `capture(ctx, this)`);
this.define(ctxStr, `capture(ctx)`);
}
let slotStr: string[] = [];
for (let slotName in ast.slots) {
@@ -1316,7 +1316,7 @@ export class CodeGenerator {
if (this.target.loopLevel || !this.hasSafeContext) {
ctxStr = generateId("ctx");
this.helpers.add("capture");
this.define(ctxStr, `capture(ctx, this)`);
this.define(ctxStr, `capture(ctx)`);
}
let id = generateId("comp");
this.staticDefs.push({
+3 -3
View File
@@ -46,8 +46,8 @@ function callSlot(
return slotBDom || text("");
}
function capture(ctx: any, component: any): any {
const result = ObjectCreate(component);
function capture(ctx: any): any {
const result = ObjectCreate(ctx);
for (let k in ctx) {
result[k] = ctx[k];
}
@@ -114,7 +114,7 @@ class LazyValue {
constructor(fn: any, ctx: any, component: any, node: any, key: any) {
this.fn = fn;
this.ctx = capture(ctx, component);
this.ctx = capture(ctx);
this.component = component;
this.node = node;
this.key = key;