Mark transpiled JSX elements as pure (#11126)
* Mark transpiled JSX elements as pure * Avoid duble annotation * Add "pure" option to the React preset * Fix generator indentation * Update tests * Add tests for the "pure" option * Update windows fixtures
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-annotate-as-pure": "^7.8.3",
|
||||
"@babel/helper-plugin-utils": "^7.8.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import { types as t } from "@babel/core";
|
||||
import annotateAsPure from "@babel/helper-annotate-as-pure";
|
||||
|
||||
export default declare((api, options) => {
|
||||
api.assertVersion(7);
|
||||
@@ -107,13 +106,7 @@ export default declare((api, options) => {
|
||||
// Traverse all props passed to this element for immutability.
|
||||
path.traverse(immutabilityVisitor, state);
|
||||
|
||||
if (state.isImmutable) {
|
||||
const hoisted = path.hoist();
|
||||
|
||||
if (hoisted) {
|
||||
annotateAsPure(hoisted);
|
||||
}
|
||||
}
|
||||
if (state.isImmutable) path.hoist();
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var _ref = /*#__PURE__*/<div>child</div>;
|
||||
var _ref = <div>child</div>;
|
||||
|
||||
const AppItem = () => {
|
||||
return _ref;
|
||||
};
|
||||
|
||||
var _ref2 = /*#__PURE__*/<div>
|
||||
var _ref2 = <div>
|
||||
<p>Parent</p>
|
||||
<AppItem />
|
||||
</div>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var _ref2 = /*#__PURE__*/<div>child</div>;
|
||||
var _ref2 = <div>child</div>;
|
||||
|
||||
var _ref3 = /*#__PURE__*/<p>Parent</p>;
|
||||
var _ref3 = <p>Parent</p>;
|
||||
|
||||
(function () {
|
||||
class App extends React.Component {
|
||||
@@ -13,7 +13,7 @@ var _ref3 = /*#__PURE__*/<p>Parent</p>;
|
||||
const AppItem = () => {
|
||||
return _ref2;
|
||||
},
|
||||
_ref = /*#__PURE__*/<div>
|
||||
_ref = <div>
|
||||
{_ref3}
|
||||
<AppItem />
|
||||
</div>;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var _ref = /*#__PURE__*/<div>child</div>;
|
||||
var _ref = <div>child</div>;
|
||||
|
||||
var _ref3 = /*#__PURE__*/<p>Parent</p>;
|
||||
var _ref3 = <p>Parent</p>;
|
||||
|
||||
(function () {
|
||||
const AppItem = () => {
|
||||
return _ref;
|
||||
};
|
||||
|
||||
var _ref2 = /*#__PURE__*/<div>
|
||||
var _ref2 = <div>
|
||||
{_ref3}
|
||||
<AppItem />
|
||||
</div>;
|
||||
|
||||
@@ -5,12 +5,12 @@ export default class App extends React.Component {
|
||||
|
||||
}
|
||||
|
||||
var _ref2 = /*#__PURE__*/<div>child</div>;
|
||||
var _ref2 = <div>child</div>;
|
||||
|
||||
const AppItem = () => {
|
||||
return _ref2;
|
||||
},
|
||||
_ref = /*#__PURE__*/<div>
|
||||
_ref = <div>
|
||||
<p>Parent</p>
|
||||
<AppItem />
|
||||
</div>;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var _ref = /*#__PURE__*/<span />;
|
||||
var _ref = <span />;
|
||||
|
||||
var Foo = React.createClass({
|
||||
render: function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'; // Regression test for https://github.com/babel/babel/issues/5552
|
||||
|
||||
var _ref = /*#__PURE__*/<div />;
|
||||
var _ref = <div />;
|
||||
|
||||
class BugReport extends React.Component {
|
||||
constructor(...args) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import Loader from 'loader';
|
||||
|
||||
var _ref = /*#__PURE__*/<Loader className="full-height" />;
|
||||
var _ref = <Loader className="full-height" />;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<Loader className="p-y-5" />;
|
||||
var _ref2 = <Loader className="p-y-5" />;
|
||||
|
||||
const errorComesHere = () => _ref,
|
||||
thisWorksFine = () => _ref2;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var Foo = require("Foo");
|
||||
|
||||
var _ref = /*#__PURE__*/<Foo />;
|
||||
var _ref = <Foo />;
|
||||
|
||||
function render() {
|
||||
return _ref;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var _ref = /*#__PURE__*/<b></b>;
|
||||
var _ref = <b></b>;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<span></span>;
|
||||
var _ref2 = <span></span>;
|
||||
|
||||
function render() {
|
||||
var children = _ref;
|
||||
|
||||
@@ -4,11 +4,11 @@ const Parent = ({}) => _ref;
|
||||
|
||||
export default Parent;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<div className="child">
|
||||
var _ref2 = <div className="child">
|
||||
ChildTextContent
|
||||
</div>;
|
||||
|
||||
let Child = () => _ref2,
|
||||
_ref = /*#__PURE__*/<div className="parent">
|
||||
_ref = <div className="parent">
|
||||
<Child />
|
||||
</div>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function render() {
|
||||
const bar = "bar",
|
||||
_ref = /*#__PURE__*/<foo bar={bar} />,
|
||||
_ref = <foo bar={bar} />,
|
||||
renderFoo = () => _ref;
|
||||
|
||||
return renderFoo();
|
||||
@@ -10,7 +10,7 @@ function render() {
|
||||
const bar = "bar",
|
||||
renderFoo = () => _ref2,
|
||||
baz = "baz",
|
||||
_ref2 = /*#__PURE__*/<foo bar={bar} baz={baz} />;
|
||||
_ref2 = <foo bar={bar} baz={baz} />;
|
||||
|
||||
return renderFoo();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function render() {
|
||||
var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
||||
|
||||
var _ref = /*#__PURE__*/<Component title={title} />;
|
||||
var _ref = <Component title={title} />;
|
||||
|
||||
return () => _ref;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function render(Component) {
|
||||
var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '',
|
||||
_ref = /*#__PURE__*/<Component text={text} />;
|
||||
_ref = <Component text={text} />;
|
||||
|
||||
return function () {
|
||||
return _ref;
|
||||
|
||||
@@ -6,7 +6,7 @@ const Parent = ({}) => _ref;
|
||||
|
||||
export default Parent;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<div className="child">
|
||||
var _ref2 = <div className="child">
|
||||
ChildTextContent
|
||||
</div>;
|
||||
|
||||
@@ -14,6 +14,6 @@ let Child = () => _ref2;
|
||||
|
||||
Child = HOC(Child);
|
||||
|
||||
var _ref = /*#__PURE__*/<div className="parent">
|
||||
var _ref = <div className="parent">
|
||||
<Child />
|
||||
</div>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function render(text) {
|
||||
var _ref = /*#__PURE__*/<foo>{text}</foo>;
|
||||
var _ref = <foo>{text}</foo>;
|
||||
|
||||
return function () {
|
||||
return _ref;
|
||||
@@ -9,7 +9,7 @@ function render(text) {
|
||||
var Foo2 = require("Foo");
|
||||
|
||||
function createComponent(text) {
|
||||
var _ref2 = /*#__PURE__*/<Foo2>{text}</Foo2>;
|
||||
var _ref2 = <Foo2>{text}</Foo2>;
|
||||
|
||||
return function render() {
|
||||
return _ref2;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var _ref = /*#__PURE__*/<div foo={notDeclared}></div>;
|
||||
var _ref = <div foo={notDeclared}></div>;
|
||||
|
||||
var Foo = React.createClass({
|
||||
render: function render() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var _ref = /*#__PURE__*/<foo />;
|
||||
var _ref = <foo />;
|
||||
|
||||
function render() {
|
||||
return _ref;
|
||||
}
|
||||
|
||||
var _ref2 = /*#__PURE__*/<div className="foo"><input type="checkbox" checked={true} /></div>;
|
||||
var _ref2 = <div className="foo"><input type="checkbox" checked={true} /></div>;
|
||||
|
||||
function render() {
|
||||
return _ref2;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function render() {
|
||||
var text = getText();
|
||||
|
||||
var _ref = /*#__PURE__*/<foo>{text}</foo>;
|
||||
var _ref = <foo>{text}</foo>;
|
||||
|
||||
return function () {
|
||||
return _ref;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function render() {
|
||||
this.component = "div";
|
||||
|
||||
var _ref = /*#__PURE__*/<this.component />;
|
||||
var _ref = <this.component />;
|
||||
|
||||
return () => _ref;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var _ref = /*#__PURE__*/<span>Sub Component</span>;
|
||||
var _ref = <span>Sub Component</span>;
|
||||
|
||||
class Component extends React.Component {
|
||||
constructor(...args) {
|
||||
@@ -6,7 +6,7 @@ class Component extends React.Component {
|
||||
|
||||
this.subComponent = () => _ref;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<this.subComponent />;
|
||||
var _ref2 = <this.subComponent />;
|
||||
|
||||
this.render = () => _ref2;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var _ref = /*#__PURE__*/<span>Sub Component</span>;
|
||||
var _ref = <span>Sub Component</span>;
|
||||
|
||||
const els = {
|
||||
subComponent: () => _ref
|
||||
};
|
||||
|
||||
var _ref2 = /*#__PURE__*/<els.subComponent />;
|
||||
var _ref2 = <els.subComponent />;
|
||||
|
||||
class Component extends React.Component {
|
||||
constructor(...args) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function fn(Component, obj) {
|
||||
var data = obj.data,
|
||||
_ref = /*#__PURE__*/<Component prop={data} />;
|
||||
_ref = <Component prop={data} />;
|
||||
|
||||
return () => _ref;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ function render(_ref) {
|
||||
className = _ref.className,
|
||||
id = _ref.id;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<Component text={text} className={className} id={id} />;
|
||||
var _ref2 = <Component text={text} className={className} id={id} />;
|
||||
|
||||
return () => _ref2;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ function render(_ref) {
|
||||
id = _ref.id,
|
||||
props = babelHelpers.objectWithoutProperties(_ref, ["text", "className", "id"]);
|
||||
|
||||
var _ref2 = /*#__PURE__*/<Component text={text} className={className} id={id} />;
|
||||
var _ref2 = <Component text={text} className={className} id={id} />;
|
||||
|
||||
// intentionally ignoring props
|
||||
return () => _ref2;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function render(_ref) {
|
||||
let text = _ref.text;
|
||||
|
||||
var _ref2 = /*#__PURE__*/<Component text={text} />;
|
||||
var _ref2 = <Component text={text} />;
|
||||
|
||||
return () => _ref2;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function render(text) {
|
||||
var _ref = /*#__PURE__*/<div>{text}</div>;
|
||||
var _ref = <div>{text}</div>;
|
||||
|
||||
return function () {
|
||||
return _ref;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function render(offset) {
|
||||
var _ref = /*#__PURE__*/<div tabIndex={offset + 1} />;
|
||||
var _ref = <div tabIndex={offset + 1} />;
|
||||
|
||||
return function () {
|
||||
return _ref;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const OFFSET = 3;
|
||||
|
||||
var _ref = /*#__PURE__*/<div tabIndex={OFFSET + 1} />;
|
||||
var _ref = <div tabIndex={OFFSET + 1} />;
|
||||
|
||||
var Foo = React.createClass({
|
||||
render: function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Intl from 'react-intl';
|
||||
|
||||
var _ref = /*#__PURE__*/<Intl.FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
|
||||
var _ref = <Intl.FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
|
||||
someValue: "A value."
|
||||
}} />;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var _ref = /*#__PURE__*/<FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
|
||||
var _ref = <FormattedMessage id="someMessage.foo" defaultMessage={"Some text, " + "and some more too. {someValue}"} description="A test message for babel." values={{
|
||||
someValue: "A value."
|
||||
}} />;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var _ref = /*#__PURE__*/<div data-text={"Some text, " + "and some more too."} />;
|
||||
var _ref = <div data-text={"Some text, " + "and some more too."} />;
|
||||
|
||||
var Foo = React.createClass({
|
||||
render: function () {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function render(text) {
|
||||
text += "yes";
|
||||
|
||||
var _ref = /*#__PURE__*/<div>{text}</div>;
|
||||
var _ref = <div>{text}</div>;
|
||||
|
||||
return function () {
|
||||
return _ref;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var _ref = /*#__PURE__*/<div className="class-name">
|
||||
var _ref = <div className="class-name">
|
||||
Text
|
||||
</div>;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function fn(Component) {
|
||||
var data = "prop",
|
||||
_ref = /*#__PURE__*/<Component prop={data} />;
|
||||
_ref = <Component prop={data} />;
|
||||
|
||||
return () => _ref;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user