Skip to content

Commit

Permalink
Do not add empty style elements
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3yx committed Dec 29, 2024
1 parent f306f01 commit 710a380
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,13 @@ function flow.get_context()
return current_ctx
end

-- Returns the new index of the affected element
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 selectors = {}
if sels then
Expand Down Expand Up @@ -960,6 +966,8 @@ local function insert_style_elem(tree, idx, node, props, sels)
props = reset_props,
})
end

return idx + 1
end

local function extract_props(t)
Expand Down Expand Up @@ -988,11 +996,11 @@ local function insert_shorthand_elements(tree)
-- elements.
props = extract_props(props)
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
insert_style_elem(tree, i + j, node, extract_props(substyle),
substyle.sel:split(","))
for _, substyle in ipairs(node.style) do
next_idx = insert_style_elem(tree, next_idx, node,
extract_props(substyle), substyle.sel:split(","))
end
end

Expand Down

0 comments on commit 710a380

Please sign in to comment.