How to use the whileStatement function from @babel/types

Find comprehensive JavaScript @babel/types.whileStatement code examples handpicked from public code repositorys.

77
78
79
80
81
82
83
84
85
86
    let discriminant = t.unaryExpression('+', memExp);
    let switchSta = t.switchStatement(discriminant, cases);
    //拼装while (!![])
    let unaExp = t.unaryExpression('!', t.arrayExpression());
    unaExp = t.unaryExpression('!', unaExp);
    let whileSta = t.whileStatement(unaExp, t.blockStatement([switchSta, t.breakStatement()]))
    path.get('body').replaceWith(t.blockStatement([dispenser, whileSta]));
  }
})
let code = generator(ast).code;
fork icon1
star icon6
watch icon1

+ 11 other calls in file

354
355
356
357
358
359
360
361
362
363
    } else if (!this.isTerminalNode(child)) {
      children.push(child.accept(this));
    }
  });

  return t.whileStatement(test, t.blockStatement(flatten(children)));
}

visitFor_stmt(ctx) {
  let contexts = ctx.children.filter(item => !this.isTerminalNode(item));
fork icon0
star icon1
watch icon0

49
50
51
52
53
54
55
56
57
58
	let switchSta = t.switchStatement(discriminant, cases);
	//生成while循环中的条件 !![]
	let unaExp = t.unaryExpression("!", t.arrayExpression());
	unaExp = t.unaryExpression("!", unaExp);
	//生成整个while循环
	let whileSta = t.whileStatement(unaExp,  t.blockStatement([switchSta, t.breakStatement()]));
	//用分发器和while循环来构建blockStatement,替换原有节点
	path.get('body').replaceWith(t.blockStatement([dispenser, whileSta]));
	
}
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)