@@ -199,11 +199,13 @@ SourceNode::to-string = (...args) ->
199199 if once then [sub , ref <<< {+temp }] else [sub , ref , [ref .value]]
200200
201201 # Compiles to a variable/source pair suitable for looping.
202- compile -loop -reference : (o , name , ret ) ->
202+ compile -loop -reference : (o , name , ret , safe - access ) ->
203203 if this instanceof Var and o .scope.check @value
204204 or this instanceof Unary and @op in <[ + - ]> and -1 /0 < +@it .value < 1 /0
205205 or this instanceof Literal and not @is -complex !
206- return [@compile o ] * 2
206+ code = @compile o , LEVEL_PAREN
207+ code = "(#code)" if safe -access and this not instanceof Var
208+ return [code ] * 2
207209 asn = Assign Var(tmp = o .scope.temporary name ), this
208210 ret or asn .void = true
209211 [tmp ; asn .compile o , if ret then LEVEL_CALL else LEVEL_PAREN ]
@@ -2352,7 +2354,7 @@ class exports.For extends While
23522354 else
23532355 @item = Var o .scope.temporary \x if @ref
23542356 if @item or @object and @own or @let
2355- [svar , srcPart ] = @source .compile-loop -reference o , \ref , not @object
2357+ [svar , srcPart ] = @source .compile-loop -reference o , \ref , not @object , true
23562358 svar is srcPart or temps .push svar
23572359 else
23582360 svar = srcPart = @source .compile o , LEVEL_PAREN
0 commit comments