Allow helpers to be put in separate files#8487
Closed
nicolo-ribaudo wants to merge 1 commit intobabel:masterfrom
Closed
Allow helpers to be put in separate files#8487nicolo-ribaudo wants to merge 1 commit intobabel:masterfrom
nicolo-ribaudo wants to merge 1 commit intobabel:masterfrom
Conversation
nicolo-ribaudo
commented
Aug 17, 2018
| { | ||
| "files": ["packages/babel-helpers/src/helpers/*.js"], | ||
| "rules": { | ||
| "no-var": "off" |
Member
Author
There was a problem hiding this comment.
Here probably we will need to add some other rules.
nicolo-ribaudo
commented
Aug 17, 2018
| var REACT_ELEMENT_TYPE; | ||
|
|
||
| function _jsx(type, props, key, children) { if (!REACT_ELEMENT_TYPE) { REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; } var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = { children: void 0 }; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = new Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; } | ||
| function _jsx(type, props, key, children) { if (!REACT_ELEMENT_TYPE) { REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; } var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = { children: void 0 }; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = new Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : "" + key, ref: null, props: props, _owner: null }; } |
Member
Author
There was a problem hiding this comment.
The only change here is that prettier transformed '' to "".
This gives a few advantages: 1) They can be linted and prettified 2) It's easier to review them on GitHub, snice they are sytnax-highlighted.
8198d8b to
b34a05a
Compare
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8838/ |
4 tasks
Member
Author
|
I have some ideas for this, but I'll create a RFC because I don't think that this PR is the best solution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This gives a few advantages:
I had to set up a separate gulp task because, when using
make watch, changes to any extracted helper need to trigger a recompilation ofbabel-helpers/src/helpers.js.I only extracted one helper, as an example and to check that everything works. The compiled output looks like this:
cc @Kovensky, since you had the original idea (accordingly to what I wrote in bfb3592) 😄