mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Adds typings for esprima-walk package (#10898)
This commit is contained in:
committed by
Masahiro Wakame
parent
d5424c1dc4
commit
8e1b4362a0
25
esprima-walk/esprima-walk-tests.ts
Normal file
25
esprima-walk/esprima-walk-tests.ts
Normal 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
40
esprima-walk/esprima-walk.d.ts
vendored
Normal 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user