Skip to content

Commit 3eb21c3

Browse files
committed
wip
1 parent 3a2ce69 commit 3eb21c3

File tree

5 files changed

+710
-622
lines changed

5 files changed

+710
-622
lines changed

Diff for: lib/elixir/lib/code.ex

+16-10
Original file line numberDiff line numberDiff line change
@@ -1035,9 +1035,7 @@ defmodule Code do
10351035
to_quoted_opts =
10361036
[
10371037
unescape: false,
1038-
literal_encoder: &{:ok, {:__block__, &2, [&1]}},
10391038
include_comments: true,
1040-
token_metadata: true,
10411039
emit_warnings: false
10421040
] ++ opts
10431041

@@ -1291,22 +1289,21 @@ defmodule Code do
12911289

12921290
Process.put(:code_formatter_comments, [])
12931291

1294-
opts =
1292+
opts =
12951293
if include_comments do
1296-
[preserve_comments: &preserve_comments/5,
1294+
[
1295+
preserve_comments: &preserve_comments/5,
12971296
literal_encoder: &{:ok, {:__block__, &2, [&1]}},
1298-
token_metadata: true,
1299-
unescape: false,
1300-
columns: true,
1301-
] ++ opts
1297+
token_metadata: true,
1298+
unescape: false
1299+
] ++ opts
13021300
else
13031301
opts
13041302
end
13051303

13061304
quoted = :elixir.string_to_quoted!(to_charlist(string), line, column, file, opts)
13071305

13081306
if include_comments do
1309-
# quoted = Code.Normalizer.normalize(quoted)
13101307
Code.Comments.merge_comments(quoted, Process.get(:code_formatter_comments))
13111308
else
13121309
quoted
@@ -1425,7 +1422,7 @@ defmodule Code do
14251422
defp next_eol_count([?\r, ?\n | rest], count), do: next_eol_count(rest, count + 1)
14261423
defp next_eol_count(_, count), do: count
14271424

1428-
defp previous_eol_count([{token, {_, _, count}} | _])
1425+
defp previous_eol_count([{token, {_, _, count}} | _] )
14291426
when token in [:eol, :",", :";"] and count > 0 do
14301427
count
14311428
end
@@ -1492,8 +1489,17 @@ defmodule Code do
14921489
@doc since: "1.13.0"
14931490
@spec quoted_to_algebra(Macro.t(), keyword) :: Inspect.Algebra.t()
14941491
def quoted_to_algebra(quoted, opts \\ []) do
1492+
comments = opts[:comments]
1493+
14951494
quoted
14961495
|> Code.Normalizer.normalize(opts)
1496+
|> then(fn quoted ->
1497+
if comments do
1498+
Code.Comments.merge_comments(quoted, comments)
1499+
else
1500+
quoted
1501+
end
1502+
end)
14971503
|> Code.Formatter.to_algebra(opts)
14981504
end
14991505

0 commit comments

Comments
 (0)