Correctly parse do blocks

Did not correctly parse expressions with do blocks
where the expression had two or more arguments before
the block.
This commit is contained in:
Mitchell Hanberg 2020-07-22 21:30:39 -04:00
parent 2206aa62fe
commit 7bf649c4b5
3 changed files with 22 additions and 7 deletions

View file

@ -2,6 +2,10 @@
## Master
### Bugs
- Did not correctly parse expressions with do blocks where the expression had two or more arguments before the block
## 0.6.0-alpha.4
- Fix a bug where lists would not properly compile

View file

@ -395,13 +395,10 @@ defmodule Temple.Parser do
%{
name: :do_expressions,
applicable?: fn
{_, _, [_, [{:do, _} | _]]} ->
true
{_, _, args} when is_list(args) ->
Enum.any?(args, fn arg -> match?([{:do, _} | _], arg) end)
{_, _, [[{:do, _} | _]]} ->
true
{_, _, _} ->
_ ->
false
end,
parse: fn {name, meta, args}, buffer ->

View file

@ -351,6 +351,20 @@ defmodule TempleTest do
end
end
assert result == ~s{<%= leenk(to: "/route", class: "foo") do %><div class="hi"></div><% end %>}
assert result ==
~s{<%= leenk(to: "/route", class: "foo") do %><div class="hi"></div><% end %>}
end
test "for with 2 generators" do
result =
temple do
for x <- 1..5, y <- 6..10 do
div do: x
div do: y
end
end
assert result ==
~s{<%= for(x <- 1..5, y <- 6..10) do %><div><%= x %></div><div><%= y %></div><% end %>}
end
end