@@ -28,8 +28,9 @@ defmodule EEx.Compiler do
28
28
generate_buffer ( t , buffer , scope , state )
29
29
end
30
30
31
- defp generate_buffer ( [ { :start_expr , line , mark , chars } | t ] , buffer , scope , state ) do
32
- { contents , t } = generate_buffer ( t , "" , [ chars | scope ] , state . dict ( [ ] ) . line ( line ) . start_line ( line ) )
31
+ defp generate_buffer ( [ { :start_expr , start_line , mark , chars } | t ] , buffer , scope , state ) do
32
+ { contents , line , t } = look_ahead_text ( t , start_line , chars )
33
+ { contents , t } = generate_buffer ( t , "" , [ contents | scope ] , state . dict ( [ ] ) . line ( line ) . start_line ( start_line ) )
33
34
buffer = state . engine . handle_expr ( buffer , mark , contents )
34
35
generate_buffer ( t , buffer , scope , state )
35
36
end
@@ -62,28 +63,27 @@ defmodule EEx.Compiler do
62
63
63
64
defp wrap_expr ( current , line , buffer , chars , state ) do
64
65
new_lines = List . duplicate ( ?\n , line - state . line )
65
-
66
- if state . dict == [ ] and empty? ( buffer ) do
67
- { current ++ new_lines ++ chars , state }
68
- else
69
- key = length ( state . dict )
70
- placeholder = '__EEX__(' ++ integer_to_list ( key ) ++ ');'
71
- { current ++ placeholder ++ new_lines ++ chars , state . update_dict ( & [ { key , buffer } | & 1 ] ) }
72
- end
66
+ key = length ( state . dict )
67
+ placeholder = '__EEX__(' ++ integer_to_list ( key ) ++ ');'
68
+ { current ++ placeholder ++ new_lines ++ chars , state . update_dict ( & [ { key , buffer } | & 1 ] ) }
73
69
end
74
70
75
- # Check if the syntax node represents an empty string
71
+ # Look text ahead on expressions
76
72
77
- defp empty? ( bin ) when is_binary ( bin ) do
78
- for ( << c <- bin >> , not c in [ ?\s , ?\t , ?\r , ?\n ] , into: "" , do: << c >> ) == ""
73
+ defp look_ahead_text ( [ { :text , text } , { :middle_expr , line , _ , chars } | t ] = list , start , contents ) do
74
+ if only_spaces? ( text ) do
75
+ { contents ++ text ++ chars , line , t }
76
+ else
77
+ { contents , start , list }
78
+ end
79
79
end
80
80
81
- defp empty? ( { :<> , _ , [ left , right ] } ) do
82
- empty? ( left ) and empty? ( right )
81
+ defp look_ahead_text ( t , start , contents ) do
82
+ { contents , start , t }
83
83
end
84
84
85
- defp empty? ( _ ) do
86
- false
85
+ defp only_spaces? ( chars ) do
86
+ Enum . all? ( chars , & ( & 1 in [ ?\s , ?\t , ?\r , ?\n ] ) )
87
87
end
88
88
89
89
# Changes placeholder to real expression
0 commit comments