Skip to content

#114 - stop requiring docblock for JSX transformer #418

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions vendor/browser-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ if (typeof window === "undefined" || window === null) {
headEl = document.getElementsByTagName('head')[0];

var run = exports.run = function(code) {
var jsx = docblock.parseAsObject(docblock.extract(code)).jsx;

var functionBody = jsx ? transform(code).code : code;
var functionBody = transform(code).code;
var scriptEl = document.createElement('script');

scriptEl.innerHTML = functionBody;
Expand Down
4 changes: 2 additions & 2 deletions vendor/fbtransform/transforms/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var JSX_ATTRIBUTE_TRANSFORMS = {
};

function visitReactTag(traverse, object, path, state) {
var jsxObjIdent = getDocblock(state).jsx;
var jsxObjIdent = getDocblock(state).jsx || "React.DOM";

catchup(object.openingElement.range[0], state);

Expand Down Expand Up @@ -180,7 +180,7 @@ function visitReactTag(traverse, object, path, state) {
visitReactTag.test = function(object, path, state) {
// only run react when react @jsx namespace is specified in docblock
var jsx = getDocblock(state).jsx;
return object.type === Syntax.XJSElement && jsx && jsx.length;
return object.type === Syntax.XJSElement && (jsx === undefined || (jsx && jsx.length && jsx === "React.DOM"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simplified to return object.type === Syntax.XJSElement && (jsx == null || jsx === 'React.DOM');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I believe that from this comment of @jeffmo #364 (comment) he actually meant return object.type === Syntax.XJSElement && (!jsx || jsx === 'React.DOM');

};

exports.visitReactTag = visitReactTag;
3 changes: 2 additions & 1 deletion vendor/fbtransform/transforms/reactDisplayName.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function visitReactDisplayName(traverse, object, path, state) {
* Will only run on @jsx files for now.
*/
visitReactDisplayName.test = function(object, path, state) {
return object.type === Syntax.VariableDeclarator && !!getDocblock(state).jsx;
var jsx = getDocblock(state).jsx;
return object.type === Syntax.VariableDeclarator && (jsx === undefined || (jsx && jsx.length && jsx === "React.DOM"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simplified to return object.type === Syntax.VariableDeclarator && (!jsx || jsx === 'React.DOM');

};

exports.visitReactDisplayName = visitReactDisplayName;