From f18ad5e6f6e6e0681c29c968fa0ca5372625558f Mon Sep 17 00:00:00 2001 From: qintarp Date: Fri, 14 Jun 2019 14:47:11 +0300 Subject: [PATCH] Fix div nbsp --- src/compiler/compile/render-dom/wrappers/Text.ts | 2 +- src/runtime/internal/dom.ts | 4 ++++ test/runtime/samples/nbsp-div/_config.js | 8 ++++++++ test/runtime/samples/nbsp-div/main.svelte | 6 ++++++ 4 files changed, 19 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/render-dom/wrappers/Text.ts b/src/compiler/compile/render-dom/wrappers/Text.ts index ceacae29ba..1781eb2e58 100644 --- a/src/compiler/compile/render-dom/wrappers/Text.ts +++ b/src/compiler/compile/render-dom/wrappers/Text.ts @@ -54,7 +54,7 @@ export default class TextWrapper extends Wrapper { block.add_element( this.var, - this.node.use_space ? `@space()` : `@text(${stringify(this.data)})`, + this.node.use_space ? (this.node.data && this.node.data.charCodeAt(0) === 160) ? `@nbsp()` : `@space()` : `@text(${stringify(this.data)})`, parent_nodes && `@claim_text(${parent_nodes}, ${stringify(this.data)})`, parent_node ); diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index f65d07117c..30962e74c7 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -66,6 +66,10 @@ export function space() { return text(' '); } +export function nbsp() { + return text(String.fromCharCode(160)); +} + export function empty() { return text(''); } diff --git a/test/runtime/samples/nbsp-div/_config.js b/test/runtime/samples/nbsp-div/_config.js new file mode 100644 index 0000000000..e292da9fbb --- /dev/null +++ b/test/runtime/samples/nbsp-div/_config.js @@ -0,0 +1,8 @@ +export default { + html: `
hello 
`, + + test({ assert, component, target }) { + const text = target.querySelector( 'div' ).textContent; + assert.equal( text.charCodeAt( 5 ), 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 0000000000..dac4b60514 --- /dev/null +++ b/test/runtime/samples/nbsp-div/main.svelte @@ -0,0 +1,6 @@ + + + +
{name}