Skip to content

Commit c2a0d8e

Browse files
committed
Do not emit duplicate warnings from tokenizer, closes #12961
1 parent a16517e commit c2a0d8e

File tree

3 files changed

+31
-42
lines changed

3 files changed

+31
-42
lines changed

lib/eex/lib/eex/compiler.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ defmodule EEx.Compiler do
7171
{:ok, expr, new_line, new_column, rest} ->
7272
{key, expr} =
7373
case :elixir_tokenizer.tokenize(expr, 1, file: "eex", check_terminators: false) do
74-
{:ok, _line, _column, warnings, tokens} ->
75-
Enum.each(Enum.reverse(warnings), fn {location, msg} ->
76-
:elixir_errors.erl_warn(location, state.file, msg)
77-
end)
78-
74+
{:ok, _line, _column, _warnings, tokens} ->
75+
# We ignore warnings because the code will be tokenized
76+
# again later with the right line+column info
7977
token_key(tokens, expr)
8078

8179
{:error, _, _, _, _} ->

lib/eex/test/eex/tokenizer_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ defmodule EEx.TokenizerTest do
55

66
@opts [indentation: 0, trim: false]
77

8-
test "tokenizer warning" do
9-
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
10-
EEx.tokenize(~c"foo <% :'bar' %>", @opts)
11-
end) =~ "found quoted atom \"bar\" but the quotes are not required"
12-
end
13-
148
test "simple charlists" do
159
assert EEx.tokenize(~c"foo", @opts) ==
1610
{:ok, [{:text, ~c"foo", %{column: 1, line: 1}}, {:eof, %{column: 4, line: 1}}]}

lib/eex/test/eex_test.exs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -463,39 +463,24 @@ defmodule EExTest do
463463
end
464464
end
465465

466-
test "when middle expression has a modifier" do
467-
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
468-
EEx.compile_string("foo <%= if true do %>true<%= else %>false<% end %>")
469-
end) =~ ~s[unexpected beginning of EEx tag \"<%=\" on \"<%= else %>\"]
470-
end
471-
472-
test "when end expression has a modifier" do
473-
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
474-
EEx.compile_string("foo <%= if true do %>true<% else %>false<%= end %>")
475-
end) =~
476-
~s[unexpected beginning of EEx tag \"<%=\" on \"<%= end %>\"]
477-
end
478-
479-
test "when trying to use marker '/' without implementation" do
466+
test "when trying to use marker '|' without implementation" do
480467
msg =
481-
~r/unsupported EEx syntax <%\/ %> \(the syntax is valid but not supported by the current EEx engine\)/
468+
~r/unsupported EEx syntax <%| %> \(the syntax is valid but not supported by the current EEx engine\)/
482469

483470
assert_raise EEx.SyntaxError, msg, fn ->
484-
EEx.compile_string("<%/ true %>")
471+
EEx.compile_string("<%| true %>")
485472
end
486473
end
487474

488-
test "when trying to use marker '|' without implementation" do
475+
test "when trying to use marker '/' without implementation" do
489476
msg =
490-
~r/unsupported EEx syntax <%| %> \(the syntax is valid but not supported by the current EEx engine\)/
477+
~r/unsupported EEx syntax <%\/ %> \(the syntax is valid but not supported by the current EEx engine\)/
491478

492479
assert_raise EEx.SyntaxError, msg, fn ->
493-
EEx.compile_string("<%| true %>")
480+
EEx.compile_string("<%/ true %>")
494481
end
495482
end
496-
end
497483

498-
describe "error messages" do
499484
test "honor line numbers" do
500485
assert_raise EEx.SyntaxError,
501486
"nofile:100:6: expected closing '%>' for EEx expression",
@@ -516,18 +501,30 @@ defmodule EExTest do
516501
EEx.compile_string("foo <%= bar", file: "my_file.eex")
517502
end
518503
end
504+
end
519505

520-
test "when <%!-- is not closed" do
521-
message = """
522-
my_file.eex:1:5: expected closing '--%>' for EEx expression
523-
|
524-
1 | foo <%!-- bar
525-
| ^\
526-
"""
506+
describe "warnings" do
507+
test "when middle expression has a modifier" do
508+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
509+
EEx.compile_string("foo <%= if true do %>true<%= else %>false<% end %>")
510+
end) =~ ~s[unexpected beginning of EEx tag \"<%=\" on \"<%= else %>\"]
511+
end
527512

528-
assert_raise EEx.SyntaxError, message, fn ->
529-
EEx.compile_string("foo <%!-- bar", file: "my_file.eex")
530-
end
513+
test "when end expression has a modifier" do
514+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
515+
EEx.compile_string("foo <%= if true do %>true<% else %>false<%= end %>")
516+
end) =~
517+
~s[unexpected beginning of EEx tag \"<%=\" on \"<%= end %>\"]
518+
end
519+
520+
test "from tokenizer" do
521+
warning =
522+
ExUnit.CaptureIO.capture_io(:stderr, fn ->
523+
EEx.compile_string(~s'<%= :"foo" %>', file: "tokenizer.ex")
524+
end)
525+
526+
assert warning =~ "found quoted atom \"foo\" but the quotes are not required"
527+
assert warning =~ "tokenizer.ex:1:5"
531528
end
532529
end
533530

0 commit comments

Comments
 (0)