mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Make utility mehtod names clearer.
This commit is contained in:
parent
7d2009ab64
commit
ea3e509154
@ -325,14 +325,12 @@ module ts {
|
||||
|
||||
// Context flags computed by aggregating child flags upwards.
|
||||
|
||||
// If this node, or any of it's children (transitively) contain an error.
|
||||
// Used during incremental parsing to determine if this node or any of its children had an
|
||||
// error. Computed only once and then cached.
|
||||
ThisNodeOrAnySubNodesHasError = 1 << 5,
|
||||
|
||||
// Used during incremental parsing to determine if we need to visit this node to see if
|
||||
// any of its children had an error. Once we compute that once, we can set this bit on the
|
||||
// node to know that we never have to do it again. From that point on, we can just check
|
||||
// the node directly for 'ContainsError'.
|
||||
HasComputedThisNodeOrAnySubNodesHasError = 1 << 6
|
||||
// Used to know if we've computed data from children and cached it in this node.
|
||||
HasAggregatedChildData = 1 << 6
|
||||
}
|
||||
|
||||
export interface Node extends TextRange {
|
||||
|
||||
@ -62,31 +62,34 @@ module ts {
|
||||
return node.end - node.pos;
|
||||
}
|
||||
|
||||
export function hasFlag(val: number, flag: number): boolean {
|
||||
function hasFlag(val: number, flag: number): boolean {
|
||||
return (val & flag) !== 0;
|
||||
}
|
||||
|
||||
// Returns true if this node contains a parse error anywhere underneath it.
|
||||
export function containsParseError(node: Node): boolean {
|
||||
if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError)) {
|
||||
aggregateChildData(node);
|
||||
return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError);
|
||||
}
|
||||
|
||||
function aggregateChildData(node: Node): void {
|
||||
if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasAggregatedChildData)) {
|
||||
// A node is considered to contain a parse error if:
|
||||
// a) the parser explicitly marked that it had an error
|
||||
// b) any of it's children reported that it had an error.
|
||||
var val = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) ||
|
||||
var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) ||
|
||||
forEachChild(node, containsParseError);
|
||||
|
||||
// If so, mark ourselves accordingly.
|
||||
if (val) {
|
||||
if (thisNodeOrAnySubNodesHasError) {
|
||||
node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError;
|
||||
}
|
||||
|
||||
// Also mark that we've propogated the child information to this node. This way we can
|
||||
// always consult the bit directly on this node without needing to check its children
|
||||
// again.
|
||||
node.parserContextFlags |= ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError;
|
||||
node.parserContextFlags |= ParserContextFlags.HasAggregatedChildData;
|
||||
}
|
||||
|
||||
return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError);
|
||||
}
|
||||
|
||||
export function getSourceFileOfNode(node: Node): SourceFile {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user