From 6a7721b05fd5b9d0f8078dc5dff337896a2c6d37 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 20 Mar 2019 22:27:10 -0400 Subject: [PATCH 1/2] replace comment anchors with empty text nodes - fixes #2280 --- src/compile/render-dom/wrappers/EachBlock.ts | 8 ++++---- src/compile/render-dom/wrappers/IfBlock.ts | 4 ++-- src/compile/render-dom/wrappers/shared/Wrapper.ts | 4 ++-- src/internal/dom.js | 4 ++++ test/js/samples/deconflict-builtins/expected.js | 4 ++-- test/js/samples/each-block-array-literal/expected.js | 4 ++-- test/js/samples/each-block-keyed-animated/expected.js | 4 ++-- test/js/samples/each-block-keyed/expected.js | 4 ++-- test/js/samples/if-block-no-update/expected.js | 4 ++-- test/js/samples/if-block-simple/expected.js | 4 ++-- test/js/samples/transition-local/expected.js | 6 +++--- test/js/samples/use-elements-as-anchors/expected.js | 4 ++-- 12 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/compile/render-dom/wrappers/EachBlock.ts b/src/compile/render-dom/wrappers/EachBlock.ts index 4c2504e8c3..cc9ebed833 100644 --- a/src/compile/render-dom/wrappers/EachBlock.ts +++ b/src/compile/render-dom/wrappers/EachBlock.ts @@ -207,8 +207,8 @@ export default class EachBlockWrapper extends Wrapper { if (needs_anchor) { block.add_element( this.vars.anchor, - `@comment()`, - parent_nodes && `@comment()`, + `@empty()`, + parent_nodes && `@empty()`, parent_node ); } @@ -300,8 +300,8 @@ export default class EachBlockWrapper extends Wrapper { this.block.first = this.block.get_unique_name('first'); this.block.add_element( this.block.first, - `@comment()`, - parent_nodes && `@comment()`, + `@empty()`, + parent_nodes && `@empty()`, null ); } diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index 2051429fda..f3b5c7f2b2 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -185,8 +185,8 @@ export default class IfBlockWrapper extends Wrapper { if (needs_anchor) { block.add_element( anchor, - `@comment()`, - parent_nodes && `@comment()`, + `@empty()`, + parent_nodes && `@empty()`, parent_node ); } diff --git a/src/compile/render-dom/wrappers/shared/Wrapper.ts b/src/compile/render-dom/wrappers/shared/Wrapper.ts index 7ec5868b20..2a9394415f 100644 --- a/src/compile/render-dom/wrappers/shared/Wrapper.ts +++ b/src/compile/render-dom/wrappers/shared/Wrapper.ts @@ -53,8 +53,8 @@ export default class Wrapper { if (needs_anchor) { block.add_element( anchor, - `@comment()`, - parent_nodes && `@comment()`, + `@empty()`, + parent_nodes && `@empty()`, parent_node ); } diff --git a/src/internal/dom.js b/src/internal/dom.js index 1c22bf4c70..9595652c66 100644 --- a/src/internal/dom.js +++ b/src/internal/dom.js @@ -54,6 +54,10 @@ export function comment() { return document.createComment(''); } +export function empty() { + return text(''); +} + export function listen(node, event, handler, options) { node.addEventListener(event, handler, options); return () => node.removeEventListener(event, handler, options); diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 32bbdb4394..3985faa362 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -2,10 +2,10 @@ import { SvelteComponent as SvelteComponent_1, append, - comment, destroy_each, detach, element, + empty, init, insert, noop, @@ -66,7 +66,7 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_1_anchor = comment(); + each_1_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js index be3b4a3b45..766cfceb71 100644 --- a/test/js/samples/each-block-array-literal/expected.js +++ b/test/js/samples/each-block-array-literal/expected.js @@ -2,10 +2,10 @@ import { SvelteComponent as SvelteComponent_1, append, - comment, destroy_each, detach, element, + empty, init, insert, noop, @@ -66,7 +66,7 @@ function create_fragment(ctx) { each_blocks[i].c(); } - each_1_anchor = comment(); + each_1_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index fd879530ea..aa9215b56d 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -3,10 +3,10 @@ import { SvelteComponent as SvelteComponent_1, append, blank_object, - comment, create_animation, detach, element, + empty, fix_and_outro_and_destroy_block, fix_position, init, @@ -89,7 +89,7 @@ function create_fragment(ctx) { c() { for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].c(); - each_1_anchor = comment(); + each_1_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index c20a43d4d4..8688d3af9a 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -3,10 +3,10 @@ import { SvelteComponent as SvelteComponent_1, append, blank_object, - comment, destroy_block, detach, element, + empty, init, insert, noop, @@ -73,7 +73,7 @@ function create_fragment(ctx) { c() { for (i = 0; i < each_blocks.length; i += 1) each_blocks[i].c(); - each_1_anchor = comment(); + each_1_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 11fbf604b1..1605696736 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,9 +1,9 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent as SvelteComponent_1, - comment, detach, element, + empty, init, insert, noop, @@ -68,7 +68,7 @@ function create_fragment(ctx) { return { c() { if_block.c(); - if_block_anchor = comment(); + if_block_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index af8d45974f..44c8ed31db 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,9 +1,9 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent as SvelteComponent_1, - comment, detach, element, + empty, init, insert, noop, @@ -40,7 +40,7 @@ function create_fragment(ctx) { return { c() { if (if_block) if_block.c(); - if_block_anchor = comment(); + if_block_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/transition-local/expected.js b/test/js/samples/transition-local/expected.js index b98d2a4520..85979e9959 100644 --- a/test/js/samples/transition-local/expected.js +++ b/test/js/samples/transition-local/expected.js @@ -2,10 +2,10 @@ import { SvelteComponent as SvelteComponent_1, add_render_callback, - comment, create_in_transition, detach, element, + empty, init, insert, noop, @@ -21,7 +21,7 @@ function create_if_block(ctx) { return { c() { if (if_block) if_block.c(); - if_block_anchor = comment(); + if_block_anchor = empty(); }, m(target, anchor) { @@ -98,7 +98,7 @@ function create_fragment(ctx) { return { c() { if (if_block) if_block.c(); - if_block_anchor = comment(); + if_block_anchor = empty(); }, m(target, anchor) { diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 7277dc8b7d..bb708284b4 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -2,9 +2,9 @@ import { SvelteComponent as SvelteComponent_1, append, - comment, detach, element, + empty, init, insert, noop, @@ -153,7 +153,7 @@ function create_fragment(ctx) { if (if_block3) if_block3.c(); t7 = space(); if (if_block4) if_block4.c(); - if_block4_anchor = comment(); + if_block4_anchor = empty(); }, m(target, anchor) { From 5a452dd06ceae2567b1da60bd7599b29e251f5a5 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 24 Mar 2019 21:44:30 -0400 Subject: [PATCH 2/2] remove comment --- src/internal/dom.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/internal/dom.js b/src/internal/dom.js index 9595652c66..2d661b5958 100644 --- a/src/internal/dom.js +++ b/src/internal/dom.js @@ -50,10 +50,6 @@ export function space() { return text(' '); } -export function comment() { - return document.createComment(''); -} - export function empty() { return text(''); }