diff --git a/src/program/types/JSXElement.js b/src/program/types/JSXElement.js index 4cb4de13..7fa7468f 100644 --- a/src/program/types/JSXElement.js +++ b/src/program/types/JSXElement.js @@ -21,7 +21,7 @@ export default class JSXElement extends Node { if (child.type !== 'Literal') return true; // remove whitespace-only literals, unless on a single line - return /\S/.test(child.value) || !/\n/.test(child.value); + return /\S/.test(child.raw) || !/\n/.test(child.raw); }); if (children.length) { @@ -43,7 +43,7 @@ export default class JSXElement extends Node { } if (child.type === 'Literal') { - const str = normalise(child.value, i === children.length - 1); + const str = normalise(child.raw, i === children.length - 1); code.overwrite(child.start, child.end, str); } diff --git a/test/samples/jsx.js b/test/samples/jsx.js index 745ca810..da5b1466 100644 --- a/test/samples/jsx.js +++ b/test/samples/jsx.js @@ -272,5 +272,20 @@ module.exports = [ output: ` React.createElement( Thing, { 'data-foo': true }) ` + }, + + { + description: 'handles non-breaking white-space entities', + + input: ` +