Do not add empty style elements

This commit is contained in:
luk3yx 2024-12-30 11:08:13 +13:00
parent f306f01f57
commit 710a380d46

View File

@ -921,7 +921,13 @@ function flow.get_context()
return current_ctx return current_ctx
end end
-- Returns the new index of the affected element
local function insert_style_elem(tree, idx, node, props, sels) local function insert_style_elem(tree, idx, node, props, sels)
if not next(props) then
-- No properties, don't try and add an empty style element
return idx
end
local base_selector = node.name or node.type local base_selector = node.name or node.type
local selectors = {} local selectors = {}
if sels then if sels then
@ -960,6 +966,8 @@ local function insert_style_elem(tree, idx, node, props, sels)
props = reset_props, props = reset_props,
}) })
end end
return idx + 1
end end
local function extract_props(t) local function extract_props(t)
@ -988,11 +996,11 @@ local function insert_shorthand_elements(tree)
-- elements. -- elements.
props = extract_props(props) props = extract_props(props)
end end
insert_style_elem(tree, i, node, props) local next_idx = insert_style_elem(tree, i, node, props)
for j, substyle in ipairs(node.style) do for _, substyle in ipairs(node.style) do
insert_style_elem(tree, i + j, node, extract_props(substyle), next_idx = insert_style_elem(tree, next_idx, node,
substyle.sel:split(",")) extract_props(substyle), substyle.sel:split(","))
end end
end end