self_example/Spider/Chapter11_JavaScript逆向/learn-ast/test.js

22 lines
560 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);