Skip to content

Commit

Permalink
Merge pull request #49 from arpds/fix-function-block-arguments-serial…
Browse files Browse the repository at this point in the history
…ization

Fixed Function AST serialization for nested functions with no arguments
  • Loading branch information
liZe authored Oct 4, 2022
2 parents ba187d1 + 15dd09f commit 5a36826
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
13 changes: 13 additions & 0 deletions tests/test_tinycss2.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ def test_serialize_declarations():
assert serialize(rules) == source


def test_serialize_rules_with_functions():
source = '''
foo#bar.baz {
background: url();
color: rgb(0, 0, 0);
width: calc(calc());
height: calc(calc(calc()));
}
'''
rules = parse_rule_list(source)
assert serialize(rules) == source


def test_backslash_delim():
source = '\\\nfoo'
tokens = parse_component_value_list(source)
Expand Down
17 changes: 8 additions & 9 deletions tinycss2/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,14 @@ def _serialize_to(self, write):
write(serialize_identifier(self.name))
write('(')
_serialize_to(self.arguments, write)
if self.arguments:
function = self
while isinstance(function, FunctionBlock):
eof_in_string = (
isinstance(function.arguments[-1], ParseError) and
function.arguments[-1].kind == 'eof-in-string')
if eof_in_string:
return
function = function.arguments[-1]
function = self
while isinstance(function, FunctionBlock) and function.arguments:
eof_in_string = (
isinstance(function.arguments[-1], ParseError) and
function.arguments[-1].kind == 'eof-in-string')
if eof_in_string:
return
function = function.arguments[-1]
write(')')


Expand Down

0 comments on commit 5a36826

Please sign in to comment.