From 7042f5d2cbbef855a0ecafef9a2de7aea80e437e Mon Sep 17 00:00:00 2001 From: ekhaled Date: Wed, 25 Jul 2018 18:45:50 +0100 Subject: [PATCH 1/3] failing test for #1598 --- .../samples/set-null-text-node/_config.js | 22 +++++++++++++++++++ .../samples/set-null-text-node/main.html | 1 + 2 files changed, 23 insertions(+) create mode 100644 test/runtime/samples/set-null-text-node/_config.js create mode 100644 test/runtime/samples/set-null-text-node/main.html diff --git a/test/runtime/samples/set-null-text-node/_config.js b/test/runtime/samples/set-null-text-node/_config.js new file mode 100644 index 000000000000..22a2e322ec29 --- /dev/null +++ b/test/runtime/samples/set-null-text-node/_config.js @@ -0,0 +1,22 @@ +const data = { foo: null }; + +export default { + data, + + html: '', + + test(assert, component, target) { + assert.htmlEqual(target.innerHTML, 'hi there'); + + data.foo = 'friend'; + component.set(data); + + assert.htmlEqual(target.innerHTML, 'hi there friend'); + + data.foo = null; + component.set(data); + + assert.htmlEqual(target.innerHTML, 'hi there'); + + } +}; \ No newline at end of file diff --git a/test/runtime/samples/set-null-text-node/main.html b/test/runtime/samples/set-null-text-node/main.html new file mode 100644 index 000000000000..30fd0b39326a --- /dev/null +++ b/test/runtime/samples/set-null-text-node/main.html @@ -0,0 +1 @@ +hi there {foo} \ No newline at end of file From 9964a77565565923b149cb6d77ca47a08159ce23 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 4 Aug 2018 09:31:24 -0400 Subject: [PATCH 2/3] stringify values before setting text data - fixes #1598 --- src/compile/nodes/MustacheTag.ts | 2 +- src/shared/dom.js | 4 ++++ .../expected-bundle.js | 6 +++++- .../expected.js | 4 ++-- .../deconflict-builtins/expected-bundle.js | 6 +++++- .../samples/deconflict-builtins/expected.js | 4 ++-- .../expected-bundle.js | 8 +++++-- .../expected.js | 6 +++--- .../expected-bundle.js | 10 ++++++--- .../each-block-changed-check/expected.js | 8 +++---- .../expected-bundle.js | 6 +++++- .../each-block-keyed-animated/expected.js | 4 ++-- .../each-block-keyed/expected-bundle.js | 6 +++++- test/js/samples/each-block-keyed/expected.js | 4 ++-- test/js/samples/input-files/expected.js | 2 +- .../window-binding-scroll/expected-bundle.js | 6 +++++- .../samples/window-binding-scroll/expected.js | 4 ++-- .../samples/set-null-text-node/_config.js | 21 ++++++------------- .../samples/set-null-text-node/main.html | 2 +- 19 files changed, 68 insertions(+), 45 deletions(-) diff --git a/src/compile/nodes/MustacheTag.ts b/src/compile/nodes/MustacheTag.ts index 7c3f0a96c4e2..630aebb41b6a 100644 --- a/src/compile/nodes/MustacheTag.ts +++ b/src/compile/nodes/MustacheTag.ts @@ -10,7 +10,7 @@ export default class MustacheTag extends Tag { ) { const { init } = this.renameThisMethod( block, - value => `${this.var}.data = ${value};` + value => `@setData(${this.var}, ${value});` ); block.addElement( diff --git a/src/shared/dom.js b/src/shared/dom.js index c417c5f6b8d5..03aaf8aaeb39 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -155,6 +155,10 @@ export function claimText (nodes, data) { return createText(data); } +export function setData(text, data) { + text.data = '' + data; +} + export function setInputType(input, type) { try { input.type = type; diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index f9438487aeb1..32e1f8f20448 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -25,6 +25,10 @@ function createText(data) { return document.createTextNode(data); } +function setData(text, data) { + text.data = '' + data; +} + function blankObject() { return Object.create(null); } @@ -167,7 +171,7 @@ function create_main_fragment(component, ctx) { p(changed, ctx) { if (changed.foo) { - text.data = ctx.foo; + setData(text, ctx.foo); } }, diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 0c94fc835613..d9b9c4072930 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto, setData } from "svelte/shared.js"; function data() { return { foo: 42 } @@ -29,7 +29,7 @@ function create_main_fragment(component, ctx) { p(changed, ctx) { if (changed.foo) { - text.data = ctx.foo; + setData(text, ctx.foo); } }, diff --git a/test/js/samples/deconflict-builtins/expected-bundle.js b/test/js/samples/deconflict-builtins/expected-bundle.js index 5be78115b902..a5b88693fc83 100644 --- a/test/js/samples/deconflict-builtins/expected-bundle.js +++ b/test/js/samples/deconflict-builtins/expected-bundle.js @@ -35,6 +35,10 @@ function createComment() { return document.createComment(''); } +function setData(text, data) { + text.data = '' + data; +} + function blankObject() { return Object.create(null); } @@ -228,7 +232,7 @@ function create_each_block(component, ctx) { p(changed, ctx) { if ((changed.createElement) && text_value !== (text_value = ctx.node)) { - text.data = text_value; + setData(text, text_value); } }, diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 28aed03cca65..343a0ffcbc9e 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createComment, createElement, createText, destroyEach, detachNode, init, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, destroyEach, detachNode, init, insertNode, proto, setData } from "svelte/shared.js"; function create_main_fragment(component, ctx) { var each_anchor; @@ -79,7 +79,7 @@ function create_each_block(component, ctx) { p(changed, ctx) { if ((changed.createElement) && text_value !== (text_value = ctx.node)) { - text.data = text_value; + setData(text, text_value); } }, diff --git a/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js b/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js index 7df754d670cc..d30075c63ff2 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js @@ -31,6 +31,10 @@ function createText(data) { return document.createTextNode(data); } +function setData(text, data) { + text.data = '' + data; +} + function blankObject() { return Object.create(null); } @@ -191,11 +195,11 @@ function create_main_fragment(component, ctx) { p: function update(changed, ctx) { if ((changed.Math || changed.foo) && text_value !== (text_value = ctx.Math.max(0, ctx.foo))) { - text.data = text_value; + setData(text, text_value); } if (changed.bar) { - text_2.data = ctx.bar; + setData(text_2, ctx.bar); } }, diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index 834da725e775..c71193e6443e 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { addLoc, appendNode, assign, createElement, createText, detachNode, init, insertNode, protoDev } from "svelte/shared.js"; +import { addLoc, appendNode, assign, createElement, createText, detachNode, init, insertNode, protoDev, setData } from "svelte/shared.js"; function bar({ foo }) { return foo * 2; @@ -28,11 +28,11 @@ function create_main_fragment(component, ctx) { p: function update(changed, ctx) { if ((changed.Math || changed.foo) && text_value !== (text_value = ctx.Math.max(0, ctx.foo))) { - text.data = text_value; + setData(text, text_value); } if (changed.bar) { - text_2.data = ctx.bar; + setData(text_2, ctx.bar); } }, diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 1eb4cd25b1de..23b20e5e2116 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -37,6 +37,10 @@ function createText(data) { return document.createTextNode(data); } +function setData(text, data) { + text.data = '' + data; +} + function blankObject() { return Object.create(null); } @@ -207,7 +211,7 @@ function create_main_fragment(component, ctx) { } if (changed.foo) { - text_1.data = ctx.foo; + setData(text_1, ctx.foo); } }, @@ -260,11 +264,11 @@ function create_each_block(component, ctx) { p(changed, ctx) { if ((changed.comments) && text_2_value !== (text_2_value = ctx.comment.author)) { - text_2.data = text_2_value; + setData(text_2, text_2_value); } if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = ctx.elapsed(ctx.comment.time, ctx.time))) { - text_4.data = text_4_value; + setData(text_4, text_4_value); } if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html)) { diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 7b9a53a76f29..07dc9d201311 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, proto, setData } from "svelte/shared.js"; function create_main_fragment(component, ctx) { var text, p, text_1; @@ -56,7 +56,7 @@ function create_main_fragment(component, ctx) { } if (changed.foo) { - text_1.data = ctx.foo; + setData(text_1, ctx.foo); } }, @@ -109,11 +109,11 @@ function create_each_block(component, ctx) { p(changed, ctx) { if ((changed.comments) && text_2_value !== (text_2_value = ctx.comment.author)) { - text_2.data = text_2_value; + setData(text_2, text_2_value); } if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = ctx.elapsed(ctx.comment.time, ctx.time))) { - text_4.data = text_4_value; + setData(text_4, text_4_value); } if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html)) { diff --git a/test/js/samples/each-block-keyed-animated/expected-bundle.js b/test/js/samples/each-block-keyed-animated/expected-bundle.js index 9bf521964ce9..c4fd56c1fff7 100644 --- a/test/js/samples/each-block-keyed-animated/expected-bundle.js +++ b/test/js/samples/each-block-keyed-animated/expected-bundle.js @@ -29,6 +29,10 @@ function createComment() { return document.createComment(''); } +function setData(text, data) { + text.data = '' + data; +} + function linear(t) { return t; } @@ -533,7 +537,7 @@ function create_each_block(component, key_1, ctx) { p(changed, ctx) { if ((changed.things) && text_value !== (text_value = ctx.thing.name)) { - text.data = text_value; + setData(text, text_value); } }, diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index 99ff9b03fe99..c47b896a5e1d 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, blankObject, createComment, createElement, createText, detachNode, fixAndOutroAndDestroyBlock, fixPosition, init, insertNode, proto, updateKeyedEach, wrapAnimation } from "svelte/shared.js"; +import { appendNode, assign, blankObject, createComment, createElement, createText, detachNode, fixAndOutroAndDestroyBlock, fixPosition, init, insertNode, proto, setData, updateKeyedEach, wrapAnimation } from "svelte/shared.js"; function foo(node, animation, params) { const dx = animation.from.left - animation.to.left; @@ -80,7 +80,7 @@ function create_each_block(component, key_1, ctx) { p(changed, ctx) { if ((changed.things) && text_value !== (text_value = ctx.thing.name)) { - text.data = text_value; + setData(text, text_value); } }, diff --git a/test/js/samples/each-block-keyed/expected-bundle.js b/test/js/samples/each-block-keyed/expected-bundle.js index 51978b8df5c6..075112f47f05 100644 --- a/test/js/samples/each-block-keyed/expected-bundle.js +++ b/test/js/samples/each-block-keyed/expected-bundle.js @@ -29,6 +29,10 @@ function createComment() { return document.createComment(''); } +function setData(text, data) { + text.data = '' + data; +} + function destroyBlock(block, lookup) { block.d(1); lookup[block.key] = null; @@ -298,7 +302,7 @@ function create_each_block(component, key_1, ctx) { p(changed, ctx) { if ((changed.things) && text_value !== (text_value = ctx.thing.name)) { - text.data = text_value; + setData(text, text_value); } }, diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index b3dbca0615f6..715e1f8c5ca0 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, blankObject, createComment, createElement, createText, destroyBlock, detachNode, init, insertNode, proto, updateKeyedEach } from "svelte/shared.js"; +import { appendNode, assign, blankObject, createComment, createElement, createText, destroyBlock, detachNode, init, insertNode, proto, setData, updateKeyedEach } from "svelte/shared.js"; function create_main_fragment(component, ctx) { var each_blocks_1 = [], each_lookup = blankObject(), each_anchor; @@ -64,7 +64,7 @@ function create_each_block(component, key_1, ctx) { p(changed, ctx) { if ((changed.things) && text_value !== (text_value = ctx.thing.name)) { - text.data = text_value; + setData(text, text_value); } }, diff --git a/test/js/samples/input-files/expected.js b/test/js/samples/input-files/expected.js index b16c239ff5f0..8ca7fa17e542 100644 --- a/test/js/samples/input-files/expected.js +++ b/test/js/samples/input-files/expected.js @@ -52,4 +52,4 @@ function SvelteComponent(options) { } assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js index 64d397a98242..2e3f892fdf15 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -25,6 +25,10 @@ function createText(data) { return document.createTextNode(data); } +function setData(text, data) { + text.data = '' + data; +} + function blankObject() { return Object.create(null); } @@ -178,7 +182,7 @@ function create_main_fragment(component, ctx) { p(changed, ctx) { if (changed.y) { - text_1.data = ctx.y; + setData(text_1, ctx.y); } }, diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index 29461610c956..126f43753753 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto, setData } from "svelte/shared.js"; function create_main_fragment(component, ctx) { var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1; @@ -39,7 +39,7 @@ function create_main_fragment(component, ctx) { p(changed, ctx) { if (changed.y) { - text_1.data = ctx.y; + setData(text_1, ctx.y); } }, diff --git a/test/runtime/samples/set-null-text-node/_config.js b/test/runtime/samples/set-null-text-node/_config.js index 22a2e322ec29..f0a7fd1df3c2 100644 --- a/test/runtime/samples/set-null-text-node/_config.js +++ b/test/runtime/samples/set-null-text-node/_config.js @@ -1,22 +1,13 @@ -const data = { foo: null }; - export default { - data, + data: { foo: null }, - html: '', + html: 'foo is null', test(assert, component, target) { - assert.htmlEqual(target.innerHTML, 'hi there'); - - data.foo = 'friend'; - component.set(data); - - assert.htmlEqual(target.innerHTML, 'hi there friend'); - - data.foo = null; - component.set(data); - - assert.htmlEqual(target.innerHTML, 'hi there'); + component.set({ foo: 42 }); + assert.htmlEqual(target.innerHTML, 'foo is 42'); + component.set({ foo: null }); + assert.htmlEqual(target.innerHTML, 'foo is null'); } }; \ No newline at end of file diff --git a/test/runtime/samples/set-null-text-node/main.html b/test/runtime/samples/set-null-text-node/main.html index 30fd0b39326a..bf9a9ffe597f 100644 --- a/test/runtime/samples/set-null-text-node/main.html +++ b/test/runtime/samples/set-null-text-node/main.html @@ -1 +1 @@ -hi there {foo} \ No newline at end of file +foo is {foo} \ No newline at end of file From a823ff32a9314217225906e661669013e246e7ea Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 4 Aug 2018 09:37:39 -0400 Subject: [PATCH 3/3] update CLI tests --- test/cli/samples/globals/expected/Main.js | 6 +++++- test/cli/samples/store/expected/Main.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/cli/samples/globals/expected/Main.js b/test/cli/samples/globals/expected/Main.js index 3b1a574c2a68..3e7b3b95b0ea 100644 --- a/test/cli/samples/globals/expected/Main.js +++ b/test/cli/samples/globals/expected/Main.js @@ -26,7 +26,7 @@ var Main = (function(answer) { "use strict"; p(changed, ctx) { if (changed.answer) { - text_1.data = ctx.answer; + setData(text_1, ctx.answer); } }, @@ -80,6 +80,10 @@ var Main = (function(answer) { "use strict"; target.appendChild(node); } + function setData(text, data) { + text.data = '' + data; + } + function detachNode(node) { node.parentNode.removeChild(node); } diff --git a/test/cli/samples/store/expected/Main.js b/test/cli/samples/store/expected/Main.js index 85e3e790b388..0042c82b4b5d 100644 --- a/test/cli/samples/store/expected/Main.js +++ b/test/cli/samples/store/expected/Main.js @@ -18,7 +18,7 @@ function create_main_fragment(component, ctx) { p(changed, ctx) { if (changed.$name) { - text_1.data = ctx.$name; + setData(text_1, ctx.$name); } }, @@ -75,6 +75,10 @@ function appendNode(node, target) { target.appendChild(node); } +function setData(text, data) { + text.data = '' + data; +} + function detachNode(node) { node.parentNode.removeChild(node); }