Permalink
Browse files

be more flexible about trailing commas in implicit object literals.

  • Loading branch information...
1 parent ff9af83 commit 17bf3b7115813a651cec7a8faad1f537a8823fa1 @jashkenas jashkenas committed Aug 5, 2010
Showing with 12 additions and 5 deletions.
  1. +1 −1 extras/coffee-script.js
  2. +2 −2 lib/rewriter.js
  3. +2 −2 src/rewriter.coffee
  4. +7 −0 test/test_literals.coffee
View
Oops, something went wrong.
View
@@ -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
@@ -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'
@@ -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 =

0 comments on commit 17bf3b7

Please sign in to comment.