MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / findParentNode

Function findParentNode

packages/expr/src/autocomplete.ts:543–556  ·  view source on GitHub ↗

* Finds the parent of child node in the provided AST.

(child: AnyNode, ast: Expression)

Source from the content-addressed store, hash-verified

541 * Finds the parent of child node in the provided AST.
542 */
543function findParentNode(child: AnyNode, ast: Expression): AnyNode | undefined {
544 let foundParent: AnyNode | undefined;
545
546 walk.ancestor(ast, {
547 [child.type]: (node: AcornNode, _state: undefined, ancestors: AnyNode[]) => {
548 if (node.start === child.start && node.end === child.end) {
549 // The parent is the second last ancestor in the stack (last one is the actual node)
550 foundParent = ancestors[ancestors.length - 2];
551 }
552 },
553 });
554
555 return foundParent;
556}
557
558function isSupportedMemberProperty(node: Expression | PrivateIdentifier | Super) {
559 return node.type === 'Identifier' || node.type === 'Literal';

Callers 2

getSuggestionsForNodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected