Don't cache child lists for tokens (#58233)

This commit is contained in:
Daniel Rosenwasser
2024-04-19 14:49:31 -07:00
committed by GitHub
parent aedd1b1bb5
commit e8f22253ba
8 changed files with 21 additions and 19 deletions
+10 -4
View File
@@ -1,14 +1,20 @@
import { Node } from "../_namespaces/ts";
import {
emptyArray,
isNodeKind,
Node,
} from "../_namespaces/ts";
const nodeChildren = new WeakMap<Node, Node[] | undefined>();
const nodeChildren = new WeakMap<Node, readonly Node[] | undefined>();
/** @internal */
export function getNodeChildren(node: Node): Node[] | undefined {
export function getNodeChildren(node: Node): readonly Node[] | undefined {
if (!isNodeKind(node.kind)) return emptyArray;
return nodeChildren.get(node);
}
/** @internal */
export function setNodeChildren(node: Node, children: Node[]): Node[] {
export function setNodeChildren(node: Node, children: readonly Node[]): readonly Node[] {
nodeChildren.set(node, children);
return children;
}
+1 -1
View File
@@ -6209,7 +6209,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
}
// @api
function createSyntaxList(children: Node[]) {
function createSyntaxList(children: readonly Node[]) {
const node = createBaseNode<SyntaxList>(SyntaxKind.SyntaxList);
setNodeChildren(node, children);
return node;
+1 -1
View File
@@ -9006,7 +9006,7 @@ export interface NodeFactory {
// Synthetic Nodes
//
/** @internal */ createSyntheticExpression(type: Type, isSpread?: boolean, tupleNameSource?: ParameterDeclaration | NamedTupleMember): SyntheticExpression;
/** @internal */ createSyntaxList(children: Node[]): SyntaxList;
/** @internal */ createSyntaxList(children: readonly Node[]): SyntaxList;
//
// Transformation nodes