Skip to content

Fix(types): Align AST definitions to parser implementations#17852

Merged
nicolo-ribaudo merged 7 commits intobabel:mainfrom
JLHwung:fix-babel-types-def
Mar 7, 2026
Merged

Fix(types): Align AST definitions to parser implementations#17852
nicolo-ribaudo merged 7 commits intobabel:mainfrom
JLHwung:fix-babel-types-def

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Mar 5, 2026

Q                       A
Fixed Issues? Align the AST definitions in @babel/types
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR is extracted from (todo).

In this PR we aligns the AST definitions in @babel/types to the actual @babel/parser behaviour. The following changes are implemented:

  • Add BigIntLiteralTypeAnnotation type definition. This AST type was introduced in BigInt type for Flow #10091 but we forgot to add the babel-types definition
  • Allow TSInterfaceDeclaration and EnumDeclaration under ExportDefaultDeclaration
  • Change the extends type of TSInterfaceDeclaration from TSClassImplements[] to TSInterfaceHeritage[]. The parser always generates TSInterfaceHeritage so this is a definition error. Since TSInterfaceHeritage is introduced in Babel 8, we can fix it before 8.0.0
  • Allow the kind of TSModuleDeclaration to be module
  • Allow the object of BindExpression to be null. This AST models the production :: MemberExpression[?Yield]
  • Allow the key of ObjectTypeProperty to be NumericLiteral. Flow allows type A = { 0: string } but it does not support bigInt as object type key yet
  • Change the value type of DeclaredPredicate from Flow to Expression. It is formed by super.parseExpression. BTW Flow has removed the support of predicate syntax
  • Allow predicate type of DeclareFunction to be InferredPredicate. Both Babel and Flow parser support declare function f(): boolean %checks though Flow will emit an error that the syntax is unsupported and will be ignored

@JLHwung JLHwung added the PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release label Mar 5, 2026
@JLHwung JLHwung changed the title Fix(types) Align AST definitions to parser implementations Fix(types): Align AST definitions to parser implementations Mar 5, 2026
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Mar 5, 2026

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 5, 2026

Open in StackBlitz

commit: 2779dd3

@JLHwung JLHwung requested a review from liuxingbaoyu March 5, 2026 14:13
Copy link
Copy Markdown
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

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

Great!

@JLHwung JLHwung force-pushed the fix-babel-types-def branch from b6b5cba to 7a04424 Compare March 5, 2026 15:46
@JLHwung JLHwung force-pushed the fix-babel-types-def branch from 7a04424 to 2779dd3 Compare March 5, 2026 16:12
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Nice!

@nicolo-ribaudo nicolo-ribaudo merged commit 0263178 into babel:main Mar 7, 2026
99 of 100 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the fix-babel-types-def branch March 7, 2026 22:06
@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants