Skip to content

Commit

Permalink
fix hyphen counts
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrul committed Oct 14, 2024
1 parent 368cdd3 commit 9f37a1d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions luax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ function State:toggle(key, bool)
end

local function kebabToCamel(str)
return str:gsub("%-(%w)", function(c)
local tag = str:gsub("%-(%w)", function(c)
return c:upper()
end)
local _, count = str:gsub("-", "-")
return tag, count
end

local function formatDocTypeParams(input)
Expand Down Expand Up @@ -112,8 +114,9 @@ local function decentParserAST(input)
end
if tagName then
if tagName:match("(%-+)") then
tagName = kebabToCamel(tagName)
s:inc()
local tag, count = kebabToCamel(tagName)
tagName = tag
s:inc(count)
end
s:incDeepNode()
end
Expand All @@ -140,8 +143,9 @@ local function decentParserAST(input)
s:inc(#tagName)
elseif tagNameEnd then
if tagNameEnd:match("(%-+)") then
tagNameEnd = kebabToCamel(tagNameEnd)
s:inc()
local tag, count = kebabToCamel(tagNameEnd)
tagNameEnd = tag
s:inc(count)
end
s:decDeepNode()
if s.isTag and not s.textNode then
Expand Down
2 changes: 1 addition & 1 deletion test/21_web_component.luax
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return <fluent-button>Example</fluent-button>
return <fluent-button-test><fci-button>Example</fci-button></fluent-button-test>
2 changes: 1 addition & 1 deletion test/test_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("LuaX", function()

it("should return a HTML string when given XML like syntax with kebab-case tag", function()
local fui = require("test.21_web_component")
assert.is.equal([[<fluent-button>Example</fluent-button>]], h(fui))
assert.is.equal([[<fluent-button-test><fci-button>Example</fci-button></fluent-button-test>]], h(fui))
end)

end)

0 comments on commit 9f37a1d

Please sign in to comment.