mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
rewriter: (a): (b): (c)
is now allowed
This commit is contained in:
parent
ff82c59903
commit
863f3f6b47
3 changed files with 12 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue