Skip to content

Commit

Permalink
invariant: improve code that babel outputs (#2064)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 30, 2019
1 parent dea6028 commit 91a4be2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions resources/inline-invariant.js
Expand Up @@ -15,9 +15,7 @@
*/
module.exports = function inlineInvariant(context) {
const replaceTemplate = context.template(`
if (!%%cond%%) {
invariant(0, %%args%%);
}
(%%cond%%) || invariant(0, %%args%%)
`);

return {
Expand All @@ -39,9 +37,9 @@ module.exports = function inlineInvariant(context) {

function isAppropriateInvariantCall(node, parent) {
return (
parent.type === 'ExpressionStatement' &&
node.callee.type === 'Identifier' &&
node.callee.name === 'invariant' &&
node.arguments.length > 0 &&
parent.type === 'ExpressionStatement'
node.arguments.length > 0
);
}
6 changes: 3 additions & 3 deletions src/jsutils/invariant.js
@@ -1,9 +1,9 @@
// @flow strict

export default function invariant(condition: mixed, message: string) {
/* istanbul ignore file */
export default function invariant(condition: mixed, message?: string): void {
const booleanCondition = Boolean(condition);
/* istanbul ignore else */
if (!booleanCondition) {
throw new Error(message);
throw new Error(message || 'Unexpected invariant triggered');
}
}

0 comments on commit 91a4be2

Please sign in to comment.