Skip to content

Commit

Permalink
Correctly handle nbsp (closes #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Nov 13, 2017
1 parent 379255d commit 16675bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/program/types/JSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions test/samples/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,20 @@ module.exports = [
output: `
React.createElement( Thing, { 'data-foo': true })
`
},

{
description: 'handles non-breaking white-space entities',

input: `
<div>
<a>1</a>&nbsp;
&nbsp;
</div>
`,
output: `
React.createElement( 'div', null,
React.createElement( 'a', null, "1" ), "&nbsp; &nbsp;")
`
}
];

0 comments on commit 16675bb

Please sign in to comment.