elixir-lang/elixir

EEx typespec

Closed this issue · 2 comments

Elixir and Erlang/OTP versions

Elixir 1.18.4

Operating system

Mac OS X

Current behavior

EEx.compile_string is spec'ed to return String.t, but eex engines to not seem to need to adhere to that result. E.g. Phoenix.HTML.Engine returns safe tuples.

Expected behavior

At this point it's probably unavoidable to officially extend the interface here, but I'm wondering it EEx engines would be expected to return just strings or plain any datastructure. I'm looking into builing up something similar like Phoenix.HTML.Engine + the safe protocol.

Can you please provide more information? Because this is what I'm looking at:

@spec compile_string(String.t(), [compile_opt]) :: Macro.t()

Perhaps you mean something else?

Ah sorry. EEx.eval_string, not compile_string

import Phoenix.HTML

EEx.eval_string("""
Abcl <%=  @test %>
""", [assigns: %{test: "Hi"}], engine: Phoenix.HTML.Engine)
# {:safe, ["Abcl ", "Hi", "\n"]}