MCPcopy Create free account
hub / github.com/babel/babel / finishNodeAtNode

Function finishNodeAtNode

packages/babel-parser/src/parser/node.ts:120–140  ·  view source on GitHub ↗
(
    node: Omit<T, "type">,
    type: T["type"],
    endNode: NodeType,
  )

Source from the content-addressed store, hash-verified

118 }
119
120 finishNodeAtNode<T extends NodeType>(
121 node: Omit<T, "type">,
122 type: T["type"],
123 endNode: NodeType,
124 ): T {
125 if (!process.env.IS_PUBLISH && node.end! > 0) {
126 throw new Error(
127 "Do not call finishNode*() twice on the same node." +
128 " Instead use resetEndLocation() or change type directly.",
129 );
130 }
131 (node as T).type = type;
132 node.end = endNode.end;
133 const { optionFlags } = this;
134 if (optionFlags & OptionFlags.Locations) {
135 node.loc!.end = endNode.loc!.end;
136 }
137 if (optionFlags & OptionFlags.Ranges) node.range![1] = node.end!;
138 if (optionFlags & OptionFlags.AttachComment) this.processComment(node as T);
139 return node as T;
140 }
141
142 resetStartLocation(node: BaseNode, startLoc: Position): void {
143 node.start = startLoc.index;

Callers

nothing calls this directly

Calls 1

processCommentMethod · 0.80

Tested by

no test coverage detected