Skip to content

Parse partial-application 2021-10 version - #18328

Open
JLHwung wants to merge 19 commits into
mainfrom
jlhwung/partial-application-2021-10
Open

JLHwung wants to merge 19 commits into
mainfrom
jlhwung/partial-application-2021-10

Conversation

@JLHwung

@JLHwung JLHwung commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? parse and print the latest 2021-10 version of the partial-application proposal
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link babel/website#3259
Any Dependency Changes?
License MIT

This PR includes parse & print supports of the 2021-10 version. The Babel parser will now accepts version: "2021-10" as a valid candidate of the partialApplication parser plugin options. The parser will throw when users used the 2018-07 syntax within the 2021-10 syntax or vice. See the spec.md for the proposed AST change.

@JLHwung JLHwung added PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Partial Application PR: Needs Docs labels Oct 9, 2026
@babel-bot

babel-bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63425

@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 3f729cf

@JLHwung
JLHwung added this pull request to stack #18330 October 9, 2026 05:23
@nicolo-ribaudo nicolo-ribaudo added this to the v8.1.0 milestone Oct 23, 2026
@nicolo-ribaudo nicolo-ribaudo added the PR: Needs Review A pull request awaiting more approvals label Oct 23, 2026
@nicolo-ribaudo nicolo-ribaudo removed this from the v8.1.0 milestone Oct 23, 2026
@JLHwung
JLHwung force-pushed the jlhwung/partial-application-2021-10 branch 2 times, most recently from fd2c403 to 09e4df1 Compare October 27, 2026 19:11
interface ArgumentPlaceholder <: Node {
type: "ArgumentPlaceholder";
type: "ArgumentPlaceholder";
ordinal?: NumericLiteral;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not fully convinces that NumericLiteral is the right node type to put in an argument placeholder. It has different parsing and printing rules, and any possible plugin logic that applies to NumericLiteral likely does not apply here.

I wonder if we could directly put it in the AST, like

interface ArgumentPlaceholder {
  ordinal?: number;
}

(or even : bigint / : string)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. In estree/estree#334, I chose ordinal: NumericLiteral (Literal for estree) because:

  1. Whitespaces are allowed between ? and number, an AST node here provides better comment attachment as we don't have to fallback to the inner comments
  2. Supports loose comparision for consumers: if (node.ordinal) { /* process ordinal /* } just works, otherwise one would have to if (node.ordinal != null) { ... } to properly differentiate between ?0 and ?. IIRC Other than NumericLiteral and NumberLiteralTypeAnnotation, we don't have other AST nodes that includes a number field, so it is error-prone for consumers here.

Like you said, they do have different parsing and printing rules, what do you think if we introduce a new AST type?

interface ArgumentPlaceholder <: Node {
    type: "ArgumentPlaceholder";
    ordinal: PlaceholderOrdinal | null;
}

interface PlaceholderOrdinal <: Node {
    type: "PlaceholderOrdinal";
    value: number;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PlaceholderOrdinal node seems ok to me 👍

// Placeholder ordinals must be decimal integer literals, so neither
// `jsescOption.numbers` nor the exponent form of large numbers applies
this.number(
raw ?? (Number.isInteger(value) ? BigInt(value).toString() : str),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case is the value not a Number.isInteger?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good qeustion, the parser does not accept floats, however currently the builder does not properly validate the invalid case such as t.argumentPlaceholder(t.numericLiteral(1.5)). I think we should fix that in the builder instead.

this.next(); // eat `?`
if (this.match(tt.num)) {
if (disallowOrdinal) {
this.raise(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this error unrecoverable, similar to the "missing plugin" error where we don't recover and silently enable it.

@JLHwung
JLHwung force-pushed the jlhwung/partial-application-2021-10 branch from 09e4df1 to 3f729cf Compare November 18, 2026 15:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Needs Review A pull request awaiting more approvals PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Partial Application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants