mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 21:31:12 +08:00
27 lines
587 B
TypeScript
27 lines
587 B
TypeScript
|
|
/// <reference types="babel-traverse" />
|
|
|
|
|
|
// Examples from https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-types
|
|
import traverse from "babel-traverse";
|
|
import * as t from "babel-types";
|
|
|
|
let ast: t.Node;
|
|
|
|
traverse(ast, {
|
|
enter(path) {
|
|
let node = path.node;
|
|
if (t.isIdentifier(node, { name: "n" })) {
|
|
node.name = "x";
|
|
}
|
|
}
|
|
});
|
|
|
|
if (t.isBinaryExpression(ast)) {
|
|
ast.left;
|
|
ast.right;
|
|
ast.operator;
|
|
}
|
|
t.assertBinaryExpression(ast);
|
|
t.assertBinaryExpression(ast, { operator: "*" });
|