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]: