Fixing the longstanding and important Issue #637. I'm glad this one got got.

This commit is contained in:
Jeremy Ashkenas
2010-08-21 12:13:43 -04:00
parent 143c4d5efc
commit d5d5de55ae
4 changed files with 32 additions and 6 deletions

View File

@@ -254,10 +254,10 @@
if (noNewlines) { if (noNewlines) {
return this.suppressNewlines(); return this.suppressNewlines();
} }
this.outdebt = 0; diff = size - this.indent + this.outdebt;
diff = size - this.indent;
this.token('INDENT', diff); this.token('INDENT', diff);
this.indents.push(diff); this.indents.push(diff);
this.outdebt = 0;
} else { } else {
this.outdentToken(this.indent - size, noNewlines); this.outdentToken(this.indent - size, noNewlines);
} }

View File

@@ -209,10 +209,10 @@ exports.Lexer = class Lexer
return @newlineToken indent return @newlineToken indent
else if size > @indent else if size > @indent
return @suppressNewlines() if noNewlines return @suppressNewlines() if noNewlines
@outdebt = 0 diff = size - @indent + @outdebt
diff = size - @indent
@token 'INDENT', diff @token 'INDENT', diff
@indents.push diff @indents.push diff
@outdebt = 0
else else
@outdentToken @indent - size, noNewlines @outdentToken @indent - size, noNewlines
@indent = size @indent = size

View File

@@ -8,11 +8,10 @@ ok results.join(' ') is '1 4 9'
# Chained blocks, with proper indentation levels: # Chained blocks, with proper indentation levels:
results = [] results = []
counter = { counter =
tick: (func) -> tick: (func) ->
results.push func() results.push func()
this this
}
counter counter
.tick -> .tick ->
@@ -53,3 +52,17 @@ obj
) )
ok result is 3 ok result is 3
# Test newline-supressed call chains with nested functions.
obj =
call: -> this
func = ->
obj
.call ->
one two
.call ->
three four
101
ok func() is 101

View File

@@ -96,3 +96,16 @@ catch e
x = 1 x = 1
result = x + if false then 10 else 1 result = x + if false then 10 else 1
ok result is 2 ok result is 2
# If/else indented within an assignment.
func = ->
a =
if false
3
else
5
101
a
ok func() is 5