Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 8, 2021
1 parent 8f26930 commit b984f7e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -61,8 +61,12 @@ import { cloneIdentifier } from "./node";
import type { SourceType } from "../options";
*/

// $FlowIgnore
const hasOwn = Function.call.bind(Object.prototype.hasOwnProperty);
const invalidHackPipeBodies = new Map([
["ArrowFunctionExpression", "arrow function"],
["AssignmentExpression", "assignment"],
["ConditionalExpression", "conditional"],
["YieldExpression", "yield"],
]);

export default class ExpressionParser extends LValParser {
// Forward-declaration: defined in statement.js
Expand Down Expand Up @@ -529,18 +533,12 @@ export default class ExpressionParser extends LValParser {

const body = this.parseMaybeAssign();

const invalidBodies = {
ArrowFunctionExpression: "arrow function",
AssignmentExpression: "assignment",
ConditionalExpression: "conditional",
YieldExpression: "yield",
};

if (hasOwn(invalidBodies, body.type) && !body.extra?.parenthesized) {
// TODO: Check how to handle type casts in Flow and TS once they are supported
if (invalidHackPipeBodies.has(body.type) && !body.extra?.parenthesized) {
this.raise(
start,
Errors.PipeUnparenthesizedBody,
invalidBodies[body.type],
invalidHackPipeBodies.get(body.type),
);
}
if (!this.topicReferenceWasUsedInCurrentContext()) {
Expand Down

0 comments on commit b984f7e

Please sign in to comment.