Skip to content

Commit ee90126

Browse files
Add delimiter meta to demote calls with quoted identifier (#13963)
1 parent 1ca0636 commit ee90126

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,15 @@ build_dot_container(Dot, Left, Right, Extra) ->
890890

891891
build_dot(Dot, Left, {_, Location, _} = Right) ->
892892
Meta = meta_from_token(Dot),
893-
IdentifierLocation = meta_from_location(Location),
894-
{'.', Meta, IdentifierLocation, [Left, extract_identifier(Right)]}.
893+
IdentifierMeta0 = meta_from_location(Location),
894+
IdentifierMeta1 =
895+
case Dot of
896+
{'.', {_Line, _Column, Delimiter}} when Delimiter =/= nil ->
897+
delimiter(<<Delimiter>>) ++ IdentifierMeta0;
898+
_ ->
899+
IdentifierMeta0
900+
end,
901+
{'.', Meta, IdentifierMeta1, [Left, extract_identifier(Right)]}.
895902

896903
extract_identifier({Kind, _, Identifier}) when
897904
Kind == identifier; Kind == bracket_identifier; Kind == paren_identifier;
@@ -916,17 +923,17 @@ build_no_parens_do_block(Expr, Args, {BlockMeta, Block}) ->
916923
build_no_parens(Expr, Args) ->
917924
build_call(Expr, Args).
918925

919-
build_identifier({'.', Meta, IdentifierLocation, DotArgs}) ->
920-
{{'.', Meta, DotArgs}, [{no_parens, true} | IdentifierLocation], []};
926+
build_identifier({'.', Meta, IdentifierMeta, DotArgs}) ->
927+
{{'.', Meta, DotArgs}, [{no_parens, true} | IdentifierMeta], []};
921928

922929
build_identifier({'.', Meta, _} = Dot) ->
923930
{Dot, [{no_parens, true} | Meta], []};
924931

925932
build_identifier({_, Location, Identifier}) ->
926933
{Identifier, meta_from_location(Location), nil}.
927934

928-
build_call({'.', Meta, IdentifierLocation, DotArgs}, Args) ->
929-
{{'.', Meta, DotArgs}, IdentifierLocation, Args};
935+
build_call({'.', Meta, IdentifierMeta, DotArgs}, Args) ->
936+
{{'.', Meta, DotArgs}, IdentifierMeta, Args};
930937

931938
build_call({'.', Meta, _} = Dot, Args) ->
932939
{Dot, Meta, Args};

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,8 @@ handle_dot([$., H | T] = Original, Line, Column, DotInfo, Scope, Tokens) when ?i
919919
case unsafe_to_atom(UnescapedPart, Line, Column, NewScope) of
920920
{ok, Atom} ->
921921
Token = check_call_identifier(Line, Column, Part, Atom, Rest),
922-
TokensSoFar = add_token_with_eol({'.', DotInfo}, Tokens),
922+
DotInfo1 = setelement(3, DotInfo, $"),
923+
TokensSoFar = add_token_with_eol({'.', DotInfo1}, Tokens),
923924
tokenize(Rest, NewLine, NewColumn, NewScope, [Token | TokensSoFar]);
924925

925926
{error, Reason} ->

lib/elixir/test/elixir/kernel/parser_test.exs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,17 @@ defmodule Kernel.ParserTest do
128128
end
129129

130130
test "handles graphemes inside quoted identifiers" do
131-
assert {{:., _, [{:foo, _, nil}, :"➡️"]}, _, []} = Code.string_to_quoted!(~s|foo."➡️"|)
131+
assert {
132+
{:., _, [{:foo, _, nil}, :"➡️"]},
133+
[no_parens: true, delimiter: ~S["], line: 1],
134+
[]
135+
} = Code.string_to_quoted!(~S|foo."➡️"|, token_metadata: true)
136+
137+
assert {
138+
{:., _, [{:foo, _, nil}, :"➡️"]},
139+
[closing: [line: 1], delimiter: ~S["], line: 1],
140+
[]
141+
} = Code.string_to_quoted!(~S|foo."➡️"()|, token_metadata: true)
132142
end
133143
end
134144

0 commit comments

Comments
 (0)