22 lines
560 B
JavaScript
22 lines
560 B
JavaScript
import * as t from '@babel/types';
|
||
|
||
// 创建标识符"a"
|
||
const idA = t.identifier("a");
|
||
|
||
// 创建数字字面量1
|
||
const literalOne = t.numericLiteral(1);
|
||
|
||
// 创建二元表达式 "a + 1"
|
||
const binaryExpression = t.binaryExpression("+", idA, literalOne);
|
||
|
||
// 创建标识符"b"
|
||
const idB = t.identifier("b");
|
||
|
||
// 创建变量声明器
|
||
const variableDeclarator = t.variableDeclarator(idB, binaryExpression);
|
||
|
||
// 创建变量声明(const)
|
||
const variableDeclaration = t.variableDeclaration("const", [variableDeclarator]);
|
||
|
||
console.log(variableDeclaration);
|