Skip to content

Commit a72abc8

Browse files
committed
Make getOriginalNode/getParseTreeNode public
1 parent ff4c72d commit a72abc8

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/compiler/utilities.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,57 +2042,6 @@ namespace ts {
20422042
|| positionIsSynthesized(node.end);
20432043
}
20442044

2045-
export function getOriginalNode(node: Node): Node;
2046-
export function getOriginalNode<T extends Node>(node: Node, nodeTest: (node: Node) => node is T): T;
2047-
export function getOriginalNode(node: Node, nodeTest?: (node: Node) => boolean): Node {
2048-
if (node) {
2049-
while (node.original !== undefined) {
2050-
node = node.original;
2051-
}
2052-
}
2053-
2054-
return !nodeTest || nodeTest(node) ? node : undefined;
2055-
}
2056-
2057-
/**
2058-
* Gets a value indicating whether a node originated in the parse tree.
2059-
*
2060-
* @param node The node to test.
2061-
*/
2062-
export function isParseTreeNode(node: Node): boolean {
2063-
return (node.flags & NodeFlags.Synthesized) === 0;
2064-
}
2065-
2066-
/**
2067-
* Gets the original parse tree node for a node.
2068-
*
2069-
* @param node The original node.
2070-
* @returns The original parse tree node if found; otherwise, undefined.
2071-
*/
2072-
export function getParseTreeNode(node: Node): Node;
2073-
2074-
/**
2075-
* Gets the original parse tree node for a node.
2076-
*
2077-
* @param node The original node.
2078-
* @param nodeTest A callback used to ensure the correct type of parse tree node is returned.
2079-
* @returns The original parse tree node if found; otherwise, undefined.
2080-
*/
2081-
export function getParseTreeNode<T extends Node>(node: Node, nodeTest?: (node: Node) => node is T): T;
2082-
export function getParseTreeNode(node: Node, nodeTest?: (node: Node) => boolean): Node {
2083-
if (isParseTreeNode(node)) {
2084-
return node;
2085-
}
2086-
2087-
node = getOriginalNode(node);
2088-
2089-
if (isParseTreeNode(node) && (!nodeTest || nodeTest(node))) {
2090-
return node;
2091-
}
2092-
2093-
return undefined;
2094-
}
2095-
20962045
export function getOriginalSourceFileOrBundle(sourceFileOrBundle: SourceFile | Bundle) {
20972046
if (sourceFileOrBundle.kind === SyntaxKind.Bundle) {
20982047
return updateBundle(sourceFileOrBundle, sameMap(sourceFileOrBundle.sourceFiles, getOriginalSourceFile));
@@ -4530,4 +4479,55 @@ namespace ts {
45304479
return true;
45314480
}
45324481
}
4482+
4483+
export function getOriginalNode(node: Node): Node;
4484+
export function getOriginalNode<T extends Node>(node: Node, nodeTest: (node: Node) => node is T): T;
4485+
export function getOriginalNode(node: Node, nodeTest?: (node: Node) => boolean): Node {
4486+
if (node) {
4487+
while (node.original !== undefined) {
4488+
node = node.original;
4489+
}
4490+
}
4491+
4492+
return !nodeTest || nodeTest(node) ? node : undefined;
4493+
}
4494+
4495+
/**
4496+
* Gets a value indicating whether a node originated in the parse tree.
4497+
*
4498+
* @param node The node to test.
4499+
*/
4500+
export function isParseTreeNode(node: Node): boolean {
4501+
return (node.flags & NodeFlags.Synthesized) === 0;
4502+
}
4503+
4504+
/**
4505+
* Gets the original parse tree node for a node.
4506+
*
4507+
* @param node The original node.
4508+
* @returns The original parse tree node if found; otherwise, undefined.
4509+
*/
4510+
export function getParseTreeNode(node: Node): Node;
4511+
4512+
/**
4513+
* Gets the original parse tree node for a node.
4514+
*
4515+
* @param node The original node.
4516+
* @param nodeTest A callback used to ensure the correct type of parse tree node is returned.
4517+
* @returns The original parse tree node if found; otherwise, undefined.
4518+
*/
4519+
export function getParseTreeNode<T extends Node>(node: Node, nodeTest?: (node: Node) => node is T): T;
4520+
export function getParseTreeNode(node: Node, nodeTest?: (node: Node) => boolean): Node {
4521+
if (isParseTreeNode(node)) {
4522+
return node;
4523+
}
4524+
4525+
node = getOriginalNode(node);
4526+
4527+
if (isParseTreeNode(node) && (!nodeTest || nodeTest(node))) {
4528+
return node;
4529+
}
4530+
4531+
return undefined;
4532+
}
45334533
}

0 commit comments

Comments
 (0)