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