Files
DefinitelyTyped/types/babylon-walk/babylon-walk-tests.ts
Marek Buchar 9df54d39a0 simple definition for babylon-walk (#20546)
* babylon-walk

* babylon-walk - added missing tests

* babylon-walk - missing tsconfig.json

* Visitor types enumeration fix

* deleted test file

* added test file back

* removed tsconfig

* added tsconfig back

* tsconfig fix

* downgraded typescript version to 2.3

* strictFunctionTypes: true

* test definitions fix

* added tslint.json and fixed most of issues

* fix for "'Instead of export =-ing a namespace, use the body of the namespace as the module body."
2017-10-15 10:31:19 -07:00

38 lines
933 B
TypeScript

import * as babelTypes from "babel-types";
import * as walk from "babylon-walk";
declare function assert(expr: boolean): void;
const simpleVisitors: walk.visitors<walk.SimpleVisitor> = {
File: (node: babelTypes.Node, state: any) => {
state.out = 1;
},
};
const ancestorVisitors: walk.visitors<walk.AncestorVisitor> = {
File: (node: babelTypes.Node, state: any, ancestors: babelTypes.Node[]) => {
state.out = 2;
},
};
const recursiveVisitors: walk.visitors<walk.RecursiveVisitor> = {
File: (node: babelTypes.Node, state: any, next: (node: babelTypes.Node) => void) => {
state.out = 3;
},
};
const node: any = {
type: "File",
};
const state: any = {
out: 0,
};
walk.simple(node, simpleVisitors, state);
assert(state.out === 1);
walk.ancestor(node, ancestorVisitors, state);
assert(state.out === 2);
walk.recursive(node, recursiveVisitors, state);
assert(state.out === 3);