From 7d4990c5d47eec078548fa806d61cac5687edc07 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 11 Apr 2022 09:50:56 +0900 Subject: [PATCH] Strip newline logic to src/compiler/compile/nodes/Eleement.ts --- src/compiler/compile/nodes/Element.ts | 16 ++++++++++------ src/compiler/compile/nodes/Text.ts | 9 --------- .../compile/render_dom/wrappers/Fragment.ts | 3 --- .../compile/render_ssr/handlers/Element.ts | 10 ++++++++++ .../samples/pre-tag/_expected.html | 12 ++++-------- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 4ca28ca736..55b7fbfb9d 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -198,6 +198,16 @@ export default class Element extends Node { this.namespace = get_namespace(parent as Element, this, component.namespace); if (this.namespace !== namespaces.foreign) { + if (this.name === 'pre' || this.name === 'textarea') { + const first = info.children[0]; + if (first && first.type === 'Text') { + // The leading newline character should be stripped. + // see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions + // see https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element + first.data = first.data.replace(start_newline, ''); + } + } + if (this.name === 'textarea') { if (info.children.length > 0) { const value_attribute = info.attributes.find(node => node.name === 'value'); @@ -208,12 +218,6 @@ export default class Element extends Node { // this is an egregious hack, but it's the easiest way to get