I'm extremely stupid and didn't commit as I go. To anyone reading this I'm extremely sorry. A lot of these changes are very broad and I plan on releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm afraid I couldn't wait. If you're ever in London I'll buy you a beer (or assorted beverage!) to make up for it, also I'll kiss your feet and give you a back massage, maybe.
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
export default function ({ types: t }) {
|
|
let JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
|
|
|
|
let visitor = require("babel-helper-builder-react-jsx")({
|
|
pre(state) {
|
|
let tagName = state.tagName;
|
|
let args = state.args;
|
|
if (t.react.isCompatTag(tagName)) {
|
|
args.push(t.stringLiteral(tagName));
|
|
} else {
|
|
args.push(state.tagExpr);
|
|
}
|
|
},
|
|
|
|
post(state, pass) {
|
|
state.callee = pass.get("jsxIdentifier");
|
|
}
|
|
});
|
|
|
|
visitor.Program = function (path, state) {
|
|
let { file } = state;
|
|
let id = state.opts.pragma || "React.createElement";
|
|
|
|
for (let comment of (file.ast.comments: Array<Object>)) {
|
|
let matches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
|
if (matches) {
|
|
id = matches[1];
|
|
if (id === "React.DOM") {
|
|
throw file.buildCodeFrameError(comment, "The @jsx React.DOM pragma has been deprecated as of React 0.12");
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
state.set("jsxIdentifier", id.split(".").map(t.identifier).reduce(function (object, property) {
|
|
return t.memberExpression(object, property);
|
|
}));
|
|
};
|
|
|
|
return {
|
|
inherits: require("babel-plugin-syntax-jsx"),
|
|
visitor
|
|
};
|
|
}
|