Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions scripts/error-codes/replace-invariant-error-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
[
Expand All @@ -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.)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's expected to occur on master builds.

// 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(
Expand Down
4 changes: 3 additions & 1 deletion scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down