From d5d5de55aee0557c93863675eca8bf021b4d18c2 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 21 Aug 2010 12:13:43 -0400 Subject: [PATCH] Fixing the longstanding and important Issue #637. I'm glad this one got got. --- lib/lexer.js | 4 ++-- src/lexer.coffee | 4 ++-- test/test_blocks.coffee | 17 +++++++++++++++-- test/test_if.coffee | 13 +++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/lexer.js b/lib/lexer.js index 0fc14518..77717bf7 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -254,10 +254,10 @@ if (noNewlines) { return this.suppressNewlines(); } - this.outdebt = 0; - diff = size - this.indent; + diff = size - this.indent + this.outdebt; this.token('INDENT', diff); this.indents.push(diff); + this.outdebt = 0; } else { this.outdentToken(this.indent - size, noNewlines); } diff --git a/src/lexer.coffee b/src/lexer.coffee index fcb4756a..7f77b6e7 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -209,10 +209,10 @@ exports.Lexer = class Lexer return @newlineToken indent else if size > @indent return @suppressNewlines() if noNewlines - @outdebt = 0 - diff = size - @indent + diff = size - @indent + @outdebt @token 'INDENT', diff @indents.push diff + @outdebt = 0 else @outdentToken @indent - size, noNewlines @indent = size diff --git a/test/test_blocks.coffee b/test/test_blocks.coffee index d71cd2c3..2405ec16 100644 --- a/test/test_blocks.coffee +++ b/test/test_blocks.coffee @@ -8,11 +8,10 @@ ok results.join(' ') is '1 4 9' # Chained blocks, with proper indentation levels: results = [] -counter = { +counter = tick: (func) -> results.push func() this -} counter .tick -> @@ -53,3 +52,17 @@ obj ) 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 diff --git a/test/test_if.coffee b/test/test_if.coffee index a79c073c..e5bfc59d 100644 --- a/test/test_if.coffee +++ b/test/test_if.coffee @@ -96,3 +96,16 @@ catch e x = 1 result = x + if false then 10 else 1 ok result is 2 + + +# If/else indented within an assignment. +func = -> + a = + if false + 3 + else + 5 + 101 + a + +ok func() is 5