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:
Brian Vaughn
2017-10-20 08:35:33 -07:00
committed by GitHub
parent 2de3702d93
commit 845b1afdc5
2 changed files with 19 additions and 12 deletions

View File

@@ -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(

View File

@@ -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(