Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel Transform JSX to React.jsx/React.jsxDEV Plugin #16432

Merged
merged 23 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fixed linter
  • Loading branch information
lunaruan committed Aug 16, 2019
commit 938d1638343ae69d9a6b5a5e140e82edf8e064a3
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ describe('transform react to jsx', () => {
).toMatchSnapshot();
});
it('should escape xhtml jsxtext', () => {
/* eslint-disable no-irregular-whitespace */
expect(
transform(`
<div>wow</div>;
Expand All @@ -295,6 +296,7 @@ describe('transform react to jsx', () => {
<div>w &lt; w</div>;
`)
).toMatchSnapshot();
/*eslint-enable */
});
it('should handle attributed elements', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ describe('transform react to jsx', () => {
).toMatchSnapshot();
});
it('should escape xhtml jsxtext', () => {
/* eslint-disable no-irregular-whitespace */
expect(
transform(`
<div>wow</div>;
Expand All @@ -376,6 +377,7 @@ describe('transform react to jsx', () => {
<div>w &lt; w</div>;
`)
).toMatchSnapshot();
/*eslint-enable */
});
it('should handle attributed elements', () => {
expect(
Expand Down
20 changes: 15 additions & 5 deletions packages/react-jsx-babel-plugin/transform-jsx-to-react-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
// Production: React.jsx(type, arguments, key)
// Development: React.jsxDEV(type, arguments, key, isStaticChildren, source, self)
function buildJSXElementCall(path, file) {
if (opts.filter && !opts.filter(path.node, file)) return;
if (opts.filter && !opts.filter(path.node, file)) {
return;
}

const openingPath = path.get('openingElement');
openingPath.parent.children = t.react.buildChildren(openingPath.parent);
Expand Down Expand Up @@ -313,7 +315,9 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
// Production: React.jsx(type, arguments)
// Development: React.jsxDEV(type, { children})
function buildJSXFragmentCall(path, file) {
if (opts.filter && !opts.filter(path.node, file)) return;
if (opts.filter && !opts.filter(path.node, file)) {
return;
}

const openingPath = path.get('openingElement');
openingPath.parent.children = t.react.buildChildren(openingPath.parent);
Expand Down Expand Up @@ -367,7 +371,9 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
// Production: React.createElement(type, arguments, children)
// Development: React.createElement(type, arguments, children, source, self)
function buildCreateElementCall(path, file) {
if (opts.filter && !opts.filter(path.node, file)) return;
if (opts.filter && !opts.filter(path.node, file)) {
return;
}

const openingPath = path.get('openingElement');
openingPath.parent.children = t.react.buildChildren(openingPath.parent);
Expand Down Expand Up @@ -412,7 +418,9 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
}

function pushProps(_props, objs) {
if (!_props.length) return _props;
if (!_props.length) {
return _props;
}

objs.push(t.objectExpression(_props));
return [];
Expand Down Expand Up @@ -470,7 +478,9 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
}

function buildCreateElementFragmentCall(path, file) {
if (opts.filter && !opts.filter(path.node, file)) return;
if (opts.filter && !opts.filter(path.node, file)) {
return;
}

const openingPath = path.get('openingElement');
openingPath.parent.children = t.react.buildChildren(openingPath.parent);
Expand Down