diff --git a/lib/rewriter.js b/lib/rewriter.js index 149ee6cd..dec7f5f6 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -50,10 +50,13 @@ this.tokens.splice(i + 2, 1); before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after); } else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) { - post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT' ? this.tokens.splice.apply(this.tokens, [i, 0].concat(this.tokens.splice(i + 2, 2))) : this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]); + if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') { + this.tokens.splice.apply(this.tokens, [i + 3, 0].concat(this.tokens.splice(i, 2))); + this.tokens.splice(i + 3, 0, ['TERMINATOR', "\n", prev[2]]); + } else { + this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]); + } return 2; - } else if (before && before[0] === 'OUTDENT' && prev && prev[0] === 'TERMINATOR' && post && post[0] === 'TERMINATOR' && after && after[0] === 'ELSE') { - this.tokens.splice(i + 1, 0, this.tokens.splice(i - 2, 1)[0]); } return 1; }; diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 90a6e804..95a08da3 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -63,13 +63,11 @@ exports.Rewriter: class Rewriter @tokens.splice i, 0, after else if prev and prev[0] not in ['TERMINATOR', 'INDENT', 'OUTDENT'] if post and post[0] is 'TERMINATOR' and after and after[0] is 'OUTDENT' - @tokens.splice(i, 0, @tokens.splice(i + 2, 2)...) + @tokens.splice(i + 3, 0, @tokens.splice(i, 2)...) + @tokens.splice(i + 3, 0, ['TERMINATOR', "\n", prev[2]]) else @tokens.splice i, 0, ['TERMINATOR', "\n", prev[2]] return 2 - else if before and before[0] is 'OUTDENT' and prev and prev[0] is 'TERMINATOR' and - post and post[0] is 'TERMINATOR' and after and after[0] is 'ELSE' - @tokens.splice i + 1, 0, @tokens.splice(i - 2, 1)[0] return 1 # Leading newlines would introduce an ambiguity in the grammar, so we diff --git a/test/test_comments.coffee b/test/test_comments.coffee index ab5e8f0e..a1e54249 100644 --- a/test/test_comments.coffee +++ b/test/test_comments.coffee @@ -66,6 +66,23 @@ func: -> ### code +func: -> + one: -> + two: -> + three: -> + ### + block. + ### + four: -> + +fn1: -> + oneLevel: null +### +This isn't fine. +### + +ok ok + obj: { a: 'b' ###