Skip to content

Commit

Permalink
allow empty css variables
Browse files Browse the repository at this point in the history
fixes Textualize#1849

Co-authored-by: @eliasdorneles
  • Loading branch information
zormit authored and seifertm committed Jul 22, 2023
1 parent abc745c commit be52691
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/textual/css/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ def substitute_references(
variables.setdefault(variable_name, []).append(token)
yield token
elif token.name == "variable_value_end":
# in case of an empty variable, avoid not referenced error
variables.setdefault(variable_name, [])
yield token
break
# For variables referring to other variables
Expand Down
16 changes: 16 additions & 0 deletions tests/css/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ def test_undefined_variable(self):
with pytest.raises(UnresolvedVariableError):
list(substitute_references(tokenize(css, "")))

def test_empty_variable(self):
css = "$x:\n* { background:$x; }"
result = list(substitute_references(tokenize(css, "")))
assert [(t.name, t.value) for t in result] == [
("variable_name", "$x:"),
("variable_value_end", "\n"),
("selector_start_universal", "*"),
("whitespace", " "),
("declaration_set_start", "{"),
("whitespace", " "),
("declaration_name", "background:"),
("declaration_end", ";"),
("whitespace", " "),
("declaration_set_end", "}"),
]

def test_transitive_reference(self):
css = "$x: 1\n$y: $x\n.thing { border: $y }"
assert list(substitute_references(tokenize(css, ""))) == [
Expand Down

0 comments on commit be52691

Please sign in to comment.