1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix #4487: Outdentation bug (#4488)

This commit is contained in:
Julian Rosse 2017-04-08 16:12:55 -04:00 committed by Geoffrey Booth
parent b192e215a5
commit 76945ab458
3 changed files with 23 additions and 12 deletions

View file

@ -474,12 +474,9 @@
lastIndent = this.indents[this.indents.length - 1];
if (!lastIndent) {
moveOut = 0;
} else if (lastIndent === this.outdebt) {
moveOut -= this.outdebt;
this.outdebt = 0;
} else if (lastIndent < this.outdebt) {
this.outdebt -= lastIndent;
moveOut -= lastIndent;
} else if (this.outdebt && moveOut <= this.outdebt) {
this.outdebt -= moveOut;
moveOut = 0;
} else {
dent = this.indents.pop() + this.outdebt;
if (outdentLength && (ref = this.chunk[outdentLength], indexOf.call(INDENTABLE_CLOSERS, ref) >= 0)) {

View file

@ -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

View file

@ -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