Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,9 @@ exports.Lexer = class Lexer
lastIndent = @indents[@indents.length - 1]
if not lastIndent
moveOut = 0
else if lastIndent is @outdebt
moveOut -= @outdebt
@outdebt = 0
else if lastIndent < @outdebt
@outdebt -= lastIndent
moveOut -= lastIndent
else if @outdebt and moveOut <= @outdebt
@outdebt -= moveOut
moveOut = 0
else
dent = @indents.pop() + @outdebt
if outdentLength and @chunk[outdentLength] in INDENTABLE_CLOSERS
Expand Down
17 changes: 17 additions & 0 deletions test/formatting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,20 @@ test "tabs and spaces cannot be mixed for indentation", ->
ok no
catch e
eq 'mixed indentation', e.message

test "#4487: Handle unusual outdentation", ->
a =
switch 1
when 2
no
when 3 then no
when 1 then yes
eq yes, a

b = do ->
if no
if no
1
2
3
eq b, undefined