[FIX] code generator: prevent AST change

This commit removes an AST change during the code generation of slots.
Before, the `compileTSlot` function deleted the `t-props` attribute
directly on `ast.attrs`. This creates wrong code when compiling a
second time as the `t-props` attribute does not exist anymore.
This commit is contained in:
Michaël Mattiello
2025-02-21 12:03:59 +01:00
committed by Géry Debongnie
parent cf8039f643
commit 2b5cea944b
3 changed files with 32 additions and 5 deletions
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`t-slot compile t-props correctly multiple time 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { callSlot } = helpers;
return function template(ctx, node, key = \\"\\") {
return callSlot(ctx, node, key, 'default', false, Object.assign({}, {a:1}));
}
}"
`;
+15
View File
@@ -0,0 +1,15 @@
import { parseXML } from "../../src/common/utils";
import { compile } from "../../src/compiler";
describe("t-slot", () => {
test("compile t-props correctly multiple time", () => {
const template = `<t t-slot="default" t-props="{ a: 1 }"/>`;
const parsedTemplate = parseXML(template).firstChild as Element;
const fn1 = compile(parsedTemplate);
expect(fn1.toString()).toMatchSnapshot();
const fn2 = compile(parsedTemplate);
expect(fn2.toString()).toBe(fn1.toString());
});
});