Skip to content

Commit 67617e5

Browse files
committed
Do not warn for assignment with blocks in EEx
1 parent 6f5fc94 commit 67617e5

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

Diff for: lib/eex/lib/eex/compiler.ex

+7-7
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,6 @@ defmodule EEx.Compiler do
340340
scope,
341341
state
342342
) do
343-
if mark == ~c"" do
344-
message =
345-
"the contents of this expression won't be output unless the EEx block starts with \"<%=\""
346-
347-
:elixir_errors.erl_warn({meta.line, meta.column}, state.file, message)
348-
end
349-
350343
{rest, line, contents} = look_ahead_middle(rest, meta.line, chars) || {rest, meta.line, chars}
351344
start_line = meta.line
352345
start_column = column(meta.column, mark)
@@ -359,6 +352,13 @@ defmodule EEx.Compiler do
359352
%{state | quoted: [], line: line}
360353
)
361354

355+
if mark == ~c"" and not match?({:=, _, [_, _]}, contents) do
356+
message =
357+
"the contents of this expression won't be output unless the EEx block starts with \"<%=\""
358+
359+
:elixir_errors.erl_warn({meta.line, meta.column}, state.file, message)
360+
end
361+
362362
buffer = state.engine.handle_expr(buffer, IO.chardata_to_string(mark), contents)
363363
generate_buffer(rest, buffer, scope, state)
364364
end

Diff for: 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

Diff for: lib/eex/test/eex_test.exs

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

546+
test "unused \"do\" block without \"<%=\" modifier" do
547+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
548+
EEx.compile_string("<% if true do %>I'm invisible!<% end %>")
549+
end) =~ "the contents of this expression won't be output"
550+
551+
# These are fine though
552+
EEx.compile_string("<% foo = fn -> %>Hello<% end %>")
553+
EEx.compile_string("<% foo = if true do %>Hello<% end %>")
554+
end
555+
546556
test "from tokenizer" do
547557
warning =
548558
ExUnit.CaptureIO.capture_io(:stderr, fn ->

0 commit comments

Comments
 (0)