Add missing/undocumented functions (#27464)

Those functions and properties are not documented.
This commit is contained in:
mail6543210
2018-07-23 08:30:19 -07:00
committed by Andy
parent 23735e51b7
commit d57015fa9f
2 changed files with 34 additions and 0 deletions
+20
View File
@@ -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;
}
}
+14
View File
@@ -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);
}