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:
Nicolò Ribaudo
2020-03-19 15:43:54 +01:00
committed by GitHub
parent fa7ec81771
commit f3912ac08f
246 changed files with 613 additions and 314 deletions

View File

@@ -4,6 +4,8 @@ import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
export default declare((api, options) => {
const PURE_ANNOTATION = options.pure;
const visitor = helper(api, {
pre(state) {
const tagName = state.tagName;
@@ -20,6 +22,9 @@ export default declare((api, options) => {
state.createElementCallee = pass.get(
"@babel/plugin-react-jsx/createElementIdentifier",
)();
state.pure =
PURE_ANNOTATION ?? !pass.get("@babel/plugin-react-jsx/pragmaSet");
} else {
state.jsxCallee = pass.get("@babel/plugin-react-jsx/jsxIdentifier")();
state.jsxStaticCallee = pass.get(
@@ -28,6 +33,10 @@ export default declare((api, options) => {
state.createElementCallee = pass.get(
"@babel/plugin-react-jsx/createElementIdentifier",
)();
state.pure =
PURE_ANNOTATION ??
!pass.get("@babel/plugin-react-jsx/importSourceSet");
}
},

View File

@@ -3,12 +3,18 @@ import jsx from "@babel/plugin-syntax-jsx";
import helper from "@babel/helper-builder-react-jsx";
import { types as t } from "@babel/core";
const DEFAULT = {
pragma: "React.createElement",
pragmaFrag: "React.Fragment",
};
export default declare((api, options) => {
const THROW_IF_NAMESPACE =
options.throwIfNamespace === undefined ? true : !!options.throwIfNamespace;
const PRAGMA_DEFAULT = options.pragma || "React.createElement";
const PRAGMA_FRAG_DEFAULT = options.pragmaFrag || "React.Fragment";
const PRAGMA_DEFAULT = options.pragma || DEFAULT.pragma;
const PRAGMA_FRAG_DEFAULT = options.pragmaFrag || DEFAULT.pragmaFrag;
const PURE_ANNOTATION = options.pure;
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
const JSX_FRAG_ANNOTATION_REGEX = /\*?\s*@jsxFrag\s+([^\s]+)/;
@@ -35,6 +41,7 @@ export default declare((api, options) => {
post(state, pass) {
state.callee = pass.get("jsxIdentifier")();
state.pure = PURE_ANNOTATION ?? !pass.get("pragmaSet");
},
throwIfNamespace: THROW_IF_NAMESPACE,
@@ -46,20 +53,16 @@ export default declare((api, options) => {
let pragma = PRAGMA_DEFAULT;
let pragmaFrag = PRAGMA_FRAG_DEFAULT;
let pragmaSet = !!options.pragma;
let pragmaFragSet = !!options.pragmaFrag;
if (file.ast.comments) {
for (const comment of (file.ast.comments: Array<Object>)) {
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
if (jsxMatches) {
pragma = jsxMatches[1];
pragmaSet = true;
}
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
if (jsxFragMatches) {
pragmaFrag = jsxFragMatches[1];
pragmaFragSet = true;
}
}
}
@@ -67,8 +70,8 @@ export default declare((api, options) => {
state.set("jsxIdentifier", createIdentifierParser(pragma));
state.set("jsxFragIdentifier", createIdentifierParser(pragmaFrag));
state.set("usedFragment", false);
state.set("pragmaSet", pragmaSet);
state.set("pragmaFragSet", pragmaFragSet);
state.set("pragmaSet", pragma !== DEFAULT.pragma);
state.set("pragmaFragSet", pragmaFrag !== DEFAULT.pragmaFrag);
},
exit(path, state) {
if (

View File

@@ -3,11 +3,11 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var x = _jsx(_Fragment, {
children: _jsxs("div", {
children: [_jsx("div", {}, "1"), _jsx("div", {
var x = /*#__PURE__*/_jsx(_Fragment, {
children: /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("div", {}, "1"), /*#__PURE__*/_jsx("div", {
meow: "wolf"
}, "2"), _jsx("div", {}, "3"), _createElement("div", { ...props,
}, "2"), /*#__PURE__*/_jsx("div", {}, "3"), /*#__PURE__*/_createElement("div", { ...props,
key: "4"
})]
})

View File

@@ -2,11 +2,11 @@ var _react = require("react");
var _reactJsxRuntime = require("react/jsx-runtime");
var x = _reactJsxRuntime.jsx(_reactJsxRuntime.Fragment, {
children: _reactJsxRuntime.jsxs("div", {
children: [_reactJsxRuntime.jsx("div", {}, "1"), _reactJsxRuntime.jsx("div", {
var x = /*#__PURE__*/_reactJsxRuntime.jsx(_reactJsxRuntime.Fragment, {
children: /*#__PURE__*/_reactJsxRuntime.jsxs("div", {
children: [/*#__PURE__*/_reactJsxRuntime.jsx("div", {}, "1"), /*#__PURE__*/_reactJsxRuntime.jsx("div", {
meow: "wolf"
}, "2"), _reactJsxRuntime.jsx("div", {}, "3"), _react.createElement("div", { ...props,
}, "2"), /*#__PURE__*/_reactJsxRuntime.jsx("div", {}, "3"), /*#__PURE__*/_react.createElement("div", { ...props,
key: "4"
})]
})

View File

@@ -15,11 +15,11 @@ const Bar = () => {
var jsx = 1;
var _jsx = 2;
return _jsx2("div", {});
return /*#__PURE__*/_jsx2("div", {});
}
;
return _jsx2("span", {});
return /*#__PURE__*/_jsx2("span", {});
};
};
};

View File

@@ -15,11 +15,11 @@ const Bar = () => {
var jsx = 1;
var _jsx = 2;
return _reactJsxRuntime.jsx("div", {});
return /*#__PURE__*/_reactJsxRuntime.jsx("div", {});
}
;
return _reactJsxRuntime.jsx("span", {});
return /*#__PURE__*/_reactJsxRuntime.jsx("span", {});
};
};
};

View File

@@ -6,10 +6,10 @@ var y = react.createElement("div", {
foo: 1
});
var x = _jsxs("div", {
children: [_jsx("div", {}, "1"), _jsx("div", {
var x = /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("div", {}, "1"), /*#__PURE__*/_jsx("div", {
meow: "wolf"
}, "2"), _jsx("div", {}, "3"), _createElement("div", { ...props,
}, "2"), /*#__PURE__*/_jsx("div", {}, "3"), /*#__PURE__*/_createElement("div", { ...props,
key: "4"
})]
});

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx(Component, { ...props,
sound: "moo"
});

View File

@@ -4,7 +4,7 @@ var foo = function () {
var _this = this;
return function () {
return _jsx(_this, {});
return /*#__PURE__*/_jsx(_this, {});
};
};
@@ -12,6 +12,6 @@ var bar = function () {
var _this2 = this;
return function () {
return _jsx(_this2.foo, {});
return /*#__PURE__*/_jsx(_this2.foo, {});
};
};

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var div = _jsx(Component, { ...props,
var div = /*#__PURE__*/_jsx(Component, { ...props,
foo: "bar"
});

View File

@@ -1,8 +1,8 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var x = _jsxs("div", {
children: ["foo", "bar", "baz", _jsx("div", {
var x = /*#__PURE__*/_jsxs("div", {
children: ["foo", "bar", "baz", /*#__PURE__*/_jsx("div", {
children: "buz bang"
}), "qux", null, "quack"]
});

View File

@@ -1,5 +1,6 @@
import { jsxs as _jsxs } from "react/jsx-runtime";
/*#__PURE__*/
_jsxs(Text, {
children: ["To get started, edit index.ios.js!!!", "\n", "Press Cmd+R to reload"]
});

View File

@@ -1,4 +1,4 @@
import { jsx as _jsx } from "react/jsx-runtime";
import * as React from "react";
var x = _jsx(React.Fragment, {}, "foo");
var x = /*#__PURE__*/_jsx(React.Fragment, {}, "foo");

View File

@@ -1,4 +1,4 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var x = _jsx(_Fragment, {});
var x = /*#__PURE__*/_jsx(_Fragment, {});

View File

@@ -1,6 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var x = _jsx(_Fragment, {
children: _jsx("div", {})
var x = /*#__PURE__*/_jsx(_Fragment, {
children: /*#__PURE__*/_jsx("div", {})
});

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", {
children: [_jsx("span", {}, '0'), _jsx("span", {}, '1')]
});
var x = /*#__PURE__*/_jsx("div", {
children: [/*#__PURE__*/_jsx("span", {}, '0'), /*#__PURE__*/_jsx("span", {}, '1')]
});

View File

@@ -1,6 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var x = _jsxs("div", {
children: [_jsx("span", {}), [_jsx("span", {}, '0'), _jsx("span", {}, '1')]]
});
var x = /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("span", {}), [/*#__PURE__*/_jsx("span", {}, '0'), /*#__PURE__*/_jsx("span", {}, '1')]]
});

View File

@@ -1,13 +1,14 @@
import { jsxs as _jsxs } from "react/jsx-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx(Foo, {});
var profile = _jsxs("div", {
children: [_jsx("img", {
var profile = /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("img", {
src: "avatar.png",
className: "profile"
}), _jsx("h3", {
}), /*#__PURE__*/_jsx("h3", {
children: [user.firstName, user.lastName].join(" ")
})]
});
});

View File

@@ -1 +1 @@
import { jsx as _jsx } from "react/jsx-runtime";var div = _jsx("div", { children: "test" });
import { jsx as _jsx } from "react/jsx-runtime";var div = /*#__PURE__*/_jsx("div", { children: "test" });

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var div = _jsx("div", {
var div = /*#__PURE__*/_jsx("div", {
children: "test"
});
});

View File

@@ -3,6 +3,6 @@ const props = {
foo: true
};
var x = _createElement("div", { ...props,
var x = /*#__PURE__*/_createElement("div", { ...props,
key: undefined
});

View File

@@ -1,4 +1,4 @@
var _ref = /*#__PURE__*/<div className="navbar-header">
var _ref = <div className="navbar-header">
<a className="navbar-brand" href="/">
<img src="/img/logo/logo-96x36.png" />
</a>

View File

@@ -1,6 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
var es3 = _jsx(F, {
var es3 = /*#__PURE__*/_jsx(F, {
aaa: true,
"new": true,
"const": true,

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx(Component, {
constructor: "foo"
});

View File

@@ -1,3 +1,4 @@
import { jsx as _jsx } from "react/jsx-runtime";
_jsx(Namespace.DeepNamespace.Component, {});
/*#__PURE__*/
_jsx(Namespace.DeepNamespace.Component, {});

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("div", {
attr: _jsx("div", {})
attr: /*#__PURE__*/_jsx("div", {})
});

View File

@@ -1,3 +1,4 @@
import { jsx as _jsx } from "react/jsx-runtime";
_jsx(Namespace.Component, {});
/*#__PURE__*/
_jsx(Namespace.Component, {});

View File

@@ -2,18 +2,19 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("div", {
children: _jsxs(_Fragment, {
children: [_jsxs(_Fragment, {
children: [_jsx("span", {
children: /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx("span", {
children: "Hello"
}), _jsx("span", {
}), /*#__PURE__*/_jsx("span", {
children: "world"
})]
}), _jsxs(_Fragment, {
children: [_jsx("span", {
}), /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx("span", {
children: "Goodbye"
}), _jsx("span", {
}), /*#__PURE__*/_jsx("span", {
children: "world"
})]
})]

View File

@@ -1,17 +1,17 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", {
children: _jsx(Component, {})
var x = /*#__PURE__*/_jsx("div", {
children: /*#__PURE__*/_jsx(Component, {})
});
var x = _jsx("div", {
var x = /*#__PURE__*/_jsx("div", {
children: props.children
});
var x = _jsx(Composite, {
var x = /*#__PURE__*/_jsx(Composite, {
children: props.children
});
var x = _jsx(Composite, {
children: _jsx(Composite2, {})
var x = /*#__PURE__*/_jsx(Composite, {
children: /*#__PURE__*/_jsx(Composite2, {})
});

View File

@@ -1,3 +1,3 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", {});
var x = /*#__PURE__*/_jsx("div", {});

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", {
var x = /*#__PURE__*/_jsx("div", {
children: "text"
});

View File

@@ -1,13 +1,16 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("div", {
id: "w\xF4w"
});
/*#__PURE__*/
_jsx("div", {
id: "\\w"
});
/*#__PURE__*/
_jsx("div", {
id: "w < w"
});

View File

@@ -1,38 +1,47 @@
import { jsxs as _jsxs } from "react/jsx-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("div", {
children: "wow"
});
/*#__PURE__*/
_jsx("div", {
children: "w\xF4w"
});
/*#__PURE__*/
_jsx("div", {
children: "w & w"
});
/*#__PURE__*/
_jsx("div", {
children: "w & w"
});
/*#__PURE__*/
_jsx("div", {
children: "w \xA0 w"
});
/*#__PURE__*/
_jsx("div", {
children: "this should not parse as unicode: \\u00a0"
});
/*#__PURE__*/
_jsx("div", {
children: "this should parse as nbsp: \xA0 "
});
/*#__PURE__*/
_jsxs("div", {
children: ["this should parse as unicode: ", '\u00a0 ']
});
/*#__PURE__*/
_jsx("div", {
children: "w < w"
});

View File

@@ -3,13 +3,13 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
var HelloMessage = React.createClass({
displayName: "HelloMessage",
render: function () {
return _jsxs("div", {
return /*#__PURE__*/_jsxs("div", {
children: ["Hello ", this.props.name]
});
}
});
React.render(_jsx(HelloMessage, {
name: _jsx("span", {
React.render( /*#__PURE__*/_jsx(HelloMessage, {
name: /*#__PURE__*/_jsx("span", {
children: "Sebastian"
})
}), mountNode);

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("hasOwnProperty", {
children: "testing"
});

View File

@@ -1,10 +1,10 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var x = _jsxs("div", {
children: [_jsx("div", {
children: _jsx("br", {})
}), _jsxs(Component, {
children: [foo, _jsx("br", {}), bar]
}), _jsx("br", {})]
var x = /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("div", {
children: /*#__PURE__*/_jsx("br", {})
}), /*#__PURE__*/_jsxs(Component, {
children: [foo, /*#__PURE__*/_jsx("br", {}), bar]
}), /*#__PURE__*/_jsx("br", {})]
});

View File

@@ -1,6 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", {
var x = /*#__PURE__*/_jsx("div", {
attr1: "foo" + "bar",
attr2: "foo" + "bar" + "baz" + "bug",
attr3: "foo" + "bar" + "baz" + "bug",

View File

@@ -1,6 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
var e = _jsx(F, {
var e = /*#__PURE__*/_jsx(F, {
aaa: true,
new: true,
const: true,

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("button", {
"data-value": "a value\n with\nnewlines\n and spaces",
children: "Button"

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("div", {
children: "\xA0 "
});

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("div", {
children: "\xA0"
});

View File

@@ -1,10 +1,10 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", {
var x = /*#__PURE__*/_jsx("div", {
/* a multi-line
comment */
attr1: "foo",
children: _jsx("span", {
children: /*#__PURE__*/_jsx("span", {
// a double-slash comment
attr2: "bar"
})

View File

@@ -1,8 +1,8 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var x = _jsxs("div", {
children: [_jsx("div", {}, "1"), _jsx("div", {
var x = /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("div", {}, "1"), /*#__PURE__*/_jsx("div", {
meow: "wolf"
}, "2"), _jsx("div", {}, "3")]
});
}, "2"), /*#__PURE__*/_jsx("div", {}, "3")]
});

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var foo = null;
var x = _jsx("div", { ...foo
var x = /*#__PURE__*/_jsx("div", { ...foo
});

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("button", {
"data-value": "a value",
children: "Button"

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx("f:image", {
"n:attr": true
});

View File

@@ -1,3 +1,4 @@
import { jsx as _jsx } from "react/jsx-runtime";
_jsx("font-face", {});
/*#__PURE__*/
_jsx("font-face", {});

View File

@@ -1,6 +1,6 @@
import { createElement as _createElement } from "react";
var x = _createElement("div", { ...props,
var x = /*#__PURE__*/_createElement("div", { ...props,
key: "1",
foo: "bar"
});

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var x = _jsx("div", { ...props,
var x = /*#__PURE__*/_jsx("div", { ...props,
foo: "bar"
}, "1");

View File

@@ -1,5 +1,5 @@
import { jsx as _jsx } from "react/jsx-runtime";
var div = _jsx(this.foo, {
var div = /*#__PURE__*/_jsx(this.foo, {
children: "test"
});

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx(Component, {
y: 2,
z: true,

View File

@@ -1,5 +1,6 @@
import { jsx as _jsx } from "react/jsx-runtime";
/*#__PURE__*/
_jsx(Component, {
y: 2,
...x,

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Component, { ...props,
sound: "moo"
});

View File

@@ -3,7 +3,7 @@ var foo = function () {
var _this = this;
return function () {
return React.createElement(_this, null);
return /*#__PURE__*/React.createElement(_this, null);
};
};
@@ -11,6 +11,6 @@ var bar = function () {
var _this2 = this;
return function () {
return React.createElement(_this2.foo, null);
return /*#__PURE__*/React.createElement(_this2.foo, null);
};
};

View File

@@ -1,4 +1,4 @@
/** @jsxRuntime classic */
var div = React.createElement(Component, { ...props,
var div = /*#__PURE__*/React.createElement(Component, { ...props,
foo: "bar"
});

View File

@@ -1,2 +1,2 @@
/** @jsxRuntime classic */
var x = React.createElement("div", null, "foo", "bar", "baz", React.createElement("div", null, "buz bang"), "qux", null, "quack");
var x = /*#__PURE__*/React.createElement("div", null, "foo", "bar", "baz", /*#__PURE__*/React.createElement("div", null, "buz bang"), "qux", null, "quack");

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Text, null, "To get started, edit index.ios.js!!!", "\n", "Press Cmd+R to reload");

View File

@@ -1,3 +1,3 @@
/** @jsxRuntime classic */
var div = React.createElement("div", null, "test");
var div = /*#__PURE__*/React.createElement("div", null, "test");

View File

@@ -1,2 +1,2 @@
/** @jsxRuntime classic */
var div = React.createElement("div", null, "test");
var div = /*#__PURE__*/React.createElement("div", null, "test");

View File

@@ -1,5 +1,5 @@
/** @jsxRuntime classic */
var es3 = React.createElement(F, {
var es3 = /*#__PURE__*/React.createElement(F, {
aaa: true,
"new": true,
"const": true,

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Component, {
constructor: "foo"
});

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Namespace.DeepNamespace.Component, null);

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("div", {
attr: React.createElement("div", null)
attr: /*#__PURE__*/React.createElement("div", null)
});

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Namespace.Component, null);

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
React.createElement("div", null, React.createElement(React.Fragment, null, React.createElement(React.Fragment, null, React.createElement("span", null, "Hello"), React.createElement("span", null, "world")), React.createElement(React.Fragment, null, React.createElement("span", null, "Goodbye"), React.createElement("span", null, "world"))));
/*#__PURE__*/
React.createElement("div", null, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", null, "Hello"), /*#__PURE__*/React.createElement("span", null, "world")), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", null, "Goodbye"), /*#__PURE__*/React.createElement("span", null, "world"))));

View File

@@ -1,5 +1,5 @@
/** @jsxRuntime classic */
var x = React.createElement("div", null, React.createElement(Component, null));
var x = React.createElement("div", null, props.children);
var x = React.createElement(Composite, null, props.children);
var x = React.createElement(Composite, null, React.createElement(Composite2, null));
var x = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Component, null));
var x = /*#__PURE__*/React.createElement("div", null, props.children);
var x = /*#__PURE__*/React.createElement(Composite, null, props.children);
var x = /*#__PURE__*/React.createElement(Composite, null, /*#__PURE__*/React.createElement(Composite2, null));

View File

@@ -1,2 +1,2 @@
/** @jsxRuntime classic */
var x = React.createElement("div", null);
var x = /*#__PURE__*/React.createElement("div", null);

View File

@@ -1,2 +1,2 @@
/** @jsxRuntime classic */
var x = React.createElement("div", null, "text");
var x = /*#__PURE__*/React.createElement("div", null, "text");

View File

@@ -1,10 +1,16 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("div", {
id: "w\xF4w"
});
/*#__PURE__*/
React.createElement("div", {
id: "\\w"
});
/*#__PURE__*/
React.createElement("div", {
id: "w < w"
});

View File

@@ -1,10 +1,28 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("div", null, "wow");
/*#__PURE__*/
React.createElement("div", null, "w\xF4w");
/*#__PURE__*/
React.createElement("div", null, "w & w");
/*#__PURE__*/
React.createElement("div", null, "w & w");
/*#__PURE__*/
React.createElement("div", null, "w \xA0 w");
/*#__PURE__*/
React.createElement("div", null, "this should not parse as unicode: \\u00a0");
/*#__PURE__*/
React.createElement("div", null, "this should parse as nbsp: \xA0 ");
/*#__PURE__*/
React.createElement("div", null, "this should parse as unicode: ", '\u00a0 ');
/*#__PURE__*/
React.createElement("div", null, "w < w");

View File

@@ -2,9 +2,9 @@
var HelloMessage = React.createClass({
displayName: "HelloMessage",
render: function () {
return React.createElement("div", null, "Hello ", this.props.name);
return /*#__PURE__*/React.createElement("div", null, "Hello ", this.props.name);
}
});
React.render(React.createElement(HelloMessage, {
name: React.createElement("span", null, "Sebastian")
React.render( /*#__PURE__*/React.createElement(HelloMessage, {
name: /*#__PURE__*/React.createElement("span", null, "Sebastian")
}), mountNode);

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("hasOwnProperty", null, "testing");

View File

@@ -1,2 +1,2 @@
/** @jsxRuntime classic */
var x = React.createElement("div", null, React.createElement("div", null, React.createElement("br", null)), React.createElement(Component, null, foo, React.createElement("br", null), bar), React.createElement("br", null));
var x = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("br", null)), /*#__PURE__*/React.createElement(Component, null, foo, /*#__PURE__*/React.createElement("br", null), bar), /*#__PURE__*/React.createElement("br", null));

View File

@@ -1,5 +1,5 @@
/** @jsxRuntime classic */
var x = React.createElement("div", {
var x = /*#__PURE__*/React.createElement("div", {
attr1: "foo" + "bar",
attr2: "foo" + "bar" + "baz" + "bug",
attr3: "foo" + "bar" + "baz" + "bug",

View File

@@ -1,5 +1,5 @@
/** @jsxRuntime classic */
var e = React.createElement(F, {
var e = /*#__PURE__*/React.createElement(F, {
aaa: true,
new: true,
const: true,

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("button", {
"data-value": "a value\n with\nnewlines\n and spaces"
}, "Button");

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("div", null, "\xA0 ");

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("div", null, "\xA0");

View File

@@ -1,9 +1,9 @@
/** @jsxRuntime classic */
var x = React.createElement("div", {
var x = /*#__PURE__*/React.createElement("div", {
/* a multi-line
comment */
attr1: "foo"
}, React.createElement("span", {
}, /*#__PURE__*/React.createElement("span", {
// a double-slash comment
attr2: "bar"
}));

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("button", {
"data-value": "a value"
}, "Button");

View File

@@ -1,2 +1,4 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement("font-face", null);

View File

@@ -1,2 +1,2 @@
/** @jsxRuntime classic */
var div = React.createElement(this.foo, null, "test");
var div = /*#__PURE__*/React.createElement(this.foo, null, "test");

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Component, { ...x,
y: 2,
z: true

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Component, {
y: 2,
z: true,

View File

@@ -1,4 +1,6 @@
/** @jsxRuntime classic */
/*#__PURE__*/
React.createElement(Component, {
y: 2,
...x,

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["transform-react-jsx", { "pure": false }]
]
}

View File

@@ -0,0 +1 @@
React.createElement("div", null);

View File

@@ -0,0 +1,3 @@
/* @jsx h */
<div />;

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["transform-react-jsx", { "pure": false }]
]
}

View File

@@ -0,0 +1,2 @@
/* @jsx h */
h("div", null);

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["transform-react-jsx", { "pragma": "h", "pure": false }]
]
}

View File

@@ -0,0 +1 @@
h("div", null);

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["transform-react-jsx", { "pure": true }]
]
}

View File

@@ -0,0 +1,2 @@
/*#__PURE__*/
React.createElement("div", null);

View File

@@ -0,0 +1,3 @@
/* @jsx h */
<div />;

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["transform-react-jsx", { "pure": true }]
]
}

View File

@@ -0,0 +1,4 @@
/* @jsx h */
/*#__PURE__*/
h("div", null);

Some files were not shown because too many files have changed in this diff Show More