Skip to content

Commit

Permalink
Restore converting HTML entities in JSX
Browse files Browse the repository at this point in the history
I broke this in 16675bb. Closes #104.
  • Loading branch information
adrianheine committed Feb 5, 2018
1 parent 65891a8 commit 569dd07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/program/types/JSXElement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Node from '../Node.js';

function normalise(str, removeTrailingWhitespace) {

str = str.replace(/\u00a0/g, ' ');

if (removeTrailingWhitespace && /\n/.test(str)) {
str = str.replace(/\s+$/, '');
}
Expand Down Expand Up @@ -43,7 +46,7 @@ export default class JSXElement extends Node {
}

if (child.type === 'JSXText') {
const str = normalise(child.raw, i === children.length - 1);
const str = normalise(child.value, i === children.length - 1);
code.overwrite(child.start, child.end, str);
}

Expand Down
14 changes: 14 additions & 0 deletions test/samples/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,19 @@ module.exports = [
React.createElement( 'div', null,
React.createElement( 'a', null, "1" ), "   ")
`
},

{
description: 'transpiles entities',

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

0 comments on commit 569dd07

Please sign in to comment.