From cb6309b3b16c2516b4526b62ba9179664ef4f19a Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 16 Jun 2019 19:18:50 -0400 Subject: [PATCH] fix text nodes in .innerHTML-optimized output - collapse whitespace to single space when appropriate (#2745) - escape template string characters in script and style tags --- src/compiler/compile/render-dom/wrappers/Element/index.ts | 6 ++++-- test/runtime/samples/script-style-non-top-level/_config.js | 2 +- test/runtime/samples/script-style-non-top-level/main.svelte | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/compile/render-dom/wrappers/Element/index.ts b/src/compiler/compile/render-dom/wrappers/Element/index.ts index 2f7452e8c6fe..397ef0265524 100644 --- a/src/compiler/compile/render-dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render-dom/wrappers/Element/index.ts @@ -335,6 +335,8 @@ export default class ElementWrapper extends Wrapper { function to_html(wrapper: ElementWrapper | TextWrapper) { if (wrapper.node.type === 'Text') { + if (wrapper.node.use_space) return ' '; + const parent = wrapper.node.parent as Element; const raw = parent && ( @@ -342,9 +344,9 @@ export default class ElementWrapper extends Wrapper { parent.name === 'style' ); - return raw + return (raw ? wrapper.node.data - : escape_html(wrapper.node.data) + : escape_html(wrapper.node.data)) .replace(/\\/g, '\\\\') .replace(/`/g, '\\`') .replace(/\$/g, '\\$'); diff --git a/test/runtime/samples/script-style-non-top-level/_config.js b/test/runtime/samples/script-style-non-top-level/_config.js index 1aade72239df..86eddf46116e 100644 --- a/test/runtime/samples/script-style-non-top-level/_config.js +++ b/test/runtime/samples/script-style-non-top-level/_config.js @@ -2,7 +2,7 @@ export default { html: `
- +
` }; \ No newline at end of file diff --git a/test/runtime/samples/script-style-non-top-level/main.svelte b/test/runtime/samples/script-style-non-top-level/main.svelte index 94cf72e4bd90..73b0dfcf383b 100644 --- a/test/runtime/samples/script-style-non-top-level/main.svelte +++ b/test/runtime/samples/script-style-non-top-level/main.svelte @@ -1,4 +1,4 @@
- +
\ No newline at end of file