Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

be more flexible about trailing commas in implicit object literals.

  • Loading branch information...
commit 17bf3b7115813a651cec7a8faad1f537a8823fa1 1 parent ff9af83
@jashkenas jashkenas authored
View
2  extras/coffee-script.js
1 addition, 1 deletion not shown
View
4 lib/rewriter.js
@@ -134,9 +134,9 @@
before = this.tokens[i - 2];
after = this.tokens[i + 2];
open = stack[len] > 0;
- if ((tag === 'TERMINATOR' && !((after && after[0] === ':') || (post && post[0] === '@' && this.tokens[i + 3] && this.tokens[i + 3][0] === ':'))) || (running && tag === ',' && post && (!('IDENTIFIER' === (_c = post[0]) || 'STRING' === _c || '@' === _c)))) {
+ if ((tag === 'TERMINATOR' && !((after && after[0] === ':') || (post && post[0] === '@' && this.tokens[i + 3] && this.tokens[i + 3][0] === ':'))) || (running && tag === ',' && post && (!('IDENTIFIER' === (_c = post[0]) || 'STRING' === _c || '@' === _c || 'TERMINATOR' === _c)))) {
running = false;
- return closeBrackets(i);
+ return closeBrackets(post && post[0] === 'OUTDENT' ? i + 1 : i);
} else if (include(EXPRESSION_START, tag)) {
stack.push(tag === '{' ? 1 : 0);
if (tag === '{' && post && post[0] === 'INDENT') {
View
4 src/rewriter.coffee
@@ -133,9 +133,9 @@ exports.Rewriter = class Rewriter
after = @tokens[i + 2]
open = stack[len] > 0
if (tag is 'TERMINATOR' and not ((after and after[0] is ':') or (post and post[0] is '@' and @tokens[i + 3] and @tokens[i + 3][0] is ':'))) or
- (running and tag is ',' and post and (post[0] not in ['IDENTIFIER', 'STRING', '@']))
+ (running and tag is ',' and post and (post[0] not in ['IDENTIFIER', 'STRING', '@', 'TERMINATOR']))
running = no
- return closeBrackets(i)
+ return closeBrackets(if post and post[0] is 'OUTDENT' then i + 1 else i)
else if include EXPRESSION_START, tag
stack.push(if tag is '{' then 1 else 0)
return 2 if tag is '{' and post and post[0] is 'INDENT'
View
7 test/test_literals.coffee
@@ -140,6 +140,13 @@ obj =
ok obj.a is 1
ok obj.b is 2
+obj =
+ a: 1,
+ b: 2,
+
+ok obj.a is 1
+ok obj.b is 2
+
# Implicit objects nesting.
obj =
Please sign in to comment.
Something went wrong with that request. Please try again.