Skip to content

Commit 76945ab

Browse files
Julian RosseGeoffreyBooth
Julian Rosse
authored andcommitted
Fix #4487: Outdentation bug (#4488)
1 parent b192e21 commit 76945ab

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

lib/coffeescript/lexer.js

+3-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

+3-6
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,9 @@ exports.Lexer = class Lexer
414414
lastIndent = @indents[@indents.length - 1]
415415
if not lastIndent
416416
moveOut = 0
417-
else if lastIndent is @outdebt
418-
moveOut -= @outdebt
419-
@outdebt = 0
420-
else if lastIndent < @outdebt
421-
@outdebt -= lastIndent
422-
moveOut -= lastIndent
417+
else if @outdebt and moveOut <= @outdebt
418+
@outdebt -= moveOut
419+
moveOut = 0
423420
else
424421
dent = @indents.pop() + @outdebt
425422
if outdentLength and @chunk[outdentLength] in INDENTABLE_CLOSERS

test/formatting.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,20 @@ test "tabs and spaces cannot be mixed for indentation", ->
287287
ok no
288288
catch e
289289
eq 'mixed indentation', e.message
290+
291+
test "#4487: Handle unusual outdentation", ->
292+
a =
293+
switch 1
294+
when 2
295+
no
296+
when 3 then no
297+
when 1 then yes
298+
eq yes, a
299+
300+
b = do ->
301+
if no
302+
if no
303+
1
304+
2
305+
3
306+
eq b, undefined

0 commit comments

Comments
 (0)