Skip to content

Commit b97573c

Browse files
committed
[WIP] fix problems with translation contexts + test
1 parent 01580f2 commit b97573c

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ function parseNode(node: Node, ctx: ParsingContext): AST | null {
259259
parseTForEach(node, ctx) ||
260260
parseTIf(node, ctx) ||
261261
parseTPortal(node, ctx) ||
262-
parseTCall(node, ctx) ||
263-
parseTCallBlock(node, ctx) ||
264262
parseTTranslation(node, ctx) ||
265263
parseTTranslationContext(node, ctx) ||
264+
parseTCall(node, ctx) ||
265+
parseTCallBlock(node, ctx) ||
266266
parseTKey(node, ctx) ||
267267
parseTEscNode(node, ctx) ||
268268
parseTOutNode(node, ctx) ||

tests/compiler/__snapshots__/t_call2.test.ts.snap

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,41 @@ exports[`t-call v_2 (template calling) scoped parameters, part 2 2`] = `
772772
}"
773773
`;
774774

775+
exports[`t-call v_2 (template calling) t-call and translation contexts 1`] = `
776+
"function anonymous(app, bdom, helpers
777+
) {
778+
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
779+
let { capture, zero } = helpers;
780+
const callTemplate_1 = app.getTemplate(\`sub\`);
781+
782+
function callBody1(ctx, node, key = \\"\\") {
783+
return text(\`jeu\`);
784+
}
785+
786+
return function template(ctx, node, key = \\"\\") {
787+
const ctx1 = capture(ctx);
788+
const lazyBlock1 = callBody1.bind(this, Object.create(ctx1));
789+
return callTemplate_1.call(this, {title: 'title', [zero]: lazyBlock1}, node, key + \`__1\`);
790+
}
791+
}"
792+
`;
793+
794+
exports[`t-call v_2 (template calling) t-call and translation contexts 2`] = `
795+
"function anonymous(app, bdom, helpers
796+
) {
797+
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
798+
let { zero } = helpers;
799+
800+
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
801+
802+
return function template(ctx, node, key = \\"\\") {
803+
let txt1 = ctx['title'];
804+
let txt2 = ctx[zero]?.(node, key);
805+
return block1([txt1, txt2]);
806+
}
807+
}"
808+
`;
809+
775810
exports[`t-call v_2 (template calling) t-call on a div with t-call-context 1`] = `
776811
"function anonymous(app, bdom, helpers
777812
) {

tests/compiler/t_call2.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,4 +557,18 @@ describe("t-call v_2 (template calling)", () => {
557557
context.addTemplate("main", `<t t-call="sub" v_2="1">Hello</t>`);
558558
expect(context.renderToString("main")).toBe("<span>1Hello</span>");
559559
});
560+
561+
test("t-call and translation contexts", () => {
562+
const translateFn = jest.fn((expr: string, translationCtx: string) =>
563+
translationCtx === "fr" ? "jeu" : translationCtx === "pt" ? "título" : expr
564+
);
565+
566+
const context = new TestContext({ translateFn });
567+
context.addTemplate("sub", `<span><t t-esc="title"/><t t-esc="0"/></span>`);
568+
context.addTemplate("main", `<t t-call="sub" title="'title'" t-translation-context-title="pt" t-translation-context="fr">game</t>`);
569+
570+
expect(context.renderToString("main")).toBe(
571+
"<span>títulojeu</span>"
572+
);
573+
});
560574
});

0 commit comments

Comments
 (0)