Skip to content

Commit fbfb94f

Browse files
Merge pull request #1470 from Microsoft/flagAggregation
Make utility method names clearer.
2 parents 7d2009a + ea3e509 commit fbfb94f

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/compiler/types.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,12 @@ module ts {
325325

326326
// Context flags computed by aggregating child flags upwards.
327327

328-
// If this node, or any of it's children (transitively) contain an error.
328+
// Used during incremental parsing to determine if this node or any of its children had an
329+
// error. Computed only once and then cached.
329330
ThisNodeOrAnySubNodesHasError = 1 << 5,
330331

331-
// Used during incremental parsing to determine if we need to visit this node to see if
332-
// any of its children had an error. Once we compute that once, we can set this bit on the
333-
// node to know that we never have to do it again. From that point on, we can just check
334-
// the node directly for 'ContainsError'.
335-
HasComputedThisNodeOrAnySubNodesHasError = 1 << 6
332+
// Used to know if we've computed data from children and cached it in this node.
333+
HasAggregatedChildData = 1 << 6
336334
}
337335

338336
export interface Node extends TextRange {

src/compiler/utilities.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,34 @@ module ts {
6262
return node.end - node.pos;
6363
}
6464

65-
export function hasFlag(val: number, flag: number): boolean {
65+
function hasFlag(val: number, flag: number): boolean {
6666
return (val & flag) !== 0;
6767
}
6868

6969
// Returns true if this node contains a parse error anywhere underneath it.
7070
export function containsParseError(node: Node): boolean {
71-
if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError)) {
71+
aggregateChildData(node);
72+
return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError);
73+
}
74+
75+
function aggregateChildData(node: Node): void {
76+
if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasAggregatedChildData)) {
7277
// A node is considered to contain a parse error if:
7378
// a) the parser explicitly marked that it had an error
7479
// b) any of it's children reported that it had an error.
75-
var val = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) ||
80+
var thisNodeOrAnySubNodesHasError = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) ||
7681
forEachChild(node, containsParseError);
7782

7883
// If so, mark ourselves accordingly.
79-
if (val) {
84+
if (thisNodeOrAnySubNodesHasError) {
8085
node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError;
8186
}
8287

8388
// Also mark that we've propogated the child information to this node. This way we can
8489
// always consult the bit directly on this node without needing to check its children
8590
// again.
86-
node.parserContextFlags |= ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError;
91+
node.parserContextFlags |= ParserContextFlags.HasAggregatedChildData;
8792
}
88-
89-
return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError);
9093
}
9194

9295
export function getSourceFileOfNode(node: Node): SourceFile {

0 commit comments

Comments
 (0)