Skip to content

Commit

Permalink
commonize
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyin committed Jan 31, 2025
1 parent 0e6e534 commit a8fadef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 10 additions & 0 deletions lizard_languages/jsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def generate_tokens(source_code, addition='', token_class=None):
for tok in js_tokenizer(token):
yield tok

def _expecting_func_opening_bracket(self, token):
if token == '<':
self.next(self._expecting_jsx)
return
super()._expecting_func_opening_bracket(token)

def _expecting_jsx(self, token):
if token == '>':
self.next(self._expecting_func_opening_bracket)


class JSXReader(JavaScriptReader, JSXMixin):
# pylint: disable=R0903
Expand Down
14 changes: 1 addition & 13 deletions lizard_languages/tsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,4 @@ def generate_tokens(source_code, addition='', token_class=None):

def __init__(self, context):
super(TSXReader, self).__init__(context)
self.parallel_states = [TSXStates(context)]


class TSXStates(TypeScriptStates):
def _expecting_func_opening_bracket(self, token):
if token == '<':
self.next(self._expecting_jsx)
return
super(TSXStates, self)._expecting_func_opening_bracket(token)

def _expecting_jsx(self, token):
if token == '>':
self.next(self._expecting_func_opening_bracket)
# No need for parallel states since JSX handling is in the mixin
6 changes: 5 additions & 1 deletion prompt-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ It looks like the XMLTagWithAttrTokenizer from @javascript.py belongs to @jsx.py

---------

@tsx.py @jsx.py should be doing very similar things. please refactor to remove the duplicate, inccluding conceptually duplicate code.
@tsx.py @jsx.py should be doing very similar things. please refactor to remove the duplicate, inccluding conceptually duplicate code.

---------

@tsx.py [email protected] should be doing very similar things. But TSX has a TSXStates as parallel_states, but JSX doesn't need one. Why? please commonize the solution.

0 comments on commit a8fadef

Please sign in to comment.