Merge branch 'master' into implement-smart-pipeline-in-parser
* master: (222 commits) Set correct methods name Use toPropertyKey in the "decorate" helper Allow function types in type params within arrow return types (#8954) Fix message when plugin of a wrong type is passed (#8950) rename colliding let bindings with for loop init (#8937) edge incomplete support for arrow destructuring (babel #8349) (#8926) fix single-arg async arrows when retainLines=true (#8868) [flow] Explicit inexact objects with `...` (#8884) Update preset-env data (#8898) Treat break inside block inside loop (#8914) fixed "source map" formatting in comment (#8878) [skip ci] fix typo in contributing guidelines (#8901) [skip ci] fix: Expression x === 'y' && '' should not evaluate to undefined. (#8880) fixed an extra word Fixes #8865 (#8866) v7.1.4 v7.1.3 Bump Babel deps (#8770) flow-bin@0.82.0 (#8832) Insertafter jsx fix (#8833) ... # Conflicts: # packages/babel-parser/src/tokenizer/index.js # packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json # packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
import * as N from "../types";
|
||||
import { types as tt, type TokenType } from "../tokenizer/types";
|
||||
import ExpressionParser from "./expression";
|
||||
import { lineBreak } from "../util/whitespace";
|
||||
import { isIdentifierChar } from "../util/identifier";
|
||||
import { lineBreak, skipWhiteSpace } from "../util/whitespace";
|
||||
|
||||
// Reused empty array added for node fields that are always empty.
|
||||
|
||||
@@ -304,15 +305,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.eat(tt.parenL)) {
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.callee = expr;
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
this.toReferencedList(node.arguments);
|
||||
expr = this.finishNode(node, "CallExpression");
|
||||
}
|
||||
|
||||
node.expression = expr;
|
||||
node.expression = this.parseMaybeDecoratorArguments(expr);
|
||||
this.state.decoratorStack.pop();
|
||||
} else {
|
||||
node.expression = this.parseMaybeAssign();
|
||||
@@ -320,6 +313,18 @@ export default class StatementParser extends ExpressionParser {
|
||||
return this.finishNode(node, "Decorator");
|
||||
}
|
||||
|
||||
parseMaybeDecoratorArguments(expr: N.Expression): N.Expression {
|
||||
if (this.eat(tt.parenL)) {
|
||||
const node = this.startNodeAtNode(expr);
|
||||
node.callee = expr;
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
this.toReferencedList(node.arguments);
|
||||
return this.finishNode(node, "CallExpression");
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
parseBreakContinueStatement(
|
||||
node: N.BreakStatement | N.ContinueStatement,
|
||||
keyword: string,
|
||||
@@ -1497,18 +1502,37 @@ export default class StatementParser extends ExpressionParser {
|
||||
return this.finishNode(node, "ExportNamedDeclaration");
|
||||
}
|
||||
|
||||
isAsyncFunction() {
|
||||
if (!this.isContextual("async")) return false;
|
||||
|
||||
const { input, pos } = this.state;
|
||||
|
||||
skipWhiteSpace.lastIndex = pos;
|
||||
const skip = skipWhiteSpace.exec(input);
|
||||
|
||||
if (!skip || !skip.length) return false;
|
||||
|
||||
const next = pos + skip[0].length;
|
||||
|
||||
return (
|
||||
!lineBreak.test(input.slice(pos, next)) &&
|
||||
input.slice(next, next + 8) === "function" &&
|
||||
(next + 8 === input.length || !isIdentifierChar(input.charAt(next + 8)))
|
||||
);
|
||||
}
|
||||
|
||||
parseExportDefaultExpression(): N.Expression | N.Declaration {
|
||||
const expr = this.startNode();
|
||||
if (this.eat(tt._function)) {
|
||||
return this.parseFunction(expr, true, false, false, true);
|
||||
} else if (
|
||||
this.isContextual("async") &&
|
||||
this.lookahead().type === tt._function
|
||||
) {
|
||||
// async function declaration
|
||||
this.eatContextual("async");
|
||||
this.eat(tt._function);
|
||||
return this.parseFunction(expr, true, false, true, true);
|
||||
|
||||
const isAsync = this.isAsyncFunction();
|
||||
|
||||
if (this.eat(tt._function) || isAsync) {
|
||||
if (isAsync) {
|
||||
this.eatContextual("async");
|
||||
this.expect(tt._function);
|
||||
}
|
||||
|
||||
return this.parseFunction(expr, true, false, isAsync, true);
|
||||
} else if (this.match(tt._class)) {
|
||||
return this.parseClass(expr, true, true);
|
||||
} else if (this.match(tt.at)) {
|
||||
@@ -1641,7 +1665,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.state.type.keyword === "let" ||
|
||||
this.state.type.keyword === "function" ||
|
||||
this.state.type.keyword === "class" ||
|
||||
this.isContextual("async")
|
||||
this.isAsyncFunction()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user