-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
[Outdated; needs revision] Add support for normal errors to error code infra #15072
Closed
Conversation
This file contains 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
acdlite
changed the title
Minify normal errors too
Add support for normal errors to error code infra
Mar 9, 2019
React: size: 🔺+0.3%, gzip: 🔺+0.5% ReactDOM: size: -0.1%, gzip: -0.3% Details of bundled changes.Comparing: aece811...8fad8da react
react-dom
react-art
react-native-renderer
react-test-renderer
react-noop-renderer
react-reconciler
react-is
react-debug-tools
react-cache
create-subscription
scheduler
jest-react
eslint-plugin-react-hooks
Generated by 🚫 dangerJS |
acdlite
force-pushed
the
minify-normal-errors-too
branch
5 times, most recently
from
March 9, 2019 03:46
d942f0e
to
ced6caa
Compare
acdlite
force-pushed
the
minify-normal-errors-too
branch
from
March 18, 2019 20:59
acc207c
to
7835fb0
Compare
This updates our script to extract error messages from invariant calls and strip them in production to also support Error constructors. As with invariant, it converts them to use ReactError in development and ReactErrorProd in production. It supports both strings and template literals with interpolated values. If it encounters an error constructor that contains unsupported syntax, it will exit gracefully. In a next step, I will add a lint rule that enforces error messages are minifiable.
I took this approach instead of failing at build time because 1. Better dev experience. The lint rule will warn you inside your editor as you type, whereas a build time rule won't fail until you run the tests or the build script. 2. Easier to opt out specific errors from the rule, like the ReactError module, which intentionally uses a dynamic error message.
Some Babel plugins are only meant to run on source files, some only on tests, and so on. We were using a single preprocessor and some metaprogramming to determine which ones to run per file; I changed it to use separate preprocessors per category instead. The practical reason I made this change was so the error code script does not run on test files.
acdlite
force-pushed
the
minify-normal-errors-too
branch
from
April 9, 2019 21:13
7835fb0
to
8fad8da
Compare
acdlite
changed the title
Add support for normal errors to error code infra
[Outdated; needs revision] Add support for normal errors to error code infra
Jun 14, 2019
Closing because the code is outdated but we should still do this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Based on #15071
Refer to the base PR for more context
This compiles normal error constructors (
new Error(...)
andError(...)
) toReactError
in andReactErrorProd
, adding support to our error code replacement infra.It also adds a lint rule to enforce that error messages are written in an extraction-friendly format.
Error messages must be a concatenation of strings and string literals. This is partly an artificial restriction, because I could generate a template string even from a dynamic expression, but requiring the use of a template literal for dynamic values helps prevent mistakes like
const msg = 'string'; throw new Error(msg)
.You can add
extract-error/skip
to messages that don't need to be replaced with an error code.