Skip to content

Commit

Permalink
Changes variables async and await to isAsync and awaitAllowed to conf…
Browse files Browse the repository at this point in the history
…orm with python 3.7

They have become reserved keywords
  • Loading branch information
diogovincenzi authored and najamelan committed Aug 24, 2018
1 parent a4ce2ad commit eeb8ad0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
16 changes: 8 additions & 8 deletions esprima/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ArrowFunctionExpression(Node):
def __init__(self, params, body, expression):
self.type = Syntax.ArrowFunctionExpression
self.generator = False
self.async = False
self.isAsync = False
self.params = params
self.body = body
self.expression = expression
Expand All @@ -83,7 +83,7 @@ class AsyncArrowFunctionExpression(Node):
def __init__(self, params, body, expression):
self.type = Syntax.ArrowFunctionExpression
self.generator = False
self.async = True
self.isAsync = True
self.params = params
self.body = body
self.expression = expression
Expand All @@ -94,7 +94,7 @@ def __init__(self, id, params, body):
self.type = Syntax.FunctionDeclaration
self.generator = False
self.expression = False
self.async = True
self.isAsync = True
self.id = id
self.params = params
self.body = body
Expand All @@ -105,7 +105,7 @@ def __init__(self, id, params, body):
self.type = Syntax.FunctionExpression
self.generator = False
self.expression = False
self.async = True
self.isAsync = True
self.id = id
self.params = params
self.body = body
Expand Down Expand Up @@ -288,7 +288,7 @@ class FunctionDeclaration(Node):
def __init__(self, id, params, body, generator):
self.type = Syntax.FunctionDeclaration
self.expression = False
self.async = False
self.isAsync = False
self.id = id
self.params = params
self.body = body
Expand All @@ -299,7 +299,7 @@ class FunctionExpression(Node):
def __init__(self, id, params, body, generator):
self.type = Syntax.FunctionExpression
self.expression = False
self.async = False
self.isAsync = False
self.id = id
self.params = params
self.body = body
Expand Down Expand Up @@ -598,14 +598,14 @@ class ArrowParameterPlaceHolder(Node):
def __init__(self, params):
self.type = Syntax.ArrowParameterPlaceHolder
self.params = params
self.async = False
self.isAsync = False


class AsyncArrowParameterPlaceHolder(Node):
def __init__(self, params):
self.type = Syntax.ArrowParameterPlaceHolder
self.params = params
self.async = True
self.isAsync = True


class BlockComment(Node):
Expand Down
40 changes: 20 additions & 20 deletions esprima/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def __init__(self, range=False, loc=False, source=None, tokens=False, comment=Fa


class Context(object):
def __init__(self, isModule=False, await=False, allowIn=True, allowStrictDirective=True, allowYield=True, firstCoverInitializedNameError=None, isAssignmentTarget=False, isBindingElement=False, inFunctionBody=False, inIteration=False, inSwitch=False, labelSet=None, strict=False):
def __init__(self, isModule=False, allowAwait=False, allowIn=True, allowStrictDirective=True, allowYield=True, firstCoverInitializedNameError=None, isAssignmentTarget=False, isBindingElement=False, inFunctionBody=False, inIteration=False, inSwitch=False, labelSet=None, strict=False):
self.isModule = isModule
self.await = await
self.allowAwait = allowAwait
self.allowIn = allowIn
self.allowStrictDirective = allowStrictDirective
self.allowYield = allowYield
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self, code, options={}, delegate=None):

self.context = Context(
isModule=False,
await=False,
allowAwait=False,
allowIn=True,
allowStrictDirective=True,
allowYield=True,
Expand Down Expand Up @@ -544,7 +544,7 @@ def parsePrimaryExpression(self):

typ = self.lookahead.type
if typ is Token.Identifier:
if (self.context.isModule or self.context.await) and self.lookahead.value == 'await':
if (self.context.isModule or self.context.allowAwait) and self.lookahead.value == 'await':
self.tolerateUnexpectedToken(self.lookahead)
expr = self.parseFunctionExpression() if self.matchAsyncFunction() else self.finalize(node, Node.Identifier(self.nextToken().value))

Expand Down Expand Up @@ -688,13 +688,13 @@ def parsePropertyMethodAsyncFunction(self):
node = self.createNode()

previousAllowYield = self.context.allowYield
previousAwait = self.context.await
previousAwait = self.context.allowAwait
self.context.allowYield = False
self.context.await = True
self.context.allowAwait = True
params = self.parseFormalParameters()
method = self.parsePropertyMethod(params)
self.context.allowYield = previousAllowYield
self.context.await = previousAwait
self.context.allowAwait = previousAwait

return self.finalize(node, Node.AsyncFunctionExpression(None, params.params, method))

Expand Down Expand Up @@ -1234,7 +1234,7 @@ def parseUnaryExpression(self):
self.tolerateError(Messages.StrictDelete)
self.context.isAssignmentTarget = False
self.context.isBindingElement = False
elif self.context.await and self.matchContextualKeyword('await'):
elif self.context.allowAwait and self.matchContextualKeyword('await'):
expr = self.parseAwaitExpression()
else:
expr = self.parseUpdateExpression()
Expand Down Expand Up @@ -1382,7 +1382,7 @@ def reinterpretAsCoverFormalsList(self, expr):
pass
elif typ is Syntax.ArrowParameterPlaceHolder:
params = expr.params
asyncArrow = expr.async
asyncArrow = expr.isAsync
else:
return None

Expand Down Expand Up @@ -1440,7 +1440,7 @@ def parseAssignmentExpression(self):
# https://tc39.github.io/ecma262/#sec-arrow-function-definitions
self.context.isAssignmentTarget = False
self.context.isBindingElement = False
isAsync = expr.async
isAsync = expr.isAsync
list = self.reinterpretAsCoverFormalsList(expr)

if list:
Expand All @@ -1453,9 +1453,9 @@ def parseAssignmentExpression(self):
self.context.allowStrictDirective = list.simple

previousAllowYield = self.context.allowYield
previousAwait = self.context.await
previousAwait = self.context.allowAwait
self.context.allowYield = True
self.context.await = isAsync
self.context.allowAwait = isAsync

node = self.startNode(startToken)
self.expect('=>')
Expand All @@ -1480,7 +1480,7 @@ def parseAssignmentExpression(self):
self.context.strict = previousStrict
self.context.allowStrictDirective = previousAllowStrictDirective
self.context.allowYield = previousAllowYield
self.context.await = previousAwait
self.context.allowAwait = previousAwait
else:
if self.matchAssign():
if not self.context.isAssignmentTarget:
Expand Down Expand Up @@ -1762,7 +1762,7 @@ def parseVariableIdentifier(self, kind=None):
else:
if self.context.strict or token.value != 'let' or kind != 'var':
self.throwUnexpectedToken(token)
elif (self.context.isModule or self.context.await) and token.type is Token.Identifier and token.value == 'await':
elif (self.context.isModule or self.context.allowAwait) and token.type is Token.Identifier and token.value == 'await':
self.tolerateUnexpectedToken(token)

return self.finalize(node, Node.Identifier(token.value))
Expand Down Expand Up @@ -2481,9 +2481,9 @@ def parseFunctionDeclaration(self, identifierIsOptional=False):
firstRestricted = token
message = Messages.StrictReservedWord

previousAllowAwait = self.context.await
previousAllowAwait = self.context.allowAwait
previousAllowYield = self.context.allowYield
self.context.await = isAsync
self.context.allowAwait = isAsync
self.context.allowYield = not isGenerator

formalParameters = self.parseFormalParameters(firstRestricted)
Expand All @@ -2504,7 +2504,7 @@ def parseFunctionDeclaration(self, identifierIsOptional=False):

self.context.strict = previousStrict
self.context.allowStrictDirective = previousAllowStrictDirective
self.context.await = previousAllowAwait
self.context.allowAwait = previousAllowAwait
self.context.allowYield = previousAllowYield

if isAsync:
Expand All @@ -2528,9 +2528,9 @@ def parseFunctionExpression(self):
id = None
firstRestricted = None

previousAllowAwait = self.context.await
previousAllowAwait = self.context.allowAwait
previousAllowYield = self.context.allowYield
self.context.await = isAsync
self.context.allowAwait = isAsync
self.context.allowYield = not isGenerator

if not self.match('('):
Expand Down Expand Up @@ -2564,7 +2564,7 @@ def parseFunctionExpression(self):
self.tolerateUnexpectedToken(stricted, message)
self.context.strict = previousStrict
self.context.allowStrictDirective = previousAllowStrictDirective
self.context.await = previousAllowAwait
self.context.allowAwait = previousAllowAwait
self.context.allowYield = previousAllowYield

if isAsync:
Expand Down

0 comments on commit eeb8ad0

Please sign in to comment.