From cd378b4afcccafc74be33047b27ee4465138c9f5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:06:38 -0700 Subject: [PATCH] Remove getOrSetNodeChildren --- src/compiler/factory/nodeChildren.ts | 12 ++---------- src/services/services.ts | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/compiler/factory/nodeChildren.ts b/src/compiler/factory/nodeChildren.ts index 1c2e9f6683cc6..89fa8383b281d 100644 --- a/src/compiler/factory/nodeChildren.ts +++ b/src/compiler/factory/nodeChildren.ts @@ -8,20 +8,12 @@ export function getNodeChildren(node: Node): Node[] | undefined { } /** @internal */ -export function setNodeChildren(node: Node, children: Node[]) { +export function setNodeChildren(node: Node, children: Node[]): Node[] { nodeChildren.set(node, children); + return children; } /** @internal */ export function unsetNodeChildren(node: Node) { nodeChildren.delete(node); } - -/** @internal */ -export function getOrSetNodeChildren(node: Node, fn: () => Node[]): Node[] { - let children = getNodeChildren(node); - if (children === undefined) { - setNodeChildren(node, children = fn()); - } - return children; -} diff --git a/src/services/services.ts b/src/services/services.ts index 9371bb1ec46ce..5e8f470278a81 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -106,10 +106,10 @@ import { getNameFromPropertyName, getNewLineCharacter, getNewLineOrDefaultFromHost, + getNodeChildren, getNonAssignedNameOfDeclaration, getNormalizedAbsolutePath, getObjectFlags, - getOrSetNodeChildren, getQuotePreference, getScriptKind, getSetExternalModuleIndicator, @@ -438,7 +438,7 @@ class NodeObject implements Node { public getChildren(sourceFile?: SourceFileLike): Node[] { this.assertHasRealPosition("Node without a real position cannot be scanned and thus has no token nodes - use forEachChild and collect the result if that's fine"); - return getOrSetNodeChildren(this, () => createChildren(this, sourceFile)); + return getNodeChildren(this) ?? setNodeChildren(this, createChildren(this, sourceFile)); } public getFirstToken(sourceFile?: SourceFileLike): Node | undefined {