Skip to content

Commit

Permalink
be more flexible about trailing commas in implicit object literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Aug 5, 2010
1 parent ff9af83 commit 17bf3b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion extras/coffee-script.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions test/test_literals.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 17bf3b7

Please sign in to comment.