[FIX] compiler: do not pass dynamic props object as is

The child receiving the props can observe changes made to the passed
t-props object which is not desirable.
This commit is contained in:
Samuel Degueldre
2022-01-27 12:58:04 +01:00
committed by Géry Debongnie
parent 3f575148b6
commit 6f0a4b1c92
4 changed files with 48 additions and 6 deletions
+20 -2
View File
@@ -53,7 +53,7 @@ describe("t-props", () => {
});
test("basic use", async () => {
expect.assertions(5);
expect.assertions(4);
let props = { a: 1, b: 2 };
@@ -65,7 +65,6 @@ describe("t-props", () => {
`;
setup() {
expect(this.props).toEqual({ a: 1, b: 2 });
expect(this.props).toBe(props);
}
}
class Parent extends Component {
@@ -105,4 +104,23 @@ describe("t-props", () => {
await mount(Parent, fixture);
});
test("child receives a copy of the t-props object, not the original", async () => {
class Child extends Component {
static template = xml`<div/>`;
setup() {
expect(this.props).toEqual({ a: 1, b: 2 });
this.props.d = 5;
}
}
class Parent extends Component {
static template = xml`<Child t-props="childProps"/>`;
static components = { Child };
childProps = { a: 1, b: 2 };
}
const parent = await mount(Parent, fixture);
expect(parent.childProps).not.toHaveProperty("d");
});
});