From f4ee49f24e05a4a0f946194eb3890d39690f1c59 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 31 Jan 2016 08:57:32 -0800 Subject: [PATCH] Renaming parsing context flags to NodeFlags.xxxContext --- src/compiler/checker.ts | 8 ++++---- src/compiler/parser.ts | 34 +++++++++++++++++----------------- src/compiler/types.ts | 12 ++++++------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fafcffbe582..91ce1be5d74 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7183,7 +7183,7 @@ namespace ts { } } - if (node.parserContextFlags & NodeFlags.Await) { + if (node.parserContextFlags & NodeFlags.AwaitContext) { getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; } } @@ -10783,7 +10783,7 @@ namespace ts { function checkAwaitExpression(node: AwaitExpression): Type { // Grammar checking if (produceDiagnostics) { - if (!(node.parserContextFlags & NodeFlags.Await)) { + if (!(node.parserContextFlags & NodeFlags.AwaitContext)) { grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function); } @@ -11239,7 +11239,7 @@ namespace ts { function checkYieldExpression(node: YieldExpression): Type { // Grammar checking if (produceDiagnostics) { - if (!(node.parserContextFlags & NodeFlags.Yield) || isYieldExpressionInClass(node)) { + if (!(node.parserContextFlags & NodeFlags.YieldContext) || isYieldExpressionInClass(node)) { grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } @@ -13701,7 +13701,7 @@ namespace ts { function checkWithStatement(node: WithStatement) { // Grammar checking for withStatement if (!checkGrammarStatementInAmbientContext(node)) { - if (node.parserContextFlags & NodeFlags.Await) { + if (node.parserContextFlags & NodeFlags.AwaitContext) { grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_an_async_function_block); } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bbf1c2bddac..d52d1272697 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -438,7 +438,7 @@ namespace ts { // Share a single scanner across all calls to parse a source file. This helps speed things // up by avoiding the cost of creating/compiling scanners over and over again. const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); - const disallowInAndDecoratorContext = NodeFlags.DisallowIn | NodeFlags.Decorator; + const disallowInAndDecoratorContext = NodeFlags.DisallowInContext | NodeFlags.DecoratorContext; // capture constructors in 'initializeState' to avoid null checks let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; @@ -682,19 +682,19 @@ namespace ts { } function setDisallowInContext(val: boolean) { - setContextFlag(val, NodeFlags.DisallowIn); + setContextFlag(val, NodeFlags.DisallowInContext); } function setYieldContext(val: boolean) { - setContextFlag(val, NodeFlags.Yield); + setContextFlag(val, NodeFlags.YieldContext); } function setDecoratorContext(val: boolean) { - setContextFlag(val, NodeFlags.Decorator); + setContextFlag(val, NodeFlags.DecoratorContext); } function setAwaitContext(val: boolean) { - setContextFlag(val, NodeFlags.Await); + setContextFlag(val, NodeFlags.AwaitContext); } function doOutsideOfContext(context: NodeFlags, func: () => T): T { @@ -740,31 +740,31 @@ namespace ts { } function allowInAnd(func: () => T): T { - return doOutsideOfContext(NodeFlags.DisallowIn, func); + return doOutsideOfContext(NodeFlags.DisallowInContext, func); } function disallowInAnd(func: () => T): T { - return doInsideOfContext(NodeFlags.DisallowIn, func); + return doInsideOfContext(NodeFlags.DisallowInContext, func); } function doInYieldContext(func: () => T): T { - return doInsideOfContext(NodeFlags.Yield, func); + return doInsideOfContext(NodeFlags.YieldContext, func); } function doInDecoratorContext(func: () => T): T { - return doInsideOfContext(NodeFlags.Decorator, func); + return doInsideOfContext(NodeFlags.DecoratorContext, func); } function doInAwaitContext(func: () => T): T { - return doInsideOfContext(NodeFlags.Await, func); + return doInsideOfContext(NodeFlags.AwaitContext, func); } function doOutsideOfAwaitContext(func: () => T): T { - return doOutsideOfContext(NodeFlags.Await, func); + return doOutsideOfContext(NodeFlags.AwaitContext, func); } function doInYieldAndAwaitContext(func: () => T): T { - return doInsideOfContext(NodeFlags.Yield | NodeFlags.Await, func); + return doInsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext, func); } function inContext(flags: NodeFlags) { @@ -772,19 +772,19 @@ namespace ts { } function inYieldContext() { - return inContext(NodeFlags.Yield); + return inContext(NodeFlags.YieldContext); } function inDisallowInContext() { - return inContext(NodeFlags.DisallowIn); + return inContext(NodeFlags.DisallowInContext); } function inDecoratorContext() { - return inContext(NodeFlags.Decorator); + return inContext(NodeFlags.DecoratorContext); } function inAwaitContext() { - return inContext(NodeFlags.Await); + return inContext(NodeFlags.AwaitContext); } function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { @@ -4785,7 +4785,7 @@ namespace ts { // The checker may still error in the static case to explicitly disallow the yield expression. property.initializer = modifiers && modifiers.flags & NodeFlags.Static ? allowInAnd(parseNonParameterInitializer) - : doOutsideOfContext(NodeFlags.Yield | NodeFlags.DisallowIn, parseNonParameterInitializer); + : doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.DisallowInContext, parseNonParameterInitializer); parseSemicolon(); return finishNode(property); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4b619041cb8..3e5ac5094dd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -393,10 +393,10 @@ namespace ts { HasDecorators = 1 << 19, // If the file has decorators (initialized by binding) HasParamDecorators = 1 << 20, // If the file has parameter decorators (initialized by binding) HasAsyncFunctions = 1 << 21, // If the file has async functions (initialized by binding) - DisallowIn = 1 << 22, // If node was parsed in a context where 'in-expressions' are not allowed - Yield = 1 << 23, // If node was parsed in the 'yield' context created when parsing a generator - Decorator = 1 << 24, // If node was parsed as part of a decorator - Await = 1 << 25, // If node was parsed in the 'await' context created when parsing an async function + DisallowInContext = 1 << 22, // If node was parsed in a context where 'in-expressions' are not allowed + YieldContext = 1 << 23, // If node was parsed in the 'yield' context created when parsing a generator + DecoratorContext = 1 << 24, // If node was parsed as part of a decorator + AwaitContext = 1 << 25, // If node was parsed in the 'await' context created when parsing an async function ThisNodeHasError = 1 << 26, // If the parser encountered an error when parsing the code that created this node JavaScriptFile = 1 << 27, // If node was parsed in a JavaScript ThisNodeOrAnySubNodesHasError = 1 << 28, // If this node or any of its children had an error @@ -410,10 +410,10 @@ namespace ts { EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions, // Context flags set directly by the parser. - ParserGeneratedFlags = DisallowIn | Yield | Decorator | ThisNodeHasError | Await, + ParserGeneratedFlags = DisallowInContext | YieldContext | DecoratorContext | ThisNodeHasError | AwaitContext, // Exclude these flags when parsing a Type - TypeExcludesFlags = Yield | Await, + TypeExcludesFlags = YieldContext | AwaitContext, } export const enum JsxFlags {