JSX pragma revert (#6195)

* Removed the deprecated jsx pragma detection code and the concerned tests that included jsx-pragma

* Removed extra tests

* Restored packages/babel-plugin-transform-react-jsx/test/fixtures/react/honor-custom-jsx-pragma-option/

* Added JSX_ANNOTATION_REGEX

* Reverted the tests for jsx-pragma-options and removed those which throw deprecated message
This commit is contained in:
Astha Sharma 2017-09-04 09:55:56 +05:30 committed by Henry Zhu
parent d6ba4d0a24
commit 3a2b7fe3cd
7 changed files with 158 additions and 1163 deletions

View File

@ -2,6 +2,8 @@ import jsx from "babel-plugin-syntax-jsx";
import helper from "babel-helper-builder-react-jsx";
export default function({ types: t }) {
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
const visitor = helper({
pre(state) {
const tagName = state.tagName;
@ -19,7 +21,16 @@ export default function({ types: t }) {
});
visitor.Program = function(path, state) {
const id = state.opts.pragma || "React.createElement";
const { file } = state;
let id = state.opts.pragma || "React.createElement";
for (const comment of (file.ast.comments: Array<Object>)) {
const matches = JSX_ANNOTATION_REGEX.exec(comment.value);
if (matches) {
id = matches[1];
break;
}
}
state.set("jsxIdentifier", () =>
id

View File

@ -0,0 +1,8 @@
/** @jsx dom */
<Foo></Foo>;
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>;

View File

@ -0,0 +1,6 @@
/** @jsx dom */
dom(Foo, null);
var profile = dom("div", null, dom("img", {
src: "avatar.png",
className: "profile"
}), dom("h3", null, [user.firstName, user.lastName].join(" ")));

View File

@ -0,0 +1,5 @@
{
"plugins": [
["transform-react-jsx", {"pragma": "foo.bar"}]
]
}

View File

@ -0,0 +1,8 @@
/** @jsx dom */
<Foo></Foo>;
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>;

View File

@ -0,0 +1,6 @@
/** @jsx dom */
dom(Foo, null);
var profile = dom("div", null, dom("img", {
src: "avatar.png",
className: "profile"
}), dom("h3", null, [user.firstName, user.lastName].join(" ")));

1275
yarn.lock

File diff suppressed because it is too large Load Diff