check parameters of a function with Babel

217 views Asked by At

I want to check parameters of a function to be in a range with babel. I mean I want to change the following code:

function(arg1, arg2)
{
     body of function
}

to this code:

function checkRange(argument)
{
       some checking
}
function(arg1, arg2)
{
     checkRange(arg1);
     checkRange(arg2);
     body of function
}

how can I do this with Babel? I read this tutorial: https://lihautan.com/step-by-step-guide-for-writing-a-babel-transformation/ and I also read a number of examples in https://github.com/babel/babel/tree/master/packages and more and more. but I'm very beginner in Babel

1

There are 1 answers

3
zek On

you can use inner function like this :

function(arg1, arg2)
{
 function checkRange(argument)
 {
   some checking
 }

 checkRange(arg1);
 checkRange(arg2);
 body of function
}