File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
module . exports = function inlineInvariant ( context ) {
17
17
const replaceTemplate = context . template ( `
18
- if (!%%cond%%) {
19
- invariant(0, %%args%%);
20
- }
18
+ (%%cond%%) || invariant(0, %%args%%)
21
19
` ) ;
22
20
23
21
return {
@@ -39,9 +37,9 @@ module.exports = function inlineInvariant(context) {
39
37
40
38
function isAppropriateInvariantCall ( node , parent ) {
41
39
return (
40
+ parent . type === 'ExpressionStatement' &&
42
41
node . callee . type === 'Identifier' &&
43
42
node . callee . name === 'invariant' &&
44
- node . arguments . length > 0 &&
45
- parent . type === 'ExpressionStatement'
43
+ node . arguments . length > 0
46
44
) ;
47
45
}
Original file line number Diff line number Diff line change 1
1
// @flow strict
2
2
3
- export default function invariant ( condition : mixed , message : string ) {
3
+ /* istanbul ignore file */
4
+ export default function invariant ( condition : mixed , message ?: string ) : void {
4
5
const booleanCondition = Boolean ( condition ) ;
5
- /* istanbul ignore else */
6
6
if ( ! booleanCondition ) {
7
- throw new Error ( message ) ;
7
+ throw new Error ( message || 'Unexpected invariant triggered' ) ;
8
8
}
9
9
}
You can’t perform that action at this time.
0 commit comments