Skip to content

Commit

Permalink
Remove getOrSetNodeChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Apr 4, 2024
1 parent 2c02eeb commit cd378b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
12 changes: 2 additions & 10 deletions src/compiler/factory/nodeChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ import {
getNameFromPropertyName,
getNewLineCharacter,
getNewLineOrDefaultFromHost,
getNodeChildren,
getNonAssignedNameOfDeclaration,
getNormalizedAbsolutePath,
getObjectFlags,
getOrSetNodeChildren,
getQuotePreference,
getScriptKind,
getSetExternalModuleIndicator,
Expand Down Expand Up @@ -438,7 +438,7 @@ class NodeObject<TKind extends SyntaxKind> 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 {
Expand Down

0 comments on commit cd378b4

Please sign in to comment.