Fix ghost nodes appearing in AST

Never _ever_ underestimate the power of testing. The previous state of the code was OK iff the only file needs to be parsed.
master
Yury Kurlykov 2020-06-28 15:34:15 +10:00
parent 5be6f96098
commit 9f0646c6f0
Signed by: t1meshift
GPG Key ID: B133F3167ABF94D8
1 changed files with 8 additions and 2 deletions

View File

@ -586,7 +586,10 @@ class StatementListener(JSBaseListener):
class SourceElementListener(JSBaseListener):
"""The proxy between Program and Statement."""
_elems: List[nodes.Statement] = []
_elems: List[nodes.Statement]
def __init__(self):
self._elems = []
@property
def source_elements(self) -> List[nodes.Statement]:
@ -605,9 +608,12 @@ class SourceElementListener(JSBaseListener):
class ASTListener(JSBaseListener):
"""AST listener."""
_program_node: Optional[nodes.Program] = None
_program_node: Optional[nodes.Program]
_source_type: nodes.SourceTypeLiteral
def __init__(self):
self._program_node = None
@property
def program_node(self) -> nodes.Program:
"""The `Program` AST node generated after parse tree walking."""