From 61476048c86dd7b458e7a414cac63529af651e24 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 12 Sep 2017 17:15:15 -0400 Subject: [PATCH] dont use skipped text nodes as anchors - fixes #843 --- src/generators/dom/preprocess.ts | 2 ++ .../samples/svg-each-block-anchor/_config.js | 25 +++++++++++++++++++ .../samples/svg-each-block-anchor/main.html | 9 +++++++ 3 files changed, 36 insertions(+) create mode 100644 test/runtime/samples/svg-each-block-anchor/_config.js create mode 100644 test/runtime/samples/svg-each-block-anchor/main.html diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index e9aff13652..1e71361f31 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -417,6 +417,8 @@ function preprocessChildren( const preprocessor = preprocessors[child.type]; if (preprocessor) preprocessor(generator, block, state, child, inEachBlock, elementStack, componentStack, stripWhitespace, cleaned[i + 1] || nextSibling); + if (child.shouldSkip) return; + if (lastChild) lastChild.next = child; child.prev = lastChild; diff --git a/test/runtime/samples/svg-each-block-anchor/_config.js b/test/runtime/samples/svg-each-block-anchor/_config.js new file mode 100644 index 0000000000..9ca280965c --- /dev/null +++ b/test/runtime/samples/svg-each-block-anchor/_config.js @@ -0,0 +1,25 @@ +export default { + data: { + foo: ['a'], + bar: ['c'] + }, + + html: ` + + a + c + + `, + + test(assert, component, target) { + component.set({ foo: ['a', 'b'] }); + + assert.htmlEqual(target.innerHTML, ` + + a + b + c + + `); + } +}; diff --git a/test/runtime/samples/svg-each-block-anchor/main.html b/test/runtime/samples/svg-each-block-anchor/main.html new file mode 100644 index 0000000000..7a299b2c11 --- /dev/null +++ b/test/runtime/samples/svg-each-block-anchor/main.html @@ -0,0 +1,9 @@ + + {{#each foo as x}} + + {{/each}} + + {{#each bar as y}} + + {{/each}} + \ No newline at end of file