@@ -2591,20 +2591,20 @@ defmodule Macro do
2591
2591
:ok
2592
2592
end
2593
2593
2594
- header = dbg_format_header ( env )
2594
+ prelude = quote do: options = unquote ( Macro . escape ( options ) )
2595
2595
2596
- prelude =
2597
- quote do
2598
- options = unquote ( __MODULE__ ) . __dbg_header__ ( unquote ( header ) , unquote ( options ) )
2599
- end
2596
+ dbg_ast_to_debuggable ( code , env )
2597
+ |> Enum . reduce ( { prelude , dbg_format_header ( env ) } , fn entry , { acc , header } ->
2598
+ acc =
2599
+ quote do
2600
+ unquote ( acc )
2601
+ to_debug = unquote ( entry )
2602
+ unquote ( __MODULE__ ) . __dbg__ ( to_debug , unquote ( header ) , options )
2603
+ end
2600
2604
2601
- Enum . reduce ( dbg_ast_to_debuggable ( code , env ) , prelude , fn entry , acc ->
2602
- quote do
2603
- unquote ( acc )
2604
- to_debug = unquote ( entry )
2605
- unquote ( __MODULE__ ) . __dbg__ ( to_debug , options )
2606
- end
2605
+ { acc , nil }
2607
2606
end )
2607
+ |> elem ( 0 )
2608
2608
end
2609
2609
2610
2610
# Pipelines.
@@ -2841,24 +2841,18 @@ defmodule Macro do
2841
2841
# Made public to be called from Macro.dbg/3, so that we generate as little code
2842
2842
# as possible and call out into a function as soon as we can.
2843
2843
@ doc false
2844
- def __dbg_header__ ( header_string , options ) do
2844
+ def __dbg__ ( to_debug , header , options ) do
2845
2845
{ print_location? , options } = Keyword . pop ( options , :print_location , true )
2846
+ ansi_enabled? = options [ :syntax_colors ] != [ ]
2846
2847
2847
- if print_location? do
2848
- ansi_enabled? = options [ :syntax_colors ] != [ ]
2849
- formatted = [ :cyan , :italic , header_string , :reset , "\n " ]
2848
+ if print_location? and is_binary ( header ) do
2849
+ formatted = [ :cyan , :italic , header , :reset , "\n " ]
2850
2850
:ok = IO . write ( IO.ANSI . format ( formatted , ansi_enabled? ) )
2851
2851
end
2852
2852
2853
- options
2854
- end
2855
-
2856
- @ doc false
2857
- def __dbg__ ( to_debug , options ) do
2858
2853
syntax_colors = if IO.ANSI . enabled? ( ) , do: IO.ANSI . syntax_colors ( ) , else: [ ]
2859
2854
options = Keyword . merge ( [ width: 80 , pretty: true , syntax_colors: syntax_colors ] , options )
2860
2855
{ formatted , result } = dbg_format_ast_to_debug ( to_debug , options )
2861
- ansi_enabled? = options [ :syntax_colors ] != [ ]
2862
2856
:ok = IO . write ( IO.ANSI . format ( [ formatted , ?\n ] , ansi_enabled? ) )
2863
2857
result
2864
2858
end
0 commit comments