From bcffaacf826774cdbd4113b8f2c8c4e27cbb813c Mon Sep 17 00:00:00 2001 From: Yuri Paliy Date: Sun, 28 Nov 2021 16:45:21 +0200 Subject: [PATCH] bugfix: Gaurd for setting None tokens. --- luaparser/astnodes.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/luaparser/astnodes.py b/luaparser/astnodes.py index e726e79..6f1f3f6 100644 --- a/luaparser/astnodes.py +++ b/luaparser/astnodes.py @@ -80,9 +80,10 @@ def first_token(self) -> Optional[CommonToken]: return self._first_token @first_token.setter - def first_token(self, val: CommonToken): - self._first_token = val.clone() - self._first_token.source = CommonToken.EMPTY_SOURCE + def first_token(self, val: Optional[CommonToken]): + if val is not None: + self._first_token = val.clone() + self._first_token.source = CommonToken.EMPTY_SOURCE @property def last_token(self) -> Optional[CommonToken]: @@ -94,9 +95,10 @@ def last_token(self) -> Optional[CommonToken]: return self._last_token @last_token.setter - def last_token(self, val: CommonToken): - self._last_token = val.clone() - self._last_token.source = CommonToken.EMPTY_SOURCE + def last_token(self, val: Optional[CommonToken]): + if val is not None: + self._last_token = val.clone() + self._last_token.source = CommonToken.EMPTY_SOURCE @property def start_char(self) -> Optional[int]: