Browse Source

Update pyjsparser 2.4.5 (39b468e) → 2.7.1 (5465d03).

pull/1200/head
JackDandy 6 years ago
parent
commit
07a5624118
  1. 1
      CHANGES.md
  2. 3
      lib/pyjsparser/__init__.py
  3. 1364
      lib/pyjsparser/parser.py
  4. 460
      lib/pyjsparser/pyjsparserdata.py
  5. 152
      lib/pyjsparser/std_nodes.py

1
CHANGES.md

@ -13,6 +13,7 @@
* Update IMDb-pie 5.6.3 (4220e83) to 5.6.4 (f695e87) * Update IMDb-pie 5.6.3 (4220e83) to 5.6.4 (f695e87)
* Update MsgPack 0.6.0 (197e307) to 0.6.1 (737f08a) * Update MsgPack 0.6.0 (197e307) to 0.6.1 (737f08a)
* Update profilehooks module 1.10.1 (fdbf19d) to 1.11.0 (e17f378) * Update profilehooks module 1.10.1 (fdbf19d) to 1.11.0 (e17f378)
* Update pyjsparser 2.4.5 (39b468e) to 2.7.1 (5465d03)
* Update PySocks 1.6.8 (b687a34) to 1.7.0 (91dcdf0) * Update PySocks 1.6.8 (b687a34) to 1.7.0 (91dcdf0)
* Update Requests library 2.21.0 (e52932c) to 2.22.0 (aeda65b) * Update Requests library 2.21.0 (e52932c) to 2.22.0 (aeda65b)
* Update scandir 1.9.0 (9ab3d1f) to 1.10.0 (982e6ba) * Update scandir 1.9.0 (9ab3d1f) to 1.10.0 (982e6ba)

3
lib/pyjsparser/__init__.py

@ -1,4 +1,5 @@
__all__ = ['PyJsParser', 'parse', 'JsSyntaxError'] __all__ = ['PyJsParser', 'parse', 'JsSyntaxError', 'pyjsparserdata']
__author__ = 'Piotr Dabkowski' __author__ = 'Piotr Dabkowski'
__version__ = '2.2.0' __version__ = '2.2.0'
from .parser import PyJsParser, parse, JsSyntaxError from .parser import PyJsParser, parse, JsSyntaxError
from . import pyjsparserdata

1364
lib/pyjsparser/parser.py

File diff suppressed because it is too large

460
lib/pyjsparser/pyjsparserdata.py

@ -23,7 +23,7 @@ import sys
import unicodedata import unicodedata
from collections import defaultdict from collections import defaultdict
PY3 = sys.version_info >= (3,0) PY3 = sys.version_info >= (3, 0)
if PY3: if PY3:
unichr = chr unichr = chr
@ -41,169 +41,244 @@ token = {
'StringLiteral': 8, 'StringLiteral': 8,
'RegularExpression': 9, 'RegularExpression': 9,
'Template': 10 'Template': 10
} }
TokenName = dict((v, k) for k, v in token.items())
TokenName = dict((v,k) for k,v in token.items())
FnExprTokens = [
FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new', '(',
'return', 'case', 'delete', 'throw', 'void', '{',
'[',
'in',
'typeof',
'instanceof',
'new',
'return',
'case',
'delete',
'throw',
'void',
# assignment operators # assignment operators
'=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=', '=',
'&=', '|=', '^=', ',', '+=',
'-=',
'*=',
'/=',
'%=',
'<<=',
'>>=',
'>>>=',
'&=',
'|=',
'^=',
',',
# binary/unary operators # binary/unary operators
'+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&', '+',
'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=', '-',
'<=', '<', '>', '!=', '!=='] '*',
'/',
syntax= set(('AssignmentExpression', '%',
'AssignmentPattern', '++',
'ArrayExpression', '--',
'ArrayPattern', '<<',
'ArrowFunctionExpression', '>>',
'BlockStatement', '>>>',
'BinaryExpression', '&',
'BreakStatement', '|',
'CallExpression', '^',
'CatchClause', '!',
'ClassBody', '~',
'ClassDeclaration', '&&',
'ClassExpression', '||',
'ConditionalExpression', '?',
'ContinueStatement', ':',
'DoWhileStatement', '===',
'DebuggerStatement', '==',
'EmptyStatement', '>=',
'ExportAllDeclaration', '<=',
'ExportDefaultDeclaration', '<',
'ExportNamedDeclaration', '>',
'ExportSpecifier', '!=',
'ExpressionStatement', '!=='
'ForStatement', ]
'ForInStatement',
'FunctionDeclaration', syntax = set(
'FunctionExpression', ('AssignmentExpression', 'AssignmentPattern', 'ArrayExpression',
'Identifier', 'ArrayPattern', 'ArrowFunctionExpression', 'BlockStatement',
'IfStatement', 'BinaryExpression', 'BreakStatement', 'CallExpression', 'CatchClause',
'ImportDeclaration', 'ClassBody', 'ClassDeclaration', 'ClassExpression',
'ImportDefaultSpecifier', 'ConditionalExpression', 'ContinueStatement', 'DoWhileStatement',
'ImportNamespaceSpecifier', 'DebuggerStatement', 'EmptyStatement', 'ExportAllDeclaration',
'ImportSpecifier', 'ExportDefaultDeclaration', 'ExportNamedDeclaration', 'ExportSpecifier',
'Literal', 'ExpressionStatement', 'ForStatement', 'ForInStatement',
'LabeledStatement', 'FunctionDeclaration', 'FunctionExpression', 'Identifier', 'IfStatement',
'LogicalExpression', 'ImportDeclaration', 'ImportDefaultSpecifier', 'ImportNamespaceSpecifier',
'MemberExpression', 'ImportSpecifier', 'Literal', 'LabeledStatement', 'LogicalExpression',
'MethodDefinition', 'MemberExpression', 'MethodDefinition', 'NewExpression',
'NewExpression', 'ObjectExpression', 'ObjectPattern', 'Program', 'Property', 'RestElement',
'ObjectExpression', 'ReturnStatement', 'SequenceExpression', 'SpreadElement', 'Super',
'ObjectPattern', 'SwitchCase', 'SwitchStatement', 'TaggedTemplateExpression',
'Program', 'TemplateElement', 'TemplateLiteral', 'ThisExpression', 'ThrowStatement',
'Property', 'TryStatement', 'UnaryExpression', 'UpdateExpression',
'RestElement', 'VariableDeclaration', 'VariableDeclarator', 'WhileStatement',
'ReturnStatement',
'SequenceExpression',
'SpreadElement',
'Super',
'SwitchCase',
'SwitchStatement',
'TaggedTemplateExpression',
'TemplateElement',
'TemplateLiteral',
'ThisExpression',
'ThrowStatement',
'TryStatement',
'UnaryExpression',
'UpdateExpression',
'VariableDeclaration',
'VariableDeclarator',
'WhileStatement',
'WithStatement')) 'WithStatement'))
supported_syntax = set(
('AssignmentExpression', 'ArrayExpression', 'BlockStatement',
'BinaryExpression', 'BreakStatement', 'CallExpression', 'CatchClause',
'ConditionalExpression', 'ContinueStatement', 'DoWhileStatement',
'DebuggerStatement', 'EmptyStatement', 'ExpressionStatement',
'ForStatement', 'ForInStatement', 'FunctionDeclaration',
'FunctionExpression', 'Identifier', 'IfStatement', 'Literal',
'LabeledStatement', 'LogicalExpression', 'MemberExpression',
'MethodDefinition', 'NewExpression', 'ObjectExpression', 'Program',
'Property', 'ReturnStatement', 'SequenceExpression', 'SwitchCase',
'SwitchStatement', 'ThisExpression', 'ThrowStatement', 'TryStatement',
'UnaryExpression', 'UpdateExpression', 'VariableDeclaration',
'VariableDeclarator', 'WhileStatement', 'WithStatement'))
# Error messages should be identical to V8. # Error messages should be identical to V8.
messages = { messages = {
'UnexpectedToken': 'Unexpected token %s', 'UnexpectedToken':
'UnexpectedNumber': 'Unexpected number', 'Unexpected token %s',
'UnexpectedString': 'Unexpected string', 'UnexpectedNumber':
'UnexpectedIdentifier': 'Unexpected identifier', 'Unexpected number',
'UnexpectedReserved': 'Unexpected reserved word', 'UnexpectedString':
'UnexpectedTemplate': 'Unexpected quasi %s', 'Unexpected string',
'UnexpectedEOS': 'Unexpected end of input', 'UnexpectedIdentifier':
'NewlineAfterThrow': 'Illegal newline after throw', 'Unexpected identifier',
'InvalidRegExp': 'Invalid regular expression', 'UnexpectedReserved':
'UnterminatedRegExp': 'Invalid regular expression: missing /', 'Unexpected reserved word',
'InvalidLHSInAssignment': 'Invalid left-hand side in assignment', 'UnexpectedTemplate':
'InvalidLHSInForIn': 'Invalid left-hand side in for-in', 'Unexpected quasi %s',
'MultipleDefaultsInSwitch': 'More than one default clause in switch statement', 'UnexpectedEOS':
'NoCatchOrFinally': 'Missing catch or finally after try', 'Unexpected end of input',
'UnknownLabel': 'Undefined label \'%s\'', 'NewlineAfterThrow':
'Redeclaration': '%s \'%s\' has already been declared', 'Illegal newline after throw',
'IllegalContinue': 'Illegal continue statement', 'InvalidRegExp':
'IllegalBreak': 'Illegal break statement', 'Invalid regular expression',
'IllegalReturn': 'Illegal return statement', 'UnterminatedRegExp':
'StrictModeWith': 'Strict mode code may not include a with statement', 'Invalid regular expression: missing /',
'StrictCatchVariable': 'Catch variable may not be eval or arguments in strict mode', 'InvalidLHSInAssignment':
'StrictVarName': 'Variable name may not be eval or arguments in strict mode', 'Invalid left-hand side in assignment',
'StrictParamName': 'Parameter name eval or arguments is not allowed in strict mode', 'InvalidLHSInForIn':
'StrictParamDupe': 'Strict mode function may not have duplicate parameter names', 'Invalid left-hand side in for-in',
'StrictFunctionName': 'Function name may not be eval or arguments in strict mode', 'MultipleDefaultsInSwitch':
'StrictOctalLiteral': 'Octal literals are not allowed in strict mode.', 'More than one default clause in switch statement',
'StrictDelete': 'Delete of an unqualified identifier in strict mode.', 'NoCatchOrFinally':
'StrictLHSAssignment': 'Assignment to eval or arguments is not allowed in strict mode', 'Missing catch or finally after try',
'StrictLHSPostfix': 'Postfix increment/decrement may not have eval or arguments operand in strict mode', 'UnknownLabel':
'StrictLHSPrefix': 'Prefix increment/decrement may not have eval or arguments operand in strict mode', 'Undefined label \'%s\'',
'StrictReservedWord': 'Use of future reserved word in strict mode', 'Redeclaration':
'TemplateOctalLiteral': 'Octal literals are not allowed in template strings.', '%s \'%s\' has already been declared',
'ParameterAfterRestParameter': 'Rest parameter must be last formal parameter', 'IllegalContinue':
'DefaultRestParameter': 'Unexpected token =', 'Illegal continue statement',
'ObjectPatternAsRestParameter': 'Unexpected token {', 'IllegalBreak':
'DuplicateProtoProperty': 'Duplicate __proto__ fields are not allowed in object literals', 'Illegal break statement',
'ConstructorSpecialMethod': 'Class constructor may not be an accessor', 'IllegalReturn':
'DuplicateConstructor': 'A class may only have one constructor', 'Illegal return statement',
'StaticPrototype': 'Classes may not have static property named prototype', 'StrictModeWith':
'MissingFromClause': 'Unexpected token', 'Strict mode code may not include a with statement',
'NoAsAfterImportNamespace': 'Unexpected token', 'StrictCatchVariable':
'InvalidModuleSpecifier': 'Unexpected token', 'Catch variable may not be eval or arguments in strict mode',
'IllegalImportDeclaration': 'Unexpected token', 'StrictVarName':
'IllegalExportDeclaration': 'Unexpected token'} 'Variable name may not be eval or arguments in strict mode',
'StrictParamName':
PRECEDENCE = {'||':1, 'Parameter name eval or arguments is not allowed in strict mode',
'&&':2, 'StrictParamDupe':
'|':3, 'Strict mode function may not have duplicate parameter names',
'^':4, 'StrictFunctionName':
'&':5, 'Function name may not be eval or arguments in strict mode',
'==':6, 'StrictOctalLiteral':
'!=':6, 'Octal literals are not allowed in strict mode.',
'===':6, 'StrictDelete':
'!==':6, 'Delete of an unqualified identifier in strict mode.',
'<':7, 'StrictLHSAssignment':
'>':7, 'Assignment to eval or arguments is not allowed in strict mode',
'<=':7, 'StrictLHSPostfix':
'>=':7, 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
'instanceof':7, 'StrictLHSPrefix':
'in':7, 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
'<<':8, 'StrictReservedWord':
'>>':8, 'Use of future reserved word in strict mode',
'>>>':8, 'TemplateOctalLiteral':
'+':9, 'Octal literals are not allowed in template strings.',
'-':9, 'ParameterAfterRestParameter':
'*':11, 'Rest parameter must be last formal parameter',
'/':11, 'DefaultRestParameter':
'%':11} 'Unexpected token =',
'ObjectPatternAsRestParameter':
class Token: pass 'Unexpected token {',
class Syntax: pass 'DuplicateProtoProperty':
class Messages: pass 'Duplicate __proto__ fields are not allowed in object literals',
'ConstructorSpecialMethod':
'Class constructor may not be an accessor',
'DuplicateConstructor':
'A class may only have one constructor',
'StaticPrototype':
'Classes may not have static property named prototype',
'MissingFromClause':
'Unexpected token',
'NoAsAfterImportNamespace':
'Unexpected token',
'InvalidModuleSpecifier':
'Unexpected token',
'IllegalImportDeclaration':
'Unexpected token',
'IllegalExportDeclaration':
'Unexpected token'
}
PRECEDENCE = {
'||': 1,
'&&': 2,
'|': 3,
'^': 4,
'&': 5,
'==': 6,
'!=': 6,
'===': 6,
'!==': 6,
'<': 7,
'>': 7,
'<=': 7,
'>=': 7,
'instanceof': 7,
'in': 7,
'<<': 8,
'>>': 8,
'>>>': 8,
'+': 9,
'-': 9,
'*': 11,
'/': 11,
'%': 11
}
class Token:
pass
class Syntax:
pass
class Messages:
pass
class PlaceHolders: class PlaceHolders:
ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder' ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder'
for k,v in token.items():
for k, v in token.items():
setattr(Token, k, v) setattr(Token, k, v)
for e in syntax: for e in syntax:
setattr(Syntax, e, e) setattr(Syntax, e, e)
for k,v in messages.items(): for k, v in messages.items():
setattr(Messages, k, v) setattr(Messages, k, v)
#http://stackoverflow.com/questions/14245893/efficiently-list-all-characters-in-a-given-unicode-category #http://stackoverflow.com/questions/14245893/efficiently-list-all-characters-in-a-given-unicode-category
@ -220,72 +295,99 @@ CR = u'\u000D'
LS = u'\u2028' LS = u'\u2028'
PS = u'\u2029' PS = u'\u2029'
U_CATEGORIES = defaultdict(list)
for c in map(unichr, range(sys.maxunicode + 1)): LETTER_CATEGORIES = set(['Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl'])
U_CATEGORIES[unicodedata.category(c)].append(c)
UNICODE_LETTER = set(U_CATEGORIES['Lu']+U_CATEGORIES['Ll']+ COMBINING_MARK_CATEGORIES = set(['Mn', 'Mc'])
U_CATEGORIES['Lt']+U_CATEGORIES['Lm']+ DIGIT_CATEGORIES = set(['Nd'])
U_CATEGORIES['Lo']+U_CATEGORIES['Nl']) CONNECTOR_PUNCTUATION_CATEGORIES = set(['Pc'])
UNICODE_COMBINING_MARK = set(U_CATEGORIES['Mn']+U_CATEGORIES['Mc']) IDENTIFIER_START_CATEGORIES = LETTER_CATEGORIES.copy() # and some fucking unicode escape sequence
UNICODE_DIGIT = set(U_CATEGORIES['Nd']) IDENTIFIER_PART_CATEGORIES = IDENTIFIER_START_CATEGORIES.union(COMBINING_MARK_CATEGORIES).union(DIGIT_CATEGORIES)\
UNICODE_CONNECTOR_PUNCTUATION = set(U_CATEGORIES['Pc']) .union(CONNECTOR_PUNCTUATION_CATEGORIES)
IDENTIFIER_START = UNICODE_LETTER.union(set(('$','_', '\\'))) # and some fucking unicode escape sequence
IDENTIFIER_PART = IDENTIFIER_START.union(UNICODE_COMBINING_MARK).union(UNICODE_DIGIT)\ EXTRA_IDENTIFIER_START_CHARS = set(('$','_', '\\'))
.union(UNICODE_CONNECTOR_PUNCTUATION).union(set((ZWJ, ZWNJ))) EXTRA_IDENTIFIER_PART_CHARS = EXTRA_IDENTIFIER_START_CHARS.union(set((ZWJ, ZWNJ)))
WHITE_SPACE = set((0x20, 0x09, 0x0B, 0x0C, 0xA0, 0x1680, WHITE_SPACE = set((0x20, 0x09, 0x0B, 0x0C, 0xA0, 0x1680, 0x180E, 0x2000,
0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007,
0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF))
0x2009, 0x200A, 0x202F, 0x205F, 0x3000,
0xFEFF))
LINE_TERMINATORS = set((0x0A, 0x0D, 0x2028, 0x2029)) LINE_TERMINATORS = set((0x0A, 0x0D, 0x2028, 0x2029))
def isIdentifierStart(ch): def isIdentifierStart(ch):
return (ch if isinstance(ch, unicode) else unichr(ch)) in IDENTIFIER_START uch = (ch if isinstance(ch, unicode) else unichr(ch))
return unicodedata.category(uch) in IDENTIFIER_START_CATEGORIES or uch in EXTRA_IDENTIFIER_START_CHARS
def isIdentifierPart(ch): def isIdentifierPart(ch):
return (ch if isinstance(ch, unicode) else unichr(ch)) in IDENTIFIER_PART uch = (ch if isinstance(ch, unicode) else unichr(ch))
return unicodedata.category(uch) in IDENTIFIER_PART_CATEGORIES or uch in EXTRA_IDENTIFIER_PART_CHARS
def isValidIdentifier(name):
if not name or isKeyword(name):
return False
check = isIdentifierStart
for e in name:
if not check(e):
return False
check = isIdentifierPart
return True
def isWhiteSpace(ch): def isWhiteSpace(ch):
return (ord(ch) if isinstance(ch, unicode) else ch) in WHITE_SPACE return (ord(ch) if isinstance(ch, unicode) else ch) in WHITE_SPACE
def isLineTerminator(ch): def isLineTerminator(ch):
return (ord(ch) if isinstance(ch, unicode) else ch) in LINE_TERMINATORS return (ord(ch) if isinstance(ch, unicode) else ch) in LINE_TERMINATORS
OCTAL = set(('0', '1', '2', '3', '4', '5', '6', '7')) OCTAL = set(('0', '1', '2', '3', '4', '5', '6', '7'))
DEC = set(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) DEC = set(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
HEX = set('0123456789abcdefABCDEF') HEX = set('0123456789abcdefABCDEF')
HEX_CONV = dict(('0123456789abcdef'[n],n) for n in xrange(16)) HEX_CONV = dict(('0123456789abcdef' [n], n) for n in xrange(16))
for i,e in enumerate('ABCDEF', 10): for i, e in enumerate('ABCDEF', 10):
HEX_CONV[e] = i HEX_CONV[e] = i
def isDecimalDigit(ch): def isDecimalDigit(ch):
return (ch if isinstance(ch, unicode) else unichr(ch)) in DEC return (ch if isinstance(ch, unicode) else unichr(ch)) in DEC
def isHexDigit(ch): def isHexDigit(ch):
return (ch if isinstance(ch, unicode) else unichr(ch)) in HEX return (ch if isinstance(ch, unicode) else unichr(ch)) in HEX
def isOctalDigit(ch): def isOctalDigit(ch):
return (ch if isinstance(ch, unicode) else unichr(ch)) in OCTAL return (ch if isinstance(ch, unicode) else unichr(ch)) in OCTAL
def isFutureReservedWord(w): def isFutureReservedWord(w):
return w in ('enum', 'export', 'import', 'super') return w in ('enum', 'export', 'import', 'super')
RESERVED_WORD = set(('implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'yield', 'let')) RESERVED_WORD = set(('implements', 'interface', 'package', 'private',
'protected', 'public', 'static', 'yield', 'let'))
def isStrictModeReservedWord(w): def isStrictModeReservedWord(w):
return w in RESERVED_WORD return w in RESERVED_WORD
def isRestrictedWord(w): def isRestrictedWord(w):
return w in ('eval', 'arguments') return w in ('eval', 'arguments')
KEYWORDS = set(('if', 'in', 'do', 'var', 'for', 'new', 'try', 'let', 'this', 'else', 'case', KEYWORDS = set(
'void', 'with', 'enum', 'while', 'break', 'catch', 'throw', 'const', 'yield', ('if', 'in', 'do', 'var', 'for', 'new', 'try', 'let', 'this', 'else',
'class', 'super', 'return', 'typeof', 'delete', 'switch', 'export', 'import', 'case', 'void', 'with', 'enum', 'while', 'break', 'catch', 'throw',
'default', 'finally', 'extends', 'function', 'continue', 'debugger', 'instanceof', 'pyimport')) 'const', 'yield', 'class', 'super', 'return', 'typeof', 'delete',
'switch', 'export', 'import', 'default', 'finally', 'extends', 'function',
'continue', 'debugger', 'instanceof', 'pyimport'))
def isKeyword(w): def isKeyword(w):
# 'const' is specialized as Keyword in V8. # 'const' is specialized as Keyword in V8.
# 'yield' and 'let' are for compatibility with SpiderMonkey and ES.next. # 'yield' and 'let' are for compatibility with SpiderMonkey and ES.next.
@ -293,9 +395,11 @@ def isKeyword(w):
return w in KEYWORDS return w in KEYWORDS
class JsSyntaxError(Exception): pass class JsSyntaxError(Exception):
pass
if __name__=='__main__': if __name__ == '__main__':
assert isLineTerminator('\n') assert isLineTerminator('\n')
assert isLineTerminator(0x0A) assert isLineTerminator(0x0A)
assert isIdentifierStart('$') assert isIdentifierStart('$')

152
lib/pyjsparser/std_nodes.py

@ -1,6 +1,16 @@
from .pyjsparserdata import * from .pyjsparserdata import *
class Ecma51NotSupported(Exception):
def __init__(self, feature):
super(Ecma51NotSupported,
self).__init__("%s is not supported by ECMA 5.1." % feature)
self.feature = feature
def get_feature(self):
return self.feature
class BaseNode: class BaseNode:
def finish(self): def finish(self):
pass pass
@ -17,17 +27,6 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishArrowFunctionExpression(self, params, defaults, body, expression):
self.type = Syntax.ArrowFunctionExpression
self.id = None
self.params = params
self.defaults = defaults
self.body = body
self.generator = False
self.expression = expression
self.finish()
return self
def finishAssignmentExpression(self, operator, left, right): def finishAssignmentExpression(self, operator, left, right):
self.type = Syntax.AssignmentExpression self.type = Syntax.AssignmentExpression
self.operator = operator self.operator = operator
@ -44,7 +43,8 @@ class BaseNode:
return self return self
def finishBinaryExpression(self, operator, left, right): def finishBinaryExpression(self, operator, left, right):
self.type = Syntax.LogicalExpression if (operator == '||' or operator == '&&') else Syntax.BinaryExpression self.type = Syntax.LogicalExpression if (
operator == '||' or operator == '&&') else Syntax.BinaryExpression
self.operator = operator self.operator = operator
self.left = left self.left = left
self.right = right self.right = right
@ -77,28 +77,6 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishClassBody(self, body):
self.type = Syntax.ClassBody
self.body = body
self.finish()
return self
def finishClassDeclaration(self, id, superClass, body):
self.type = Syntax.ClassDeclaration
self.id = id
self.superClass = superClass
self.body = body
self.finish()
return self
def finishClassExpression(self, id, superClass, body):
self.type = Syntax.ClassExpression
self.id = id
self.superClass = superClass
self.body = body
self.finish()
return self
def finishConditionalExpression(self, test, consequent, alternate): def finishConditionalExpression(self, test, consequent, alternate):
self.type = Syntax.ConditionalExpression self.type = Syntax.ConditionalExpression
self.test = test self.test = test
@ -200,7 +178,7 @@ class BaseNode:
def finishLiteral(self, token): def finishLiteral(self, token):
self.type = Syntax.Literal self.type = Syntax.Literal
self.value = token['value'] self.value = token['value']
self.raw = None # todo fix it? self.raw = token['raw']
if token.get('regex'): if token.get('regex'):
self.regex = token['regex'] self.regex = token['regex']
self.finish() self.finish()
@ -264,12 +242,6 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishRestElement(self, argument):
self.type = Syntax.RestElement
self.argument = argument
self.finish()
return self
def finishReturnStatement(self, argument): def finishReturnStatement(self, argument):
self.type = Syntax.ReturnStatement self.type = Syntax.ReturnStatement
self.argument = argument self.argument = argument
@ -282,12 +254,6 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishSpreadElement(self, argument):
self.type = Syntax.SpreadElement
self.argument = argument
self.finish()
return self
def finishSwitchCase(self, test, consequent): def finishSwitchCase(self, test, consequent):
self.type = Syntax.SwitchCase self.type = Syntax.SwitchCase
self.test = test self.test = test
@ -295,11 +261,6 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishSuper(self, ):
self.type = Syntax.Super
self.finish()
return self
def finishSwitchStatement(self, discriminant, cases): def finishSwitchStatement(self, discriminant, cases):
self.type = Syntax.SwitchStatement self.type = Syntax.SwitchStatement
self.discriminant = discriminant self.discriminant = discriminant
@ -307,27 +268,6 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishTaggedTemplateExpression(self, tag, quasi):
self.type = Syntax.TaggedTemplateExpression
self.tag = tag
self.quasi = quasi
self.finish()
return self
def finishTemplateElement(self, value, tail):
self.type = Syntax.TemplateElement
self.value = value
self.tail = tail
self.finish()
return self
def finishTemplateLiteral(self, quasis, expressions):
self.type = Syntax.TemplateLiteral
self.quasis = quasis
self.expressions = expressions
self.finish()
return self
def finishThisExpression(self, ): def finishThisExpression(self, ):
self.type = Syntax.ThisExpression self.type = Syntax.ThisExpression
self.finish() self.finish()
@ -350,7 +290,8 @@ class BaseNode:
return self return self
def finishUnaryExpression(self, operator, argument): def finishUnaryExpression(self, operator, argument):
self.type = Syntax.UpdateExpression if (operator == '++' or operator == '--') else Syntax.UnaryExpression self.type = Syntax.UpdateExpression if (
operator == '++' or operator == '--') else Syntax.UnaryExpression
self.operator = operator self.operator = operator
self.argument = argument self.argument = argument
self.prefix = True self.prefix = True
@ -392,58 +333,14 @@ class BaseNode:
self.finish() self.finish()
return self return self
def finishExportSpecifier(self, local, exported): def __getattr__(self, item):
self.type = Syntax.ExportSpecifier if item in self.__dict__:
self.exported = exported or local return self.__dict__[item]
self.local = local if item.startswith('finish'):
self.finish() feature = item[6:]
return self raise Ecma51NotSupported(feature)
else:
def finishImportDefaultSpecifier(self, local): raise AttributeError(item)
self.type = Syntax.ImportDefaultSpecifier
self.local = local
self.finish()
return self
def finishImportNamespaceSpecifier(self, local):
self.type = Syntax.ImportNamespaceSpecifier
self.local = local
self.finish()
return self
def finishExportNamedDeclaration(self, declaration, specifiers, src):
self.type = Syntax.ExportNamedDeclaration
self.declaration = declaration
self.specifiers = specifiers
self.source = src
self.finish()
return self
def finishExportDefaultDeclaration(self, declaration):
self.type = Syntax.ExportDefaultDeclaration
self.declaration = declaration
self.finish()
return self
def finishExportAllDeclaration(self, src):
self.type = Syntax.ExportAllDeclaration
self.source = src
self.finish()
return self
def finishImportSpecifier(self, local, imported):
self.type = Syntax.ImportSpecifier
self.local = local or imported
self.imported = imported
self.finish()
return self
def finishImportDeclaration(self, specifiers, src):
self.type = Syntax.ImportDeclaration
self.specifiers = specifiers
self.source = src
self.finish()
return self
def __getitem__(self, item): def __getitem__(self, item):
return getattr(self, item) return getattr(self, item)
@ -451,6 +348,9 @@ class BaseNode:
def __setitem__(self, key, value): def __setitem__(self, key, value):
setattr(self, key, value) setattr(self, key, value)
def to_dict(self):
return node_to_dict(self)
class Node(BaseNode): class Node(BaseNode):
pass pass

Loading…
Cancel
Save