Skip to content

Commit a39f469

Browse files
committed
Do not warn for assignment with blocks in EEx
1 parent b56b49f commit a39f469

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

lib/eex/lib/eex/compiler.ex

+7-7
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,6 @@ defmodule EEx.Compiler do
353353
scope,
354354
state
355355
) do
356-
if mark == ~c"" do
357-
message =
358-
"the contents of this expression won't be output unless the EEx block starts with \"<%=\""
359-
360-
:elixir_errors.erl_warn({meta.line, meta.column}, state.file, message)
361-
end
362-
363356
{rest, line, contents} = look_ahead_middle(rest, meta.line, chars) || {rest, meta.line, chars}
364357
start_line = meta.line
365358
start_column = column(meta.column, mark)
@@ -372,6 +365,13 @@ defmodule EEx.Compiler do
372365
%{state | quoted: [], line: line}
373366
)
374367

368+
if mark == ~c"" and not match?({:=, _, [_, _]}, contents) do
369+
message =
370+
"the contents of this expression won't be output unless the EEx block starts with \"<%=\""
371+
372+
:elixir_errors.erl_warn({meta.line, meta.column}, state.file, message)
373+
end
374+
375375
buffer = state.engine.handle_expr(buffer, IO.chardata_to_string(mark), contents)
376376
generate_buffer(rest, buffer, scope, state)
377377
end

lib/eex/test/eex/smart_engine_test.exs

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ defmodule EEx.SmartEngineTest do
4343
assert_received :found
4444
end
4545

46-
test "error with unused \"do\" block without \"<%=\" modifier" do
47-
stderr =
48-
ExUnit.CaptureIO.capture_io(:stderr, fn ->
49-
assert_eval("", "<% if true do %>I'm invisible!<% end %>", assigns: %{})
50-
end)
51-
52-
assert stderr =~ "the contents of this expression won't be output"
53-
end
54-
5546
defp assert_eval(expected, actual, binding \\ []) do
5647
result = EEx.eval_string(actual, binding, file: __ENV__.file, engine: EEx.SmartEngine)
5748
assert result == expected

lib/eex/test/eex_test.exs

+10
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,16 @@ defmodule EExTest do
534534
~s[unexpected beginning of EEx tag \"<%=\" on \"<%= end %>\"]
535535
end
536536

537+
test "unused \"do\" block without \"<%=\" modifier" do
538+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
539+
EEx.compile_string("<% if true do %>I'm invisible!<% end %>")
540+
end) =~ "the contents of this expression won't be output"
541+
542+
# These are fine though
543+
EEx.compile_string("<% foo = fn -> %>Hello<% end %>")
544+
EEx.compile_string("<% foo = if true do %>Hello<% end %>")
545+
end
546+
537547
test "from tokenizer" do
538548
warning =
539549
ExUnit.CaptureIO.capture_io(:stderr, fn ->

0 commit comments

Comments
 (0)