From 863f3f6b47489ada35a42c2dce1715c062d02742 Mon Sep 17 00:00:00 2001 From: satyr Date: Tue, 26 Oct 2010 00:56:03 +0900 Subject: [PATCH] rewriter: `(a): (b): (c)` is now allowed --- lib/rewriter.js | 10 +++------- src/rewriter.coffee | 13 +++++++------ test/test_literals.coffee | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/rewriter.js b/lib/rewriter.js index 581821b9..c9336f27 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -153,7 +153,7 @@ return this.tokens.splice(i, 0, ['}', '}', token[2]]); }; return this.scanTokens(function(token, i, tokens) { - var _ref, _ref2, ago2, idx, tag, tok; + var _ref, _ref2, ago1, ago2, idx, tag, tok; if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) { stack.push([(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag), i]); return 1; @@ -162,15 +162,11 @@ start = stack.pop(); return 1; } - if (tag !== ':') { - return 1; - } - ago2 = this.tag(i - 2); - if (!(ago2 === ':' || ((_ref2 = stack[stack.length - 1]) != null ? _ref2[0] : undefined) !== '{')) { + if (!(tag === ':' && ((ago2 = this.tag(i - 2)) === ':' || (ago1 = this.tag(i - 1)) === ')' && this.tag(start[1] - 1) === ':' || ((_ref2 = stack[stack.length - 1]) != null ? _ref2[0] : undefined) !== '{'))) { return 1; } stack.push(['{']); - idx = ago2 === '@' ? i - 2 : this.tag(i - 1) === ')' ? start[1] : i - 1; + idx = ago1 === ')' ? start[1] : ago2 === '@' ? i - 2 : i - 1; if (this.tag(idx - 2) === 'HERECOMMENT') { idx -= 2; } diff --git a/src/rewriter.coffee b/src/rewriter.coffee index fcae9130..0afb5d5c 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -134,14 +134,15 @@ class exports.Rewriter if tag in EXPRESSION_END start = stack.pop() return 1 - return 1 unless tag is ':' - ago2 = @tag i - 2 - return 1 unless ago2 is ':' or stack[stack.length - 1]?[0] isnt '{' + return 1 unless tag is ':' and + ((ago2 = @tag i - 2) is ':' or + (ago1 = @tag i - 1) is ')' and @tag(start[1] - 1) is ':' or + stack[stack.length - 1]?[0] isnt '{') stack.push ['{'] - idx = if ago2 is '@' - i - 2 - else if @tag(i - 1) is ')' + idx = if ago1 is ')' start[1] + else if ago2 is '@' + i - 2 else i - 1 idx -= 2 if @tag(idx - 2) is 'HERECOMMENT' diff --git a/test/test_literals.coffee b/test/test_literals.coffee index 8ac45125..8376e8d9 100644 --- a/test/test_literals.coffee +++ b/test/test_literals.coffee @@ -232,13 +232,13 @@ eq result.two, obj.list()[1] i = 0 obj = { ### leading comment ### - "interpolated#{'key'}": 123 (4 * 2): 8 ### cached shorthand ### (++i) + "#{'interpolated'}": """#{"key"}""": 123 ### traling comment ### } -eq obj.interpolatedkey, 123 +eq obj.interpolated.key, 123 eq obj[8], 8 eq obj[1], 1