From 1aed9c545f526aaab5328bc9d69bd8f32b08b316 Mon Sep 17 00:00:00 2001 From: Greg Fodor Date: Sun, 18 Apr 2010 00:41:47 -0400 Subject: [PATCH] Fix for bug with chaining --- src/rewriter.coffee | 11 ++++++++++- test/test_chaining.coffee | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 40b57390..8ebe38ff 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -231,7 +231,16 @@ exports.Rewriter: class Rewriter return 1 if tag is INVERSES[mtag] debt[mtag]: + 1 val: if mtag is 'INDENT' then match[1] else INVERSES[mtag] - @tokens.splice i, 0, [INVERSES[mtag], val] + + # Edge case, lookahead and if we are inserting in front of a + # subsequent opening token, insert ahead of it and re-queue onto + # stack. + if @tokens[i + 2]?[0] == mtag + @tokens.splice i + 3, 0, [INVERSES[mtag], val] + stack.push(match) + else + @tokens.splice i, 0, [INVERSES[mtag], val] + return 1 else return 1 diff --git a/test/test_chaining.coffee b/test/test_chaining.coffee index 7df92699..30a618c3 100644 --- a/test/test_chaining.coffee +++ b/test/test_chaining.coffee @@ -33,4 +33,14 @@ six: 2 + 3 -ok six is 6 \ No newline at end of file +ok six is 6 + +# Bug due to rewriting issue with indented array literals +func: () -> + ok arguments.length is 1 + +func( + [[[[[], + []], + [[]]]], + []])