Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/__tests__/create-element-to-jsx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe('create-element-to-jsx', () => {
test('create-element-to-jsx', 'create-element-to-jsx-call-expression-as-prop');

test('create-element-to-jsx', 'create-element-to-jsx-allow-member-expression');

test('create-element-to-jsx', 'create-element-to-jsx-gt-lt-entities');
});

it('raises when it does not recognize a property type', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/create-element-to-jsx-gt-lt-entities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var React = require('React');

React.createElement('div', null, '\x3C\x3E');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\x3C\x3E is how our CJSX compiler ends up outputting to ES5. I'm not sure if I should add support for other ways of writing these characters as well.

3 changes: 3 additions & 0 deletions test/create-element-to-jsx-gt-lt-entities.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var React = require('React');

<div>&lt;&gt;</div>;
6 changes: 5 additions & 1 deletion transforms/create-element-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module.exports = function(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
const ReactUtils = require('./utils/ReactUtils')(j);
const encodeJSXTextValue = value =>
value
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');

const convertExpressionToJSXAttributes = (expression) => {
const isReactSpread = expression.type === 'CallExpression' &&
Expand Down Expand Up @@ -89,7 +93,7 @@ module.exports = function(file, api, options) {

const children = node.value.arguments.slice(2).map((child, index) => {
if (child.type === 'Literal' && typeof child.value === 'string') {
return j.jsxText(child.value);
return j.jsxText(encodeJSXTextValue(child.value));
} else if (child.type === 'CallExpression' &&
child.callee.object &&
child.callee.object.name === 'React' &&
Expand Down