mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 12:32:42 -05:00
Store node children WeakMaps in vars and bind its methods as locals.
This commit is contained in:
@@ -4,18 +4,25 @@ import {
|
||||
Node,
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
const nodeChildren = new WeakMap<Node, readonly Node[] | undefined>();
|
||||
// Why var? It avoids TDZ checks in the runtime which can be costly.
|
||||
// See: https://github.com/microsoft/TypeScript/issues/52924
|
||||
/* eslint-disable no-var */
|
||||
var nodeChildren = new WeakMap<Node, readonly Node[] | undefined>();
|
||||
var nodeChildrenGet = nodeChildren.get.bind(nodeChildren);
|
||||
var nodeChildrenSet = nodeChildren.set.bind(nodeChildren);
|
||||
/* eslint-enable no-var */
|
||||
|
||||
|
||||
/** @internal */
|
||||
export function getNodeChildren(node: Node): readonly Node[] | undefined {
|
||||
if (!isNodeKind(node.kind)) return emptyArray;
|
||||
|
||||
return nodeChildren.get(node);
|
||||
return nodeChildrenGet(node);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function setNodeChildren(node: Node, children: readonly Node[]): readonly Node[] {
|
||||
nodeChildren.set(node, children);
|
||||
nodeChildrenSet(node, children);
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user