diff -r 3bf7c007883d -r b67697fba413 src/Parser.cpp --- a/src/Parser.cpp Sun Aug 05 12:55:51 2012 -0700 +++ b/src/Parser.cpp Sun Aug 05 14:19:05 2012 -0700 @@ -641,7 +641,7 @@ if (match(TOK_NEW)) { if (!enterScope(Scope::BLOCK)) return NULL; - if ((decl = variableDeclaration(TOK_NEW)) == NULL) + if ((decl = vars(TOK_NEW)) == NULL) return NULL; } else { if ((decl = expressionStatement()) == NULL) @@ -682,7 +682,7 @@ scope_ = scope_->enclosing(); Scope *declScope = NULL; - if (decl && decl->isVariableDeclaration()) { + if (decl && (decl->isVariableDeclaration() || decl->isBlockStatement())) { declScope = scope_->unlinkIfEmpty(); scope_ = scope_->enclosing(); } @@ -709,7 +709,7 @@ } VariableDeclaration * -Parser::variableDeclaration(TokenKind kind) +Parser::var(TokenKind kind) { Local tag(zone_); if (matchName(tag.ref(), TOK_LABEL) && !tag) @@ -748,6 +748,32 @@ } Statement * +Parser::vars(TokenKind kind) +{ + VariableDeclaration *decl = var(kind); + if (!decl) + return NULL; + + if (!peek(TOK_COMMA)) + return decl; + + StatementList *statements = new (pool_) StatementList(); + if (!statements->append(decl)) + return NULL; + + while (match(TOK_COMMA)) { + Statement *decl = var(kind); + if (!decl) + return NULL; + if (!statements->append(decl)) + return NULL; + } + + // Create a fake-o block with no scope to create a statement list. + return new (pool_) BlockStatement(decl->pos(), NULL, statements); +} + +Statement * Parser::returnStatement() { SourcePosition pos = scanner_.begin(); @@ -873,7 +899,7 @@ case TOK_CONST: case TOK_NEW: scanner_.scan(); - if ((statement = variableDeclaration(kind)) == NULL) + if ((statement = vars(kind)) == NULL) return NULL; break; @@ -1270,8 +1296,11 @@ case TOK_CONST: case TOK_NEW: { + // Note: at global scope, we don't accept comma-delimited + // declarations yet, to see if we can get away with forcing + // a nicer top-level style. scanner_.scan(); - if ((statement = variableDeclaration(kind)) == NULL) + if ((statement = var(kind)) == NULL) return NULL; if (!matchSemicolon()) return NULL;