@@ -189,12 +189,15 @@ do_quote({'__aliases__', Meta, [H | T]} = Alias, #elixir_quote{aliases_hygiene=t
189
189
Aliases when is_list (Aliases ) -> false
190
190
end ,
191
191
AliasMeta = keystore (alias , keydelete (counter , Meta ), Annotation ),
192
- do_quote_tuple ({ '__aliases__' , AliasMeta , [H | T ]} , Q , E );
192
+ do_quote_tuple ('__aliases__' , AliasMeta , [H | T ], Q , E );
193
193
194
194
% % Vars
195
195
196
+ do_quote ({Left , Meta , nil }, # elixir_quote {vars_hygiene = true , imports_hygiene = true } = Q , E ) when is_atom (Left ) ->
197
+ do_quote_import (Left , Meta , Q # elixir_quote .context , Q , E );
198
+
196
199
do_quote ({Left , Meta , nil }, # elixir_quote {vars_hygiene = true } = Q , E ) when is_atom (Left ) ->
197
- do_quote_tuple ({ Left , Meta , Q # elixir_quote .context } , Q , E );
200
+ do_quote_tuple (Left , Meta , Q # elixir_quote .context , Q , E );
198
201
199
202
% % Unquote
200
203
@@ -207,28 +210,11 @@ do_quote({{'.', Meta, [Left, unquote]}, _, [Expr]}, #elixir_quote{unquote=true}
207
210
% % Imports
208
211
209
212
do_quote ({'&' , Meta , [{'/' , _ , [{F , _ , C }, A ]}] = Args },
210
- # elixir_quote {imports_hygiene = true } = Q , E ) when is_atom (F ), is_integer (A ), is_atom (C ) ->
213
+ # elixir_quote {imports_hygiene = true } = Q , E ) when is_atom (F ), is_integer (A ), is_atom (C ) ->
211
214
do_quote_fa ('&' , Meta , Args , F , A , Q , E );
212
215
213
216
do_quote ({Name , Meta , ArgsOrAtom }, # elixir_quote {imports_hygiene = true } = Q , E ) when is_atom (Name ) ->
214
- Arity = case is_atom (ArgsOrAtom ) of
215
- true -> 0 ;
216
- false -> length (ArgsOrAtom )
217
- end ,
218
-
219
- NewMeta = case (keyfind (import , Meta ) == false ) andalso
220
- elixir_dispatch :find_import (Meta , Name , Arity , E ) of
221
- false ->
222
- case (Arity == 1 ) andalso keyfind (ambiguous_op , Meta ) of
223
- {ambiguous_op , nil } -> keystore (ambiguous_op , Meta , Q # elixir_quote .context );
224
- _ -> Meta
225
- end ;
226
- Receiver ->
227
- keystore (import , keystore (context , Meta , Q # elixir_quote .context ), Receiver )
228
- end ,
229
-
230
- Annotated = annotate ({Name , NewMeta , ArgsOrAtom }, Q # elixir_quote .context ),
231
- do_quote_tuple (Annotated , Q , E );
217
+ do_quote_import (Name , Meta , ArgsOrAtom , Q , E );
232
218
233
219
do_quote ({_ , _ , _ } = Tuple , # elixir_quote {escape = false } = Q , E ) ->
234
220
Annotated = annotate (Tuple , Q # elixir_quote .context ),
@@ -300,6 +286,26 @@ bad_escape(Arg) ->
300
286
" The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, " ,
301
287
" PIDs and remote functions in the format &Mod.fun/arity" >>).
302
288
289
+ do_quote_import (Name , Meta , ArgsOrAtom , # elixir_quote {imports_hygiene = true } = Q , E ) ->
290
+ Arity = case is_atom (ArgsOrAtom ) of
291
+ true -> 0 ;
292
+ false -> length (ArgsOrAtom )
293
+ end ,
294
+
295
+ NewMeta = case (keyfind (import , Meta ) == false ) andalso
296
+ elixir_dispatch :find_import (Meta , Name , Arity , E ) of
297
+ false ->
298
+ case (Arity == 1 ) andalso keyfind (ambiguous_op , Meta ) of
299
+ {ambiguous_op , nil } -> keystore (ambiguous_op , Meta , Q # elixir_quote .context );
300
+ _ -> Meta
301
+ end ;
302
+ Receiver ->
303
+ keystore (import , keystore (context , Meta , Q # elixir_quote .context ), Receiver )
304
+ end ,
305
+
306
+ Annotated = annotate ({Name , NewMeta , ArgsOrAtom }, Q # elixir_quote .context ),
307
+ do_quote_tuple (Annotated , Q , E ).
308
+
303
309
do_quote_call (Left , Meta , Expr , Args , Q , E ) ->
304
310
All = [meta (Meta , Q ), Left , {unquote , Meta , [Expr ]}, Args ,
305
311
Q # elixir_quote .context ],
@@ -313,21 +319,24 @@ do_quote_fa(Target, Meta, Args, F, A, Q, E) ->
313
319
false -> Meta ;
314
320
Receiver -> keystore (import_fa , Meta , {Receiver , Q # elixir_quote .context })
315
321
end ,
316
- do_quote_tuple ({Target , NewMeta , Args }, Q , E ).
322
+ do_quote_tuple (Target , NewMeta , Args , Q , E ).
323
+
324
+ do_quote_tuple ({Left , Meta , Right }, Q , E ) ->
325
+ do_quote_tuple (Left , Meta , Right , Q , E ).
317
326
318
327
% In a def unquote(name)(args) expression name will be an atom literal,
319
328
% thus location: :keep will not have enough information to generate the proper file/line annotation.
320
329
% This alters metadata to force Elixir to show the file to which the definition is added
321
330
% instead of the file where definition is quoted (i.e. we behave the opposite to location: :keep).
322
- do_quote_tuple ({ Left , Meta , [{{unquote , _ , _ }, _ , _ }, _ ] = Right } , Q , E ) when ? defs (Left ) ->
331
+ do_quote_tuple (Left , Meta , [{{unquote , _ , _ }, _ , _ }, _ ] = Right , Q , E ) when ? defs (Left ) ->
323
332
{TLeft , LQ } = do_quote (Left , Q , E ),
324
333
{[Head , Body ], RQ } = do_quote (Right , LQ , E ),
325
334
{'{}' , [], [HLeft , HMeta , HRight ]} = Head ,
326
335
NewMeta = lists :keydelete (file , 1 , HMeta ),
327
336
NewHead = {'{}' , [], [HLeft , NewMeta , HRight ]},
328
337
{{'{}' , [], [TLeft , meta (Meta , Q ), [NewHead , Body ]]}, RQ };
329
338
330
- do_quote_tuple ({ Left , Meta , Right } , Q , E ) ->
339
+ do_quote_tuple (Left , Meta , Right , Q , E ) ->
331
340
{TLeft , LQ } = do_quote (Left , Q , E ),
332
341
{TRight , RQ } = do_quote (Right , LQ , E ),
333
342
{{'{}' , [], [TLeft , meta (Meta , Q ), TRight ]}, RQ }.
0 commit comments