mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-07 23:37:35 +08:00
* 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."
38 lines
933 B
TypeScript
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);
|