From b620502a0f46e8efbf5b31dceb959e18399daf09 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 24 Jun 2025 14:03:57 +0200 Subject: [PATCH] [FIX] parser: t-esc/t-out vs t-translation* The directives t-esc/t-out both discard the ASTs that are not of DomNode type. Since the directives t-translation and t-translation-context both creates AST wrappers of type TTranslation and TTranslationContext respectively, mix t-esc/t-out and t-translation/t-translation-context does not work. For example parse gives the AST { type: ASTType.TEsc, expr: "'Hello'", defaultValue: "", } This makes the span not been rendered in the end. We fix that problem. --- src/compiler/parser.ts | 4 +- tests/compiler/parser.test.ts | 98 +++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 760b8534..12fb592b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -253,11 +253,11 @@ function parseNode(node: Node, ctx: ParsingContext): AST | null { parseTPortal(node, ctx) || parseTCall(node, ctx) || parseTCallBlock(node, ctx) || + parseTTranslation(node, ctx) || + parseTTranslationContext(node, ctx) || parseTEscNode(node, ctx) || parseTOutNode(node, ctx) || parseTKey(node, ctx) || - parseTTranslation(node, ctx) || - parseTTranslationContext(node, ctx) || parseTSlot(node, ctx) || parseComponent(node, ctx) || parseDOMNode(node, ctx) || diff --git a/tests/compiler/parser.test.ts b/tests/compiler/parser.test.ts index de3db0bf..a7c9d505 100644 --- a/tests/compiler/parser.test.ts +++ b/tests/compiler/parser.test.ts @@ -1971,6 +1971,54 @@ describe("qweb parser", () => { }); }); + test('t-translation="off": interaction with t-esc', async () => { + expect(parse(``)).toEqual({ + type: ASTType.TTranslation, + content: { + attrs: null, + attrsTranslationCtx: null, + content: [ + { + defaultValue: "", + expr: "a", + type: ASTType.TEsc, + }, + ], + dynamicTag: null, + model: null, + ns: null, + on: null, + ref: null, + tag: "span", + type: ASTType.DomNode, + }, + }); + }); + + test('t-translation="off": interaction with t-out', async () => { + expect(parse(``)).toEqual({ + type: ASTType.TTranslation, + content: { + attrs: null, + attrsTranslationCtx: null, + content: [ + { + body: null, + expr: "a", + type: ASTType.TOut, + }, + ], + dynamicTag: null, + model: null, + ns: null, + on: null, + ref: null, + tag: "span", + type: ASTType.DomNode, + }, + }); + }); + // --------------------------------------------------------------------------- // t-translation-context // --------------------------------------------------------------------------- @@ -2008,6 +2056,56 @@ describe("qweb parser", () => { }); }); + test("t-translation-context: interaction with t-esc", async () => { + expect(parse(``)).toEqual({ + type: ASTType.TTranslationContext, + content: { + attrs: null, + attrsTranslationCtx: null, + content: [ + { + defaultValue: "", + expr: "a", + type: ASTType.TEsc, + }, + ], + dynamicTag: null, + model: null, + ns: null, + on: null, + ref: null, + tag: "span", + type: ASTType.DomNode, + }, + translationCtx: "fr", + }); + }); + + test("t-translation-context: interaction with t-out", async () => { + expect(parse(``)).toEqual({ + type: ASTType.TTranslationContext, + content: { + attrs: null, + attrsTranslationCtx: null, + content: [ + { + body: null, + expr: "a", + type: ASTType.TOut, + }, + ], + dynamicTag: null, + model: null, + ns: null, + on: null, + ref: null, + tag: "span", + type: ASTType.DomNode, + }, + translationCtx: "fr", + }); + }); + // --------------------------------------------------------------------------- // t-translation-context-attr // ---------------------------------------------------------------------------