简体   繁体   中英

check parameters of a function with Babel

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

you can use inner function like this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM