File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change 21
21
* !<cond> ? invariant(0, ...) : undefined;
22
22
*/
23
23
module . exports = function inlineInvariant ( context ) {
24
- const t = context . types ;
24
+ const replaceTemplate = context . template ( `
25
+ if (!%%cond%%) {
26
+ invariant(0, %%args%%);
27
+ }
28
+ ` ) ;
25
29
26
30
return {
27
31
visitor : {
@@ -33,17 +37,8 @@ module.exports = function inlineInvariant(context) {
33
37
return ;
34
38
}
35
39
36
- const args = node . arguments . slice ( 0 ) ;
37
- args [ 0 ] = t . numericLiteral ( 0 ) ;
38
-
39
- path . replaceWith (
40
- t . ifStatement (
41
- t . unaryExpression ( '!' , node . arguments [ 0 ] ) ,
42
- t . expressionStatement (
43
- t . callExpression ( t . identifier ( node . callee . name ) , args )
44
- )
45
- )
46
- ) ;
40
+ const [ cond , args ] = node . arguments ;
41
+ path . replaceWith ( replaceTemplate ( { cond, args } ) ) ;
47
42
} ,
48
43
} ,
49
44
} ;
You can’t perform that action at this time.
0 commit comments