How to use the switchCase function from @babel/types
Find comprehensive JavaScript @babel/types.switchCase code examples handpicked from public code repositorys.
54 55 56 57 58 59 60 61 62 63
let cases = []; statements.map(function (v, i) { //记录执行顺序 dispenserArr[v.index] = i; //打乱顺序 let switchCase = t.switchCase(t.numericLiteral(i), [v.value, t.continueStatement()]); cases.push(switchCase); }); let dispenserStr = dispenserArr.join('|'); let array = path.scope.generateUidIdentifier('array');
+ 11 other calls in file
GitHub: chardos/rsk
![chardos profile picture](/chardos.png?size=40)
66 67 68 69 70 71 72 73 74 75
return state; `; }; const generateCaseObject = actionName => t.switchCase(t.identifier(changeCase.constantCase(actionName)), [ t.returnStatement(t.identifier('state')) ]); exports.generateCaseObject = generateCaseObject;
24 25 26 27 28 29 30 31 32 33
//构建分发器,创建switchCase数组 let dispenserArr = []; let cases = []; Statements.map(function(v, i){ dispenserArr[v.index] = i; let switchCase = t.switchCase(t.numericLiteral(i), [v.value, t.continueStatement()]); cases.push(switchCase); }); let dispenserStr = dispenserArr.join('|'); //生成_array和_index标识符,利用BabelAPI保证不重名
+ 4 other calls in file
@babel/types.identifier is the most popular function in @babel/types (20936 examples)