diff --git a/lib/coffee-script/rewriter.js b/lib/coffee-script/rewriter.js index 5447665d..0d1b55da 100644 --- a/lib/coffee-script/rewriter.js +++ b/lib/coffee-script/rewriter.js @@ -358,8 +358,8 @@ var action, condition, indent, outdent, starter; starter = indent = outdent = null; condition = function(token, i) { - var _ref, _ref1; - return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((_ref1 = token[0]) === 'CATCH' || _ref1 === 'FINALLY') && (starter === '->' || starter === '=>')); + var _ref, _ref1, _ref2; + return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'TERMINATOR' && ((_ref1 = this.tag(i + 1)) === 'THEN' || _ref1 === 'ELSE')) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((_ref2 = token[0]) === 'CATCH' || _ref2 === 'FINALLY') && (starter === '->' || starter === '=>')); }; action = function(token, i) { return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent); diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 575cf149..57371984 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -361,6 +361,7 @@ class exports.Rewriter condition = (token, i) -> token[1] isnt ';' and token[0] in SINGLE_CLOSERS and + not (token[0] is 'TERMINATOR' and @tag(i + 1) in ['THEN', 'ELSE']) and not (token[0] is 'ELSE' and starter isnt 'THEN') and not (token[0] in ['CATCH', 'FINALLY'] and starter in ['->', '=>']) diff --git a/test/formatting.coffee b/test/formatting.coffee index 52fcba30..7823de79 100644 --- a/test/formatting.coffee +++ b/test/formatting.coffee @@ -151,3 +151,12 @@ test "#2981: Enforce initial indentation", -> ok no catch e eq 'missing indentation', e.message + +test "'single-line' expression containing multiple lines", -> + doesNotThrow -> CoffeeScript.compile """ + (a, b) -> if a + -a + else if b + then -b + else null + """