diff --git a/types/traverse/index.d.ts b/types/traverse/index.d.ts index dc78978da5..c81094be98 100644 --- a/types/traverse/index.d.ts +++ b/types/traverse/index.d.ts @@ -121,6 +121,11 @@ declare namespace traverse { */ parent: TraverseContext | undefined; + /** + * The contexts of the node's parents. + */ + parents: TraverseContext[]; + /** * The name of the key of the present node in its parent. * This is `undefined` for the root node. @@ -172,6 +177,11 @@ declare namespace traverse { */ delete(stopHere?: boolean): void; + /** + * Object keys of the node. + */ + keys: string[] | null; + /** * Call this function before all of the children are traversed. * You can assign into `this.keys` here to traverse in a custom order. @@ -192,6 +202,16 @@ declare namespace traverse { * Call this function after each of the children are traversed. */ post(callback: (this: TraverseContext, child: any) => void): void; + + /** + * Stops traversal entirely. + */ + stop(): void; + + /** + * Prevents traversing descendents of the current node. + */ + block(): void; } } diff --git a/types/traverse/traverse-tests.ts b/types/traverse/traverse-tests.ts index f31ec97e3f..c96cdf813d 100644 --- a/types/traverse/traverse-tests.ts +++ b/types/traverse/traverse-tests.ts @@ -62,3 +62,17 @@ function testPaths(){ }) }) } + +function testPropsAndFuncs(){ + var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; + + traverse(obj).forEach(function (x) { + console.log(this.keys); + console.log(this.parents); + + if (this.level == 2) this.block(); + if (this.level > 10) this.stop(); + }); + + console.dir(obj); +}