From 718a25b53cfc073b523d7521cb48d89a8ecfbd99 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 3 Apr 2023 14:51:03 +0200 Subject: [PATCH] fix tests, handle Comment --- .../compile/render_dom/wrappers/Comment.ts | 6 ++++++ .../compile/render_dom/wrappers/Element/index.ts | 9 ++++++--- test/hydration/samples/claim-comment/_config.js | 15 --------------- .../raw-anchor-first-last-child/_config.js | 15 +-------------- 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Comment.ts b/src/compiler/compile/render_dom/wrappers/Comment.ts index a8c63b4227bf..9c4e2ffdfb6b 100644 --- a/src/compiler/compile/render_dom/wrappers/Comment.ts +++ b/src/compiler/compile/render_dom/wrappers/Comment.ts @@ -38,4 +38,10 @@ export default class CommentWrapper extends Wrapper { parent_node ); } + + text() { + if (!this.renderer.options.preserveComments) return ''; + + return ``; + } } diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 4687feaebf52..ebda5b4d37d5 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -29,6 +29,7 @@ import is_dynamic from '../shared/is_dynamic'; import { is_name_contenteditable, has_contenteditable_attr } from '../../../utils/contenteditable'; import create_debugging_comment from '../shared/create_debugging_comment'; import { push_array } from '../../../../utils/push_array'; +import CommentWrapper from '../Comment'; interface BindingGroup { events: string[]; @@ -499,7 +500,7 @@ export default class ElementWrapper extends Wrapper { }; const can_use_raw_text = !this.node.can_use_innerhtml && can_use_textcontent; - to_html((this.fragment.nodes as unknown as Array), block, literal, state, can_use_raw_text); + to_html((this.fragment.nodes as unknown as Array), block, literal, state, can_use_raw_text); literal.quasis.push(state.quasi as any); if (hydratable) { @@ -1250,9 +1251,11 @@ export default class ElementWrapper extends Wrapper { const regex_backticks = /`/g; const regex_dollar_signs = /\$/g; -function to_html(wrappers: Array, block: Block, literal: any, state: any, can_use_raw_text?: boolean) { +function to_html(wrappers: Array, block: Block, literal: any, state: any, can_use_raw_text?: boolean) { wrappers.forEach(wrapper => { - if (wrapper instanceof TextWrapper) { + if (wrapper instanceof CommentWrapper) { + state.quasi.value.raw += wrapper.text(); + } else if (wrapper instanceof TextWrapper) { // Don't add the
/