Partial Application Syntax: Stage 1 (#9343)
* add partial application syntax and some tests * remove unnecessary error message and hasPartial function from parseNewArguments * add types for PartialExpression * Update the tests * rename PartialExpression to Partial * move Partial from expressions to types and rename to ArgumentPlaceholder * add tests for ArgumentPlaceholder in babel-generator * rename Partial to ArgumentPlaceholder * update the tests * remove alias from the type and undo changes in generated folder * adds a nice error message * better definition for the type * auto-generated files * update the conditional for allowPlaceholder message and tests * update CallExpression definition to accept ArgumentPlaceholder * change description * clean up * indent ArgumentPlaceholder entry and revert unwanted changes
This commit is contained in:
committed by
Nicolò Ribaudo
parent
37a427f692
commit
c60c4dd375
@@ -323,7 +323,6 @@ export default class ExpressionParser extends LValParser {
|
||||
const operator = this.state.value;
|
||||
node.left = left;
|
||||
node.operator = operator;
|
||||
|
||||
if (
|
||||
operator === "**" &&
|
||||
left.type === "UnaryExpression" &&
|
||||
@@ -634,6 +633,7 @@ export default class ExpressionParser extends LValParser {
|
||||
tt.parenR,
|
||||
possibleAsync,
|
||||
base.type === "Import",
|
||||
base.type !== "Super",
|
||||
);
|
||||
if (!state.optionalChainMember) {
|
||||
this.finishCallExpression(node);
|
||||
@@ -744,6 +744,7 @@ export default class ExpressionParser extends LValParser {
|
||||
close: TokenType,
|
||||
possibleAsyncArrow: boolean,
|
||||
dynamicImport?: boolean,
|
||||
allowPlaceholder?: boolean,
|
||||
): $ReadOnlyArray<?N.Expression> {
|
||||
const elts = [];
|
||||
let innerParenStart;
|
||||
@@ -776,6 +777,7 @@ export default class ExpressionParser extends LValParser {
|
||||
false,
|
||||
possibleAsyncArrow ? { start: 0 } : undefined,
|
||||
possibleAsyncArrow ? { start: 0 } : undefined,
|
||||
allowPlaceholder,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1945,6 +1947,7 @@ export default class ExpressionParser extends LValParser {
|
||||
allowEmpty: ?boolean,
|
||||
refShorthandDefaultPos: ?Pos,
|
||||
refNeedsArrowPos: ?Pos,
|
||||
allowPlaceholder: ?boolean,
|
||||
): ?N.Expression {
|
||||
let elt;
|
||||
if (allowEmpty && this.match(tt.comma)) {
|
||||
@@ -1957,6 +1960,14 @@ export default class ExpressionParser extends LValParser {
|
||||
spreadNodeStartPos,
|
||||
spreadNodeStartLoc,
|
||||
);
|
||||
} else if (this.match(tt.question)) {
|
||||
this.expectPlugin("partialApplication");
|
||||
if (!allowPlaceholder) {
|
||||
this.raise(this.state.start, "Unexpected argument placeholder");
|
||||
}
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
elt = this.finishNode(node, "ArgumentPlaceholder");
|
||||
} else {
|
||||
elt = this.parseMaybeAssign(
|
||||
false,
|
||||
|
||||
@@ -340,6 +340,8 @@ export type VariableDeclarator = NodeBase & {
|
||||
|
||||
// Misc
|
||||
|
||||
export type ArgumentPlaceholder = NodeBase & { type: "ArgumentPlaceholder" };
|
||||
|
||||
export type Decorator = NodeBase & {
|
||||
type: "Decorator",
|
||||
expression: Expression,
|
||||
|
||||
Reference in New Issue
Block a user