Create a SourceFile-level indirection on children maps, store SyntaxList children directly on nodes. (#59154)

This commit is contained in:
Daniel Rosenwasser
2024-07-09 08:55:41 +09:00
committed by GitHub
parent 247a98335d
commit a6fb4dc103
6 changed files with 67 additions and 23 deletions

View File

@@ -457,9 +457,9 @@ class NodeObject<TKind extends SyntaxKind> implements Node {
return this.getChildren(sourceFile)[index];
}
public getChildren(sourceFile?: SourceFileLike): readonly Node[] {
public getChildren(sourceFile: SourceFileLike = getSourceFileOfNode(this)): readonly 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 getNodeChildren(this) ?? setNodeChildren(this, createChildren(this, sourceFile));
return getNodeChildren(this, sourceFile) ?? setNodeChildren(this, sourceFile, createChildren(this, sourceFile));
}
public getFirstToken(sourceFile?: SourceFileLike): Node | undefined {
@@ -558,7 +558,7 @@ function createSyntaxList(nodes: NodeArray<Node>, parent: Node): Node {
pos = node.end;
}
addSyntheticNodes(children, pos, nodes.end, parent);
setNodeChildren(list, children);
list._children = children;
return list;
}