From eba8a5646cde0bdd3f2d7a44c946f977cbe834f7 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sun, 26 Oct 2014 23:14:06 +0200 Subject: [PATCH] Loose: added support for holes in arrays (but disallows trailing comma). --- acorn_loose.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/acorn_loose.js b/acorn_loose.js index b0b73b00df..87cdbd552c 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -702,7 +702,7 @@ case tt.bracketL: var node = startNode(); pushCx(); - node.elements = parseExprList(tt.bracketR); + node.elements = parseExprList(tt.bracketR, true); return finishNode(node, "ArrayExpression"); case tt.braceL: @@ -861,11 +861,15 @@ return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); } - function parseExprList(close) { + function parseExprList(close, allowEmpty) { var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart; next(); // Opening bracket if (curLineStart > continuedLine) continuedLine = curLineStart; while (!closes(close, indent + (curLineStart <= continuedLine ? 1 : 0), line)) { + if (allowEmpty && eat(tt.comma)) { + elts.push(null); + continue; + } var elt = parseExpression(true); if (isDummy(elt)) { if (closes(close, indent, line)) break; @@ -873,7 +877,7 @@ } else { elts.push(elt); } - while (eat(tt.comma)) {} + eat(tt.comma); } popCx(); eat(close);