From ea3e509154efd42fc30c5198c34aefe229aa02e2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 Dec 2014 15:29:52 -0800 Subject: [PATCH] Make utility mehtod names clearer. --- src/compiler/types.ts | 10 ++++------ src/compiler/utilities.ts | 17 ++++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2c5376e744fa2..48288628a1710 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -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 { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index d35364009b6a5..8e0a02b2be683 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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 {