Skip to content

Commit a701cc8

Browse files
wojtekmachjosevalim
authored andcommitted
Turn EEx.SyntaxError into a warning to keep backwards compatibility (#6220)
1 parent a8a662d commit a701cc8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/eex/lib/eex/compiler.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ defmodule EEx.Compiler do
6969
{buffer, rest}
7070
end
7171

72-
defp generate_buffer([{:end_expr, line, modifier, chars} | _], _buffer, [_ | _], state) do
72+
defp generate_buffer([{:end_expr, line, modifier, chars} | t], buffer, [_ | _] = scope, state) do
7373
message = "unexpected beginning of EEx tag \"<%#{modifier}\" on end of expression \"<%#{modifier}#{chars}%>\", " <>
7474
"please remove \"#{modifier}\" accordingly"
75-
raise EEx.SyntaxError, message: message, file: state.file, line: line
75+
:elixir_errors.warn line, state.file, message
76+
generate_buffer([{:end_expr, line, '', chars} | t], buffer, scope, state)
77+
# TODO: Make this an error on Elixir v2.0 since it accidentally worked previously.
78+
# raise EEx.SyntaxError, message: message, file: state.file, line: line
7679
end
7780

7881
defp generate_buffer([{:end_expr, line, _, chars} | _], _buffer, [], state) do

lib/eex/test/eex_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ defmodule EExTest do
169169
end
170170

171171
test "when middle expression has a modifier" do
172-
ExUnit.CaptureIO.capture_io :stderr, fn ->
172+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
173173
EEx.compile_string "foo <%= if true do %>true<%= else %>false<% end %>"
174-
end
174+
end) =~ ~s[unexpected beginning of EEx tag \"<%=\" on \"<%= else %>\"]
175175
end
176176

177177
test "when end expression has a modifier" do
178-
assert_raise EEx.SyntaxError, ~s[nofile:1: unexpected beginning of EEx tag "<%=" on end of expression "<%= end %>", please remove "=" accordingly], fn ->
178+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
179179
EEx.compile_string "foo <%= if true do %>true<% else %>false<%= end %>"
180-
end
180+
end) =~ ~s[unexpected beginning of EEx tag \"<%=\" on end of expression \"<%= end %>\"]
181181
end
182182
end
183183

0 commit comments

Comments
 (0)