Rollup script can now extract error codes and build in a single pass#11291
Merged
bvaughn merged 2 commits intofacebook:masterfrom Oct 20, 2017
Merged
Rollup script can now extract error codes and build in a single pass#11291bvaughn merged 2 commits intofacebook:masterfrom
bvaughn merged 2 commits intofacebook:masterfrom
Conversation
2 tasks
gaearon
approved these changes
Oct 20, 2017
Collaborator
|
Maybe I'm missing something, but isn't this a bug? I just noticed: function testErrorNotInMap(thing: string) {
(!string ? (__DEV__ ? invariant(false, "Error not in map") : 'Error not in map') : void 0);
}which in non-DEV does not produce an invariant at all. Instead, it should probably just be: (!string ? invariant(false, "Error not in map") : void 0);since behavior differences are not expected. |
gaearon
reviewed
Oct 24, 2017
| var prodInvariant; | ||
| if (prodErrorId === undefined) { | ||
| // The error cannot be found in the map. | ||
| // (This case isn't expected to occur.) |
Collaborator
There was a problem hiding this comment.
It's expected to occur on master builds.
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 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.
Relates to this comment.
Now we no longer have to run:
yarn build --extract-errors yarn build # This second run isn't necessary anymoreThis PR contains 2 changes:
scripts/rollup/build.jsThe main fix was swapping the order of error-code-extraction and replacement.
I verified this by first emptying out the contents of
error-codes.json({}) and running:This built the bundle and extracted error codes in a single pass. I copied the resulting build artifacts to an external location and then ran
yarn build dom-fibera second time (after error codes had already been extracted). Then I useddiffto compare the bundles and verify that the following files were identical:scripts/error-codes/replace-invariant-error-codes.jsI also changed this file to always convert invariants to ternaries:
Regardless of whether the error message is in our error codes map. This shouldn't actually matter but...the 2nd format can be faster and so I thought I might as well do it while I was in there. (I'll revert this if anyone thinks it's overkill.)
I tested this change with AST explorer by transforming the following JavaScript:
With an error map that only contained 1 of the strings:
And the resulting transform looked good: