From 726de4b40232083433220ee6fed8643453528034 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 24 Nov 2014 21:04:46 -0800 Subject: [PATCH] Add the context mutation operators. --- src/compiler/parser.ts | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 60ffa5d4b3c..a7dff2ea809 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -919,6 +919,16 @@ module ts { updateContextFlags(); } + function setYieldContext(val: boolean) { + yieldContext = val; + updateContextFlags(); + } + + function setGeneratorParameterContext(val: boolean) { + generatorParameterContext = val; + updateContextFlags(); + } + function allowInAnd(func: () => T): T { if (disallowInContext) { setDisallowInContext(false); @@ -943,6 +953,54 @@ module ts { return result; } + function enterYieldContextAnd(func: () => T): T { + if (yieldContext) { + // no need to do anything special if we're already in the [Yield] context. + return func(); + } + + setYieldContext(true); + var result = func(); + setYieldContext(false); + return result; + } + + function exitYieldContextAnd(func: () => T): T { + if (yieldContext) { + setYieldContext(false); + var result = func(); + setYieldContext(true); + return result; + } + + // no need to do anything special if we're not in the [Yield] context. + return func(); + } + + function enterGeneratorParameterContextAnd(func: () => T): T { + if (generatorParameterContext) { + // no need to do anything special if we're already in the [GeneratorParameter] context + return func(); + } + + setGeneratorParameterContext(true); + var result = func(); + setGeneratorParameterContext(false); + return result; + } + + function exitGeneratorParameterContextAnd(func: () => T): T { + if (generatorParameterContext) { + setGeneratorParameterContext(false); + var result = func(); + setGeneratorParameterContext(true); + return result; + } + + // no need to do anything special if we're not in the [GeneratorParameter] context + return func(); + } + function getLineStarts(): number[] { return lineStarts || (lineStarts = computeLineStarts(sourceText)); }