1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

#2757, Allow non-significant commas at end of nested implicit objects

This commit is contained in:
Troels Nielsen 2013-03-04 12:52:47 +01:00
parent 56fe211b79
commit 37a6ea63b1
3 changed files with 35 additions and 12 deletions

View file

@ -162,7 +162,7 @@
var stack;
stack = [];
return this.scanTokens(function(token, i, tokens) {
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, nextTag, prevTag, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, nextTag, offset, prevTag, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
tag = token[0];
prevTag = (i > 0 ? tokens[i - 1] : [])[0];
nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0];
@ -225,9 +225,10 @@
return i += 1;
}
};
endImplicitObject = function() {
endImplicitObject = function(j) {
j = j != null ? j : i;
stack.pop();
tokens.splice(i, 0, generate('}', '}'));
tokens.splice(j, 0, generate('}', '}'));
return i += 1;
};
if (inImplicitCall() && (tag === 'IF' || tag === 'TRY' || tag === 'FINALLY' || tag === 'CATCH' || tag === 'CLASS' || tag === 'SWITCH')) {
@ -319,11 +320,9 @@
}
}
if (tag === ',' && !this.looksObjectish(i + 1) && inImplicitObject() && (nextTag !== 'TERMINATOR' || !this.looksObjectish(i + 2))) {
if (nextTag === 'OUTDENT') {
i += 1;
}
offset = nextTag === 'OUTDENT' ? 1 : 0;
while (inImplicitObject()) {
endImplicitObject();
endImplicitObject(i + offset);
}
}
return forward(1);

View file

@ -173,9 +173,10 @@ class exports.Rewriter
tokens.splice idx, 0, generate '{', generate(new String('{'))
i += 1 if not j?
endImplicitObject = ->
endImplicitObject = (j) ->
j = j ? i
stack.pop()
tokens.splice i, 0, generate '}', '}'
tokens.splice j, 0, generate '}', '}'
i += 1
# Don't end an implicit call on next indent if any of these are in an argument
@ -313,10 +314,10 @@ class exports.Rewriter
#
# When it isn't the comma go on to play a role in a call or
# array further up the stack, so give it a chance.
if nextTag is 'OUTDENT'
i += 1
offset = if nextTag is 'OUTDENT' then 1 else 0
while inImplicitObject()
endImplicitObject()
endImplicitObject i + offset
return forward(1)
# Add location data to all tokens generated by the rewriter.

View file

@ -323,6 +323,29 @@ test "#2549, Brace-less Object Literal as a Second Operand on a New Line", ->
two: 2
eq baz.two, 2
test "#2757, Nested", ->
foo =
bar:
one: 1,
eq foo.bar.one, 1
baz =
qux:
one: 1,
corge:
two: 2,
three: three: three: 3,
xyzzy:
thud:
four:
four: 4,
five: 5,
eq baz.qux.one, 1
eq baz.corge.three.three.three, 3
eq baz.xyzzy.thud.four.four, 4
eq baz.xyzzy.five, 5
test "#1865, syntax regression 1.1.3", ->
foo = (x, y) -> y