Files
DefinitelyTyped/babel-types/babel-types-tests.ts
2016-05-10 12:22:25 -07:00

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: "*" });