@@ -159,6 +159,10 @@ class exports.Rewriter
159
159
tokens .splice i, 0 , generate ' CALL_END' , ' )'
160
160
i += 1
161
161
162
+ endAllImplicitCalls = ->
163
+ while inImplicitCall ()
164
+ endImplicitCall ()
165
+
162
166
startImplicitObject = (j , startsLine = yes ) ->
163
167
idx = j ? i
164
168
stack .push [' {' , idx, sameLine : yes , startsLine : startsLine, ours : yes ]
@@ -281,10 +285,13 @@ class exports.Rewriter
281
285
# .g b
282
286
# .h a
283
287
#
284
- if (prevTag is ' OUTDENT' or prevToken .newLine ) and inImplicitCall () and
285
- tag in [' .' , ' ?.' , ' ::' , ' ?::' ]
286
- endImplicitCall ()
287
- return forward (1 )
288
+ if inImplicitCall () and tag in CALL_CLOSERS
289
+ if prevTag is ' OUTDENT'
290
+ endImplicitCall ()
291
+ return forward (1 )
292
+ if prevToken .newLine
293
+ endAllImplicitCalls ()
294
+ return forward (1 )
288
295
289
296
stackTop ()[2 ].sameLine = no if inImplicitObject () and tag in LINEBREAKS
290
297
@@ -363,7 +370,8 @@ class exports.Rewriter
363
370
token[1 ] isnt ' ;' and token[0 ] in SINGLE_CLOSERS and
364
371
not (token[0 ] is ' TERMINATOR' and @ tag (i + 1 ) in EXPRESSION_CLOSE) and
365
372
not (token[0 ] is ' ELSE' and starter isnt ' THEN' ) and
366
- not (token[0 ] in [' CATCH' , ' FINALLY' ] and starter in [' ->' , ' =>' ])
373
+ not (token[0 ] in [' CATCH' , ' FINALLY' ] and starter in [' ->' , ' =>' ]) or
374
+ token[0 ] in CALL_CLOSERS and @tokens [i - 1 ].newLine
367
375
368
376
action = (token , i ) ->
369
377
@tokens .splice (if @ tag (i - 1 ) is ' ,' then i - 1 else i), 0 , outdent
@@ -478,3 +486,6 @@ SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADIN
478
486
479
487
# Tokens that end a line.
480
488
LINEBREAKS = [' TERMINATOR' , ' INDENT' , ' OUTDENT' ]
489
+
490
+ # Tokens that close open calls when they follow a newline.
491
+ CALL_CLOSERS = [' .' , ' ?.' , ' ::' , ' ?::' ]
0 commit comments