-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-5.5' into cherry-pick/59070/release-5.5
- Loading branch information
Showing
319 changed files
with
6,318 additions
and
2,430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
import { | ||
Debug, | ||
emptyArray, | ||
isNodeKind, | ||
Node, | ||
SourceFileLike, | ||
SyntaxKind, | ||
SyntaxList, | ||
} from "../_namespaces/ts.js"; | ||
|
||
const nodeChildren = new WeakMap<Node, readonly Node[] | undefined>(); | ||
const sourceFileToNodeChildren = new WeakMap<SourceFileLike, WeakMap<Node, readonly Node[] | undefined>>(); | ||
|
||
/** @internal */ | ||
export function getNodeChildren(node: Node): readonly Node[] | undefined { | ||
if (!isNodeKind(node.kind)) return emptyArray; | ||
export function getNodeChildren(node: Node, sourceFile: SourceFileLike): readonly Node[] | undefined { | ||
const kind = node.kind; | ||
if (!isNodeKind(kind)) { | ||
return emptyArray; | ||
} | ||
if (kind === SyntaxKind.SyntaxList) { | ||
return (node as SyntaxList)._children; | ||
} | ||
|
||
return nodeChildren.get(node); | ||
return sourceFileToNodeChildren.get(sourceFile)?.get(node); | ||
} | ||
|
||
/** @internal */ | ||
export function setNodeChildren(node: Node, children: readonly Node[]): readonly Node[] { | ||
nodeChildren.set(node, children); | ||
export function setNodeChildren(node: Node, sourceFile: SourceFileLike, children: readonly Node[]): readonly Node[] { | ||
if (node.kind === SyntaxKind.SyntaxList) { | ||
// SyntaxList children are always eagerly created in the process of | ||
// creating their parent's `children` list. We shouldn't need to set them here. | ||
Debug.fail("Should not need to re-set the children of a SyntaxList."); | ||
} | ||
|
||
let map = sourceFileToNodeChildren.get(sourceFile); | ||
if (map === undefined) { | ||
map = new WeakMap(); | ||
sourceFileToNodeChildren.set(sourceFile, map); | ||
} | ||
map.set(node, children); | ||
return children; | ||
} | ||
|
||
/** @internal */ | ||
export function unsetNodeChildren(node: Node) { | ||
nodeChildren.delete(node); | ||
export function unsetNodeChildren(node: Node, origSourceFile: SourceFileLike) { | ||
if (node.kind === SyntaxKind.SyntaxList) { | ||
// Syntax lists are synthesized and we store their children directly on them. | ||
// They are a special case where we expect incremental parsing to toss them away entirely | ||
// if a change intersects with their containing parents. | ||
Debug.fail("Did not expect to unset the children of a SyntaxList."); | ||
} | ||
sourceFileToNodeChildren.get(origSourceFile)?.delete(node); | ||
} | ||
|
||
/** @internal */ | ||
export function transferSourceFileChildren(sourceFile: SourceFileLike, targetSourceFile: SourceFileLike) { | ||
const map = sourceFileToNodeChildren.get(sourceFile); | ||
if (map !== undefined) { | ||
sourceFileToNodeChildren.delete(sourceFile); | ||
sourceFileToNodeChildren.set(targetSourceFile, map); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.