Adds typings for esprima-walk package (#10898)

This commit is contained in:
Tyler Waters
2016-08-30 08:00:42 -07:00
committed by Masahiro Wakame
parent d5424c1dc4
commit 8e1b4362a0
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
/// <reference path="../estree/estree.d.ts" />
/// <reference path="esprima-walk.d.ts" />
import * as walk from 'esprima-walk'
var program: ESTree.Program
var string: string
var node: ESTree.Node
walk(program, _node => {
string = node.type
node = _node
})
walk.walk(program, _node => {
string = node.type
node = _node
})
walk.walkAddParent(program, _node => {
node = _node
node = _node.parent
string = node.type
})

40
esprima-walk/esprima-walk.d.ts vendored Normal file
View File

@@ -0,0 +1,40 @@
// Type definitions for esprima-walk v0.1.0
// Project: https://github.com/jrajav/esprima-walk
// Definitions by: tswaters <https://github.com/tswaters>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../estree/estree.d.ts" />
declare module "esprima-walk" {
interface NodeWithParent extends ESTree.Node {
parent?: ESTree.Node
}
/**
* Walk the provided AST; fn is called once for each node with a `type`
* @param {ESTree.Program} ast program to walk
* @param {function} fn function invoked for each node with type
*/
function walk (ast: ESTree.Program, fn:(node: ESTree.Node)=>void) :void
namespace walk {
/**
* Walk the provided AST; fn is called once for each node with a `type`
* @param {ESTree.Program} ast program to walk
* @param {function} fn function invoked for each node
*/
export function walk (ast: ESTree.Program, fn:(node: ESTree.Node)=>void) :void
/**
* Walk the provided AST; fn is called once for each node with a `type`.
* Adds a parent property prior to invoking fn when applicable
* @param {ESTree.Program} ast program to walk
* @param {function} fn function invoked for each node
*/
export function walkAddParent (ast: ESTree.Program, fn:(node: NodeWithParent)=>void) :void
}
export = walk
}