From be783c5c67a0c8c5b8a02cecca5589ff508fabfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20K=C3=BC=C3=A7=C3=BCk?= Date: Sun, 16 Jun 2019 01:13:06 +0300 Subject: [PATCH] do not collapse whitespace containing nbsp (#3014) --- src/compiler/compile/nodes/Text.ts | 2 +- test/runtime/samples/nbsp-div/_config.js | 19 +++++++++++++++++++ test/runtime/samples/nbsp-div/main.svelte | 7 +++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/nbsp-div/_config.js create mode 100644 test/runtime/samples/nbsp-div/main.svelte diff --git a/src/compiler/compile/nodes/Text.ts b/src/compiler/compile/nodes/Text.ts index 7500f5ff30d9..a4514f56f26e 100644 --- a/src/compiler/compile/nodes/Text.ts +++ b/src/compiler/compile/nodes/Text.ts @@ -12,7 +12,7 @@ export default class Text extends Node { super(component, parent, scope, info); this.data = info.data; - if (!component.component_options.preserveWhitespace && !/\S/.test(info.data)) { + if (!component.component_options.preserveWhitespace && !/[\S\u00A0]/.test(info.data)) { let node = parent; while (node) { if (node.type === 'Element' && node.name === 'pre') { diff --git a/test/runtime/samples/nbsp-div/_config.js b/test/runtime/samples/nbsp-div/_config.js new file mode 100644 index 000000000000..6026af2c9090 --- /dev/null +++ b/test/runtime/samples/nbsp-div/_config.js @@ -0,0 +1,19 @@ +export default { + html: `
 hello
+
 hello  
+
 hello   hello
`, + + test({ assert, component, target }) { + var divList = target.querySelectorAll('div') + assert.equal( divList[0].textContent.charCodeAt( 0 ), 160 ); + assert.equal( divList[1].textContent.charCodeAt( 0 ), 160 ); + assert.equal( divList[1].textContent.charCodeAt( 6 ), 160 ); + assert.equal( divList[1].textContent.charCodeAt( 7 ), 160 ); + assert.equal( divList[2].textContent.charCodeAt( 0 ), 160 ); + assert.equal( divList[2].textContent.charCodeAt( 6 ), 160 ); + assert.equal( divList[2].textContent.charCodeAt( 7 ), 32 );//normal space + assert.equal( divList[2].textContent.charCodeAt( 8 ), 160 ); + + + } +}; \ No newline at end of file diff --git a/test/runtime/samples/nbsp-div/main.svelte b/test/runtime/samples/nbsp-div/main.svelte new file mode 100644 index 000000000000..64557bfeb142 --- /dev/null +++ b/test/runtime/samples/nbsp-div/main.svelte @@ -0,0 +1,7 @@ + + +
 {name}
+
 {name}  
+
 {name}   {name}
\ No newline at end of file