From c8db663869a28499b223725ed293ad0d9b420835 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 2 Dec 2021 18:06:03 +0100 Subject: [PATCH] [FIX] parser: correctly parse pre node within a div with new lines --- src/compiler/parser.ts | 1 + .../__snapshots__/white_space.test.ts.snap | 13 ++++++++++ tests/compiler/parser.test.ts | 26 +++++++++++++++++++ tests/compiler/white_space.test.ts | 6 +++++ 4 files changed, 46 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 63ac828b..ebe5f0e4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -298,6 +298,7 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null { if (tagName === "t" && !dynamicTag) { return null; } + ctx = Object.assign({}, ctx); const children: AST[] = []; if (tagName === "pre") { ctx.inPreTag = true; diff --git a/tests/compiler/__snapshots__/white_space.test.ts.snap b/tests/compiler/__snapshots__/white_space.test.ts.snap index 9f5a8249..974e8adc 100644 --- a/tests/compiler/__snapshots__/white_space.test.ts.snap +++ b/tests/compiler/__snapshots__/white_space.test.ts.snap @@ -56,6 +56,19 @@ exports[`white space handling nothing is done in pre tags 3`] = ` }" `; +exports[`white space handling pre inside a div with a new line 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + let block1 = createBlock(\`
SomeText
\`); + + return function template(ctx, node, key = \\"\\") { + return block1(); + } +}" +`; + exports[`white space handling white space only text nodes are condensed into a single space 1`] = ` "function anonymous(bdom, helpers ) { diff --git a/tests/compiler/parser.test.ts b/tests/compiler/parser.test.ts index 9f1d102a..366d044b 100644 --- a/tests/compiler/parser.test.ts +++ b/tests/compiler/parser.test.ts @@ -255,6 +255,32 @@ describe("qweb parser", () => { }); }); + test("pre dom node with new line", async () => { + expect(parse(`
\n
`)).toEqual({ + type: 2, + tag: "div", + dynamicTag: null, + attrs: {}, + on: {}, + ref: null, + content: [ + { + type: 2, + tag: "pre", + dynamicTag: null, + attrs: {}, + on: {}, + ref: null, + content: [], + model: null, + ns: null, + }, + ], + model: null, + ns: null, + }); + }); + // --------------------------------------------------------------------------- // t-esc // --------------------------------------------------------------------------- diff --git a/tests/compiler/white_space.test.ts b/tests/compiler/white_space.test.ts index 1fdf096d..44f2b95e 100644 --- a/tests/compiler/white_space.test.ts +++ b/tests/compiler/white_space.test.ts @@ -39,4 +39,10 @@ describe("white space handling", () => { `; expect(renderToString(template3)).toBe(template3); }); + + test("pre inside a div with a new line", () => { + expect(renderToString(`
SomeText
\n
`)).toBe( + "
SomeText
" + ); + }); });