Avoid extra call and arg in parseExpression for single-expression case.
This commit is contained in:
parent
41ad304955
commit
f0569147e6
18
acorn.js
18
acorn.js
@ -1837,7 +1837,7 @@
|
||||
return parseForIn(node, init);
|
||||
return parseFor(node, init);
|
||||
}
|
||||
var init = parseExpression(false, true);
|
||||
var init = parseExpression(true);
|
||||
if (tokType === _in || (options.ecmaVersion >= 6 && isContextual("of"))) {
|
||||
checkLVal(init);
|
||||
return parseForIn(node, init);
|
||||
@ -2054,7 +2054,7 @@
|
||||
var decl = startNode();
|
||||
decl.id = parseAssignableAtom();
|
||||
checkLVal(decl.id, true);
|
||||
decl.init = eat(_eq) ? parseExpression(true, noIn) : (kind === _const.keyword ? unexpected() : null);
|
||||
decl.init = eat(_eq) ? parseMaybeAssign(noIn) : (kind === _const.keyword ? unexpected() : null);
|
||||
node.declarations.push(finishNode(decl, "VariableDeclarator"));
|
||||
if (!eat(_comma)) break;
|
||||
}
|
||||
@ -2073,10 +2073,10 @@
|
||||
// sequences (in argument lists, array literals, or object literals)
|
||||
// or the `in` operator (in for loops initalization expressions).
|
||||
|
||||
function parseExpression(noComma, noIn) {
|
||||
function parseExpression(noIn) {
|
||||
var start = storeCurrentPos();
|
||||
var expr = parseMaybeAssign(noIn);
|
||||
if (!noComma && tokType === _comma) {
|
||||
if (tokType === _comma) {
|
||||
var node = startNodeAt(start);
|
||||
node.expressions = [expr];
|
||||
while (eat(_comma)) node.expressions.push(parseMaybeAssign(noIn));
|
||||
@ -2111,9 +2111,9 @@
|
||||
if (eat(_question)) {
|
||||
var node = startNodeAt(start);
|
||||
node.test = expr;
|
||||
node.consequent = parseExpression(true);
|
||||
node.consequent = parseMaybeAssign();
|
||||
expect(_colon);
|
||||
node.alternate = parseExpression(true, noIn);
|
||||
node.alternate = parseMaybeAssign(noIn);
|
||||
return finishNode(node, "ConditionalExpression");
|
||||
}
|
||||
return expr;
|
||||
@ -2514,7 +2514,7 @@
|
||||
var isExpression = allowExpression && tokType !== _braceL;
|
||||
|
||||
if (isExpression) {
|
||||
node.body = parseExpression(true);
|
||||
node.body = parseMaybeAssign();
|
||||
node.expression = true;
|
||||
} else {
|
||||
// Start a new scope with regard to labels and the `inFunction`
|
||||
@ -2637,7 +2637,7 @@
|
||||
} else
|
||||
// export default ...;
|
||||
if (eat(_default)) {
|
||||
node.declaration = parseExpression(true);
|
||||
node.declaration = parseMaybeAssign();
|
||||
node['default'] = true;
|
||||
node.specifiers = null;
|
||||
node.source = null;
|
||||
@ -2755,7 +2755,7 @@
|
||||
node.argument = null;
|
||||
} else {
|
||||
node.delegate = eat(_star);
|
||||
node.argument = parseExpression(true);
|
||||
node.argument = parseMaybeAssign();
|
||||
}
|
||||
return finishNode(node, "YieldExpression");
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@
|
||||
}
|
||||
return parseFor(node, init);
|
||||
}
|
||||
var init = parseExpression(false, true);
|
||||
var init = parseExpression(true);
|
||||
if (token.type === tt._in || isContextual("of")) {
|
||||
return parseForIn(node, checkLVal(init));
|
||||
}
|
||||
@ -539,7 +539,7 @@
|
||||
do {
|
||||
var decl = startNode();
|
||||
decl.id = options.ecmaVersion >= 6 ? toAssignable(parseExprAtom()) : parseIdent();
|
||||
decl.init = eat(tt.eq) ? parseExpression(true, noIn) : null;
|
||||
decl.init = eat(tt.eq) ? parseMaybeAssign(noIn) : null;
|
||||
node.declarations.push(finishNode(decl, "VariableDeclarator"));
|
||||
} while (eat(tt.comma));
|
||||
if (!node.declarations.length) {
|
||||
@ -551,10 +551,10 @@
|
||||
return finishNode(node, "VariableDeclaration");
|
||||
}
|
||||
|
||||
function parseExpression(noComma, noIn) {
|
||||
function parseExpression(noIn) {
|
||||
var start = storeCurrentPos();
|
||||
var expr = parseMaybeAssign(noIn);
|
||||
if (!noComma && token.type === tt.comma) {
|
||||
if (token.type === tt.comma) {
|
||||
var node = startNodeAt(start);
|
||||
node.expressions = [expr];
|
||||
while (eat(tt.comma)) node.expressions.push(parseMaybeAssign(noIn));
|
||||
@ -592,8 +592,8 @@
|
||||
if (eat(tt.question)) {
|
||||
var node = startNodeAt(start);
|
||||
node.test = expr;
|
||||
node.consequent = parseExpression(true);
|
||||
node.alternate = expect(tt.colon) ? parseExpression(true, noIn) : dummyIdent();
|
||||
node.consequent = parseMaybeAssign();
|
||||
node.alternate = expect(tt.colon) ? parseMaybeAssign(noIn) : dummyIdent();
|
||||
return finishNode(node, "ConditionalExpression");
|
||||
}
|
||||
return expr;
|
||||
@ -783,7 +783,7 @@
|
||||
node.argument = null;
|
||||
} else {
|
||||
node.delegate = eat(tt.star);
|
||||
node.argument = parseExpression(true);
|
||||
node.argument = parseMaybeAssign();
|
||||
}
|
||||
return finishNode(node, "YieldExpression");
|
||||
|
||||
@ -871,7 +871,7 @@
|
||||
isGenerator = eat(tt.star);
|
||||
}
|
||||
parsePropertyName(prop);
|
||||
if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
|
||||
if (isDummy(prop.key)) { if (isDummy(parseMaybeAssign())) next(); eat(tt.comma); continue; }
|
||||
if (isClass) {
|
||||
if (prop.key.type === "Identifier" && !prop.computed && prop.key.name === "static" &&
|
||||
(token.type != tt.parenL && token.type != tt.braceL)) {
|
||||
@ -884,7 +884,7 @@
|
||||
}
|
||||
if (!isClass && eat(tt.colon)) {
|
||||
prop.kind = "init";
|
||||
prop.value = parseExpression(true);
|
||||
prop.value = parseMaybeAssign();
|
||||
} else if (options.ecmaVersion >= 6 && (token.type === tt.parenL || token.type === tt.braceL)) {
|
||||
if (isClass) {
|
||||
prop.kind = "";
|
||||
@ -1029,7 +1029,7 @@
|
||||
node.params = parseFunctionParams();
|
||||
node.generator = isGenerator || false;
|
||||
node.expression = options.ecmaVersion >= 6 && token.type !== tt.braceL;
|
||||
node.body = node.expression ? parseExpression(true) : parseBlock();
|
||||
node.body = node.expression ? parseMaybeAssign() : parseBlock();
|
||||
return finishNode(node, "FunctionExpression");
|
||||
}
|
||||
|
||||
@ -1037,7 +1037,7 @@
|
||||
initFunction(node);
|
||||
node.params = toAssignableList(params);
|
||||
node.expression = token.type !== tt.braceL;
|
||||
node.body = node.expression ? parseExpression(true) : parseBlock();
|
||||
node.body = node.expression ? parseMaybeAssign() : parseBlock();
|
||||
return finishNode(node, "ArrowFunctionExpression");
|
||||
}
|
||||
|
||||
@ -1124,7 +1124,7 @@
|
||||
elts.push(allowEmpty ? null : dummyIdent());
|
||||
continue;
|
||||
}
|
||||
var elt = parseExpression(true);
|
||||
var elt = parseMaybeAssign();
|
||||
if (isDummy(elt)) {
|
||||
if (closes(close, indent, line)) break;
|
||||
next();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user