mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Rollup script can now extract error codes and build in a single pass (#11291)
* Rollup build scripts can now extract error codes while building * I can't spell ternary
This commit is contained in:
@@ -91,13 +91,6 @@ module.exports = function(babel) {
|
||||
var condition = node.arguments[0];
|
||||
var errorMsgLiteral = evalToString(node.arguments[1]);
|
||||
|
||||
var prodErrorId = errorMap[errorMsgLiteral];
|
||||
if (prodErrorId === undefined) {
|
||||
// The error cannot be found in the map.
|
||||
node[SEEN_SYMBOL] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var devInvariant = t.callExpression(
|
||||
node.callee,
|
||||
[
|
||||
@@ -109,10 +102,22 @@ module.exports = function(babel) {
|
||||
devInvariant[SEEN_SYMBOL] = true;
|
||||
|
||||
var localInvariantId = getProdInvariantIdentifier(path, this);
|
||||
var prodInvariant = t.callExpression(
|
||||
localInvariantId,
|
||||
[t.stringLiteral(prodErrorId)].concat(node.arguments.slice(2))
|
||||
);
|
||||
|
||||
var prodErrorId = errorMap[errorMsgLiteral];
|
||||
var prodInvariant;
|
||||
if (prodErrorId === undefined) {
|
||||
// The error cannot be found in the map.
|
||||
// (This case isn't expected to occur.)
|
||||
// Even if it does, it's best to transform the invariant to a ternary,
|
||||
// So we don't risk executing any slow code unnecessarily
|
||||
// (eg generating an invariant message we don't actually need).
|
||||
prodInvariant = path.node.arguments[1];
|
||||
} else {
|
||||
prodInvariant = t.callExpression(
|
||||
localInvariantId,
|
||||
[t.stringLiteral(prodErrorId)].concat(node.arguments.slice(2))
|
||||
);
|
||||
}
|
||||
|
||||
prodInvariant[SEEN_SYMBOL] = true;
|
||||
path.replaceWith(
|
||||
|
||||
@@ -375,11 +375,13 @@ function getPlugins(
|
||||
modulesToStub,
|
||||
featureFlags
|
||||
) {
|
||||
// Extract error codes 1st so we can replace invariant messages in prod builds
|
||||
// Without re-running the slow build script.
|
||||
const plugins = [
|
||||
babel(updateBabelConfig(babelOpts, bundleType)),
|
||||
alias(
|
||||
Modules.getAliases(paths, bundleType, moduleType, argv['extract-errors'])
|
||||
),
|
||||
babel(updateBabelConfig(babelOpts, bundleType)),
|
||||
];
|
||||
|
||||
const replaceModules = Modules.getDefaultReplaceModules(
|
||||
|
||||
Reference in New Issue
Block a user