Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Remove noArrowParamsConversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 25, 2017
1 parent 74ef24e commit 8541f2c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 61 deletions.
66 changes: 29 additions & 37 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class ExpressionParser extends LValParser {
// Parse an assignment expression. This includes applications of
// operators like `+=`.

parseMaybeAssign(noIn?: ?boolean, refShorthandDefaultPos?: ?Pos, afterLeftParse?: Function, refNeedsArrowPos?: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseMaybeAssign(noIn?: ?boolean, refShorthandDefaultPos?: ?Pos, afterLeftParse?: Function, refNeedsArrowPos?: ?Pos): N.Expression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
if (this.match(tt._yield) && this.state.inGenerator) {
Expand All @@ -117,7 +117,7 @@ export default class ExpressionParser extends LValParser {
this.state.potentialArrowAt = this.state.start;
}

let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos, noArrowParamsConversion);
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos);
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
if (this.state.type.isAssign) {
const node = this.startNodeAt(startPos, startLoc);
Expand Down Expand Up @@ -151,13 +151,13 @@ export default class ExpressionParser extends LValParser {

// Parse a ternary conditional (`?:`) operator.

parseMaybeConditional(noIn: ?boolean, refShorthandDefaultPos: Pos, refNeedsArrowPos?: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseMaybeConditional(noIn: ?boolean, refShorthandDefaultPos: Pos, refNeedsArrowPos?: ?Pos): N.Expression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const expr = this.parseExprOps(noIn, refShorthandDefaultPos, noArrowParamsConversion);
const expr = this.parseExprOps(noIn, refShorthandDefaultPos);
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;

return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos, noArrowParamsConversion);
return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos);
}

parseConditional(
Expand All @@ -167,9 +167,7 @@ export default class ExpressionParser extends LValParser {
startLoc: Position,
// FIXME: Disabling this for now since can't seem to get it to play nicely
// eslint-disable-next-line no-unused-vars
refNeedsArrowPos?: ?Pos,
// eslint-disable-next-line no-unused-vars
noArrowParamsConversion?: boolean
refNeedsArrowPos?: ?Pos
): N.Expression {
if (this.eat(tt.question)) {
const node = this.startNodeAt(startPos, startLoc);
Expand All @@ -184,10 +182,10 @@ export default class ExpressionParser extends LValParser {

// Start the precedence parser.

parseExprOps(noIn: ?boolean, refShorthandDefaultPos: Pos, noArrowParamsConversion?: boolean): N.Expression {
parseExprOps(noIn: ?boolean, refShorthandDefaultPos: Pos): N.Expression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const expr = this.parseMaybeUnary(refShorthandDefaultPos, noArrowParamsConversion);
const expr = this.parseMaybeUnary(refShorthandDefaultPos);
if (refShorthandDefaultPos && refShorthandDefaultPos.start) {
return expr;
} else {
Expand Down Expand Up @@ -235,7 +233,7 @@ export default class ExpressionParser extends LValParser {

// Parse unary operators, both prefix and postfix.

parseMaybeUnary(refShorthandDefaultPos: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseMaybeUnary(refShorthandDefaultPos: ?Pos): N.Expression {
if (this.state.type.prefix) {
const node = this.startNode();
const update = this.match(tt.incDec);
Expand Down Expand Up @@ -263,7 +261,7 @@ export default class ExpressionParser extends LValParser {

const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr = this.parseExprSubscripts(refShorthandDefaultPos, noArrowParamsConversion);
let expr = this.parseExprSubscripts(refShorthandDefaultPos);
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
while (this.state.type.postfix && !this.canInsertSemicolon()) {
const node = this.startNodeAt(startPos, startLoc);
Expand All @@ -279,11 +277,11 @@ export default class ExpressionParser extends LValParser {

// Parse call, dot, and `[]`-subscript expressions.

parseExprSubscripts(refShorthandDefaultPos: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseExprSubscripts(refShorthandDefaultPos: ?Pos): N.Expression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const potentialArrowAt = this.state.potentialArrowAt;
const expr = this.parseExprAtom(refShorthandDefaultPos, noArrowParamsConversion);
const expr = this.parseExprAtom(refShorthandDefaultPos);

if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) {
return expr;
Expand All @@ -293,10 +291,10 @@ export default class ExpressionParser extends LValParser {
return expr;
}

return this.parseSubscripts(expr, startPos, startLoc, undefined, noArrowParamsConversion);
return this.parseSubscripts(expr, startPos, startLoc);
}

parseSubscripts(base: N.Expression, startPos: number, startLoc: Position, noCalls?: boolean, noArrowParamsConversion?: ?boolean): N.Expression {
parseSubscripts(base: N.Expression, startPos: number, startLoc: Position, noCalls?: boolean): N.Expression {
for (;;) {
if (!noCalls && this.eat(tt.doubleColon)) {
const node = this.startNodeAt(startPos, startLoc);
Expand Down Expand Up @@ -374,7 +372,7 @@ export default class ExpressionParser extends LValParser {
base = this.finishNode(node, "CallExpression");

if (possibleAsync && this.shouldParseAsyncArrow()) {
return this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node, noArrowParamsConversion);
return this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node);
} else {
this.toReferencedList(node.arguments);
}
Expand Down Expand Up @@ -424,9 +422,9 @@ export default class ExpressionParser extends LValParser {
return this.match(tt.arrow);
}

parseAsyncArrowFromCallExpression(node: N.ArrowFunctionExpression, call: N.CallExpression, noArrowParamsConversion?: boolean): N.ArrowFunctionExpression {
parseAsyncArrowFromCallExpression(node: N.ArrowFunctionExpression, call: N.CallExpression): N.ArrowFunctionExpression {
this.expect(tt.arrow);
return this.parseArrowExpression(node, call.arguments, true, noArrowParamsConversion);
return this.parseArrowExpression(node, call.arguments, true);
}

// Parse a no-call expression (like argument of `new` or `::` operators).
Expand All @@ -442,7 +440,7 @@ export default class ExpressionParser extends LValParser {
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
// or `{}`.

parseExprAtom(refShorthandDefaultPos?: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression {
const canBeArrow = this.state.potentialArrowAt === this.state.start;
let node;

Expand Down Expand Up @@ -509,7 +507,7 @@ export default class ExpressionParser extends LValParser {
}

if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
return this.parseArrowExpression(node, [id], undefined, noArrowParamsConversion);
return this.parseArrowExpression(node, [id]);
}

return id;
Expand Down Expand Up @@ -553,7 +551,7 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "BooleanLiteral");

case tt.parenL:
return this.parseParenAndDistinguishExpression(canBeArrow, noArrowParamsConversion);
return this.parseParenAndDistinguishExpression(canBeArrow);

case tt.bracketL:
node = this.startNode();
Expand Down Expand Up @@ -667,7 +665,7 @@ export default class ExpressionParser extends LValParser {
return val;
}

parseParenAndDistinguishExpression(canBeArrow: boolean, noArrowParamsConversion?: boolean): N.Expression {
parseParenAndDistinguishExpression(canBeArrow: boolean): N.Expression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;

Expand Down Expand Up @@ -715,7 +713,7 @@ export default class ExpressionParser extends LValParser {
if (param.extra && param.extra.parenthesized) this.unexpected(param.extra.parenStart);
}

return this.parseArrowExpression(arrowNode, exprList, false, noArrowParamsConversion);
return this.parseArrowExpression(arrowNode, exprList);
}

if (!exprList.length) {
Expand Down Expand Up @@ -1055,19 +1053,14 @@ export default class ExpressionParser extends LValParser {

// Parse arrow function expression with given parameters.

parseArrowExpression(node: N.ArrowFunctionExpression, params: N.Expression[], isAsync?: boolean, noArrowParamsConversion?: boolean): N.ArrowFunctionExpression {
parseArrowExpression(node: N.ArrowFunctionExpression, params: N.Expression[], isAsync?: boolean): N.ArrowFunctionExpression {
this.initFunction(node, isAsync);
this.setArrowFunctionParameters(node, params, noArrowParamsConversion);
this.parseFunctionBody(node, true, noArrowParamsConversion);
this.setArrowFunctionParameters(node, params);
this.parseFunctionBody(node, true);
return this.finishNode(node, "ArrowFunctionExpression");
}

setArrowFunctionParameters(
node: N.ArrowFunctionExpression,
params: N.Expression[],
// eslint-disable-next-line no-unused-vars
noArrowParamsConversion?: boolean
): N.ArrowFunctionExpression {
setArrowFunctionParameters(node: N.ArrowFunctionExpression, params: N.Expression[]): N.ArrowFunctionExpression {
node.params = this.toAssignableList(params, true, "arrow function parameters");
}

Expand All @@ -1084,13 +1077,13 @@ export default class ExpressionParser extends LValParser {
}

// Parse function body and check parameters.
parseFunctionBody(node: N.Function, allowExpression?: boolean, noArrowParamsConversion?: boolean): void {
parseFunctionBody(node: N.Function, allowExpression?: boolean): void {
const isExpression = allowExpression && !this.match(tt.braceL);

const oldInAsync = this.state.inAsync;
this.state.inAsync = node.async;
if (isExpression) {
node.body = this.parseMaybeAssign(undefined, undefined, undefined, undefined, noArrowParamsConversion);
node.body = this.parseMaybeAssign();
node.expression = true;
} else {
// Start a new scope with regard to labels and the `inFunction`
Expand All @@ -1116,6 +1109,7 @@ export default class ExpressionParser extends LValParser {
// are not repeated, and it does not try to bind the words `eval`
// or `arguments`.
const isStrict = this.isStrictBody(node, node.expression);
// Also check for arrow functions
const checkLVal = this.state.strict || isStrict || isArrowFunction;

if (isStrict && node.id && node.id.type === "Identifier" && node.id.name === "yield") {
Expand All @@ -1125,7 +1119,6 @@ export default class ExpressionParser extends LValParser {
if (checkLVal) {
const nameHash = Object.create(null);
const oldStrict = this.state.strict;

if (isStrict) this.state.strict = true;
if (node.id) {
this.checkLVal(node.id, true, undefined, "function name");
Expand All @@ -1136,7 +1129,6 @@ export default class ExpressionParser extends LValParser {
}
this.checkLVal(param, true, nameHash, "function parameter list");
}

this.state.strict = oldStrict;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
classBody.body.push(this.finishNode(method, "MethodDefinition"));
}

parseExprAtom(refShorthandDefaultPos?: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression {
switch (this.state.type) {
case tt.regexp:
return this.estreeParseRegExpLiteral(this.state.value);
Expand All @@ -183,7 +183,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return this.estreeParseLiteral(false);

default:
return super.parseExprAtom(refShorthandDefaultPos, noArrowParamsConversion);
return super.parseExprAtom(refShorthandDefaultPos);
}
}

Expand Down
36 changes: 16 additions & 20 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
// Overrides
// ==================================

parseFunctionBody(node: N.Function, allowExpression?: boolean, noArrowParamsConversion?: boolean): void {
parseFunctionBody(node: N.Function, allowExpression?: boolean): void {
if (allowExpression && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
this.state.noArrowParamsConversionAt.push(this.state.start);
super.parseFunctionBody(node, allowExpression);
Expand All @@ -1036,7 +1036,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
: null;
}

return super.parseFunctionBody(node, allowExpression, noArrowParamsConversion);
return super.parseFunctionBody(node, allowExpression);
}

// interfaces
Expand Down Expand Up @@ -1088,7 +1088,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return super.isExportDefaultSpecifier();
}

parseConditional(expr: N.Expression, noIn: ?boolean, startPos: number, startLoc: Position, refNeedsArrowPos?: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseConditional(expr: N.Expression, noIn: ?boolean, startPos: number, startLoc: Position, refNeedsArrowPos?: ?Pos): N.Expression {
if (!this.match(tt.question)) return expr;

// only do the expensive clone if there is a question mark
Expand Down Expand Up @@ -1158,7 +1158,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
node.test = expr;
node.consequent = consequent;
node.alternate = this.forwardNoArrowParamsConversionAt(node, () => (
this.parseMaybeAssign(noIn, undefined, undefined, undefined, noArrowParamsConversion)
this.parseMaybeAssign(noIn, undefined, undefined, undefined)
));

return this.finishNode(node, "ConditionalExpression");
Expand All @@ -1167,10 +1167,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
tryParseConditionalConsequent(): { consequent: N.Expression, failed: boolean } {
this.state.noArrowParamsConversionAt.push(this.state.start);

const consequent = this.parseMaybeAssign(
undefined, undefined, undefined, undefined,
/* noArrowParamsConversion */ true
);
const consequent = this.parseMaybeAssign();
const failed = !this.match(tt.colon);

this.state.noArrowParamsConversionAt.pop();
Expand Down Expand Up @@ -1598,15 +1595,15 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
}

// parse the return type of an async arrow function - let foo = (async (): number => {});
parseAsyncArrowFromCallExpression(node: N.ArrowFunctionExpression, call: N.CallExpression, noArrowParamsConversion?: ?boolean): N.ArrowFunctionExpression {
parseAsyncArrowFromCallExpression(node: N.ArrowFunctionExpression, call: N.CallExpression): N.ArrowFunctionExpression {
if (this.match(tt.colon)) {
const oldNoAnonFunctionType = this.state.noAnonFunctionType;
this.state.noAnonFunctionType = true;
node.returnType = this.flowParseTypeAnnotation();
this.state.noAnonFunctionType = oldNoAnonFunctionType;
}

return super.parseAsyncArrowFromCallExpression(node, call, noArrowParamsConversion);
return super.parseAsyncArrowFromCallExpression(node, call);
}

// todo description
Expand All @@ -1624,12 +1621,12 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
// parse the rest, make sure the rest is an arrow function, and go from
// there
// 3. This is neither. Just call the super method
parseMaybeAssign(noIn?: ?boolean, refShorthandDefaultPos?: ?Pos, afterLeftParse?: Function, refNeedsArrowPos?: ?Pos, noArrowParamsConversion?: boolean): N.Expression {
parseMaybeAssign(noIn?: ?boolean, refShorthandDefaultPos?: ?Pos, afterLeftParse?: Function, refNeedsArrowPos?: ?Pos): N.Expression {
let jsxError = null;
if (tt.jsxTagStart && this.match(tt.jsxTagStart)) {
const state = this.state.clone();
try {
return super.parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos, noArrowParamsConversion);
return super.parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos);
} catch (err) {
if (err instanceof SyntaxError) {
this.state = state;
Expand All @@ -1653,7 +1650,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
try {
typeParameters = this.flowParseTypeParameterDeclaration();
arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => (
super.parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos, noArrowParamsConversion)
super.parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos)
));
arrowExpression.typeParameters = typeParameters;
this.resetStartLocationFromNode(arrowExpression, typeParameters);
Expand All @@ -1673,7 +1670,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
}
}

return super.parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos, noArrowParamsConversion);
return super.parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos);
}

// handle return types for arrow functions
Expand Down Expand Up @@ -1714,7 +1711,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return this.match(tt.colon) || super.shouldParseArrow();
}

setArrowFunctionParameters(node: N.ArrowFunctionExpression, params: N.Expression[], noArrowParamsConversion ?: boolean): N.ArrowFunctionExpression {
setArrowFunctionParameters(node: N.ArrowFunctionExpression, params: N.Expression[]): N.ArrowFunctionExpression {
if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
node.params = params;
return node;
Expand All @@ -1731,14 +1728,13 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return super.checkFunctionNameAndParams(node, isArrowFunction);
}

parseParenAndDistinguishExpression(canBeArrow: boolean, noArrowParamsConversion?: boolean): N.Expression {
parseParenAndDistinguishExpression(canBeArrow: boolean): N.Expression {
return super.parseParenAndDistinguishExpression(
canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1,
noArrowParamsConversion
canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1
);
}

parseSubscripts(base: N.Expression, startPos: number, startLoc: Position, noCalls?: boolean, noArrowParamsConversion?: ?boolean): N.Expression {
parseSubscripts(base: N.Expression, startPos: number, startLoc: Position, noCalls?: boolean): N.Expression {
if (
base.type === "Identifier" && base.name === "async" &&
this.state.noArrowAt.indexOf(startPos) !== -1
Expand All @@ -1751,6 +1747,6 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
base = this.finishNode(node, "CallExpression");
}

return super.parseSubscripts(base, startPos, startLoc, noCalls, noArrowParamsConversion);
return super.parseSubscripts(base, startPos, startLoc, noCalls);
}
};
Loading

0 comments on commit 8541f2c

Please sign in to comment.