From 569dd0746d540d4ae7d2225345a921c47a1bf3fb Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Mon, 5 Feb 2018 15:35:19 +0100 Subject: [PATCH] Restore converting HTML entities in JSX I broke this in 16675bb146b9584e4c37e264068f44d3bbab3abb. Closes #104. --- src/program/types/JSXElement.js | 5 ++++- test/samples/jsx.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/program/types/JSXElement.js b/src/program/types/JSXElement.js index a75d56b7..7ca888a4 100644 --- a/src/program/types/JSXElement.js +++ b/src/program/types/JSXElement.js @@ -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+$/, ''); } @@ -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); } diff --git a/test/samples/jsx.js b/test/samples/jsx.js index dd155ca2..e23f91ec 100644 --- a/test/samples/jsx.js +++ b/test/samples/jsx.js @@ -293,5 +293,19 @@ module.exports = [ React.createElement( 'div', null, React.createElement( 'a', null, "1" ), "   ") ` + }, + + { + description: 'transpiles entities', + + input: ` +
+ 1<  +
+ `, + output: ` + React.createElement( 'div', null, + React.createElement( 'a', null, "1<" ), " ") + ` } ];