be more flexible about trailing commas in implicit object literals.

This commit is contained in:
Jeremy Ashkenas
2010-08-04 23:25:30 -04:00
parent ff9af83358
commit 17bf3b7115
4 changed files with 12 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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 File

@@ -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 File

@@ -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 =