-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Add reactProdInvariant and corresponding babel rewrite pass #6948
Conversation
var buildRequire = babel.template(`var IMPORT_NAME = require(SOURCE);`); | ||
|
||
var REQUIRE_PROD_INVARIANT = buildRequire({ | ||
IMPORT_NAME: t.identifier(prodInvariantName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider doing this differently. Right now we don't have a guarantee that this identifier doesn't already exist (practically it probably won't matter but just in case…). We can use babel helpers to generate a unique identifier to use though and it'll be tracked on a per-file basis. This is how I did it for the object-assign transform: https://github.com/facebook/fbjs/blob/7c77c3c2ebcf0f1174512a66a08998dcff3d4cc5/babel-preset/plugins/object-assign.js#L15-L27
@keyanzhang updated the pull request. |
1 similar comment
@keyanzhang updated the pull request. |
@keyanzhang updated the pull request. |
@keyanzhang updated the pull request. |
@keyanzhang updated the pull request. |
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule reactProdInvariant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that all React*
modules currently capitalized React
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern is actually this:
- export an object or class? Upper case
- export a function? lower case
The only other one we have of the latter that starts with react
is reactComponentExpect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! thanks!
I think this looks good other than my inlines. Can you post build size numbers? |
Yep,
I wonder if there are things I can do to further reduce the size. It's much better than not rewriting invariant calls (leave them as-is) though. |
* WARNING: DO NOT manually require this module. | ||
* This is a replacement for `invariant(...)` used by the error code system | ||
* and will _only_ be required by the corresponding babel pass. | ||
* It always throw. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(grammar: "It always throws.")
@keyanzhang updated the pull request. |
@keyanzhang updated the pull request. |
(cherry picked from commit 1abce16)
Implements #6874. Thanks for reviewing!