diff --git a/src/compiler/factory/nodeChildren.ts b/src/compiler/factory/nodeChildren.ts index 79e8563f6f5..fa77de189fc 100644 --- a/src/compiler/factory/nodeChildren.ts +++ b/src/compiler/factory/nodeChildren.ts @@ -4,18 +4,25 @@ import { Node, } from "../_namespaces/ts.js"; -const nodeChildren = new WeakMap(); +// 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(); +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; }