Skip to content

Commit

Permalink
Fix #4487: Outdentation bug (#4488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Rosse authored and GeoffreyBooth committed Apr 8, 2017
1 parent b192e21 commit 76945ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
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

0 comments on commit 76945ab

Please sign in to comment.