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');
fork icon1
star icon6
watch icon1

+ 11 other calls in file

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;
fork icon0
star icon2
watch icon0

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保证不重名
fork icon0
star icon0
watch icon0

+ 4 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)