[FIX] qweb: correctly capture the scope of arrow functions in props

This commit is contained in:
Samuel Degueldre
2021-12-02 12:05:16 +01:00
committed by Géry Debongnie
parent 150d620b8e
commit 718c765e3b
5 changed files with 542 additions and 2 deletions
+12 -1
View File
@@ -163,7 +163,18 @@ export class CompilationContext {
const done = new Set();
return tokens
.map((tok) => {
if (tok.varName) {
// "this" in captured expressions should be the current component
if (tok.value === "this") {
if (!done.has("this")) {
done.add("this");
this.addLine(`const this_${argId} = utils.getComponent(context);`);
}
tok.value = `this_${argId}`;
}
// Variables that should be looked up in the scope. isLocal is for arrow
// function arguments that should stay untouched (eg "ev => ev" should
// not become "const ev_1 = scope['ev']; ev_1 => ev_1")
if (tok.varName && !tok.isLocal) {
if (!done.has(tok.varName)) {
done.add(tok.varName);
this.addLine(`const ${tok.varName}_${argId} = ${tok.value};`);