Skip to content

fix(parser): correctly parse type assertions in extends clause#17761

Merged
nicolo-ribaudo merged 1 commit intobabel:mainfrom
wulu007:fix-issue-17749
Jan 31, 2026
Merged

fix(parser): correctly parse type assertions in extends clause#17761
nicolo-ribaudo merged 1 commit intobabel:mainfrom
wulu007:fix-issue-17749

Conversation

@wulu007
Copy link
Contributor

@wulu007 wulu007 commented Jan 31, 2026

Q                       A
Fixed Issues? Fixes #17749
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This commit fixes an issue where the parser failed to handle TypeScript type assertions (as, satisfies) inside class extends clauses, specifically when generics are involved (e.g., class C extends (B<T> as D) {}).

The fix involves:

  1. Updating parseMaybeAssign in the TypeScript plugin to properly handle as and satisfies expressions instead of returning early.
  2. Updating parseSubscript to correctly identify < as the start of generic type arguments even when followed by as or satisfies, preventing it from incorrectly bailing out to a comparison operator.

Tests added for nested generics, array types, and satisfies operator.

@babel-bot
Copy link
Collaborator

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 31, 2026

Open in StackBlitz

commit: 2ee2698

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Jan 31, 2026
Copy link
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.

Thank you :)

@nicolo-ribaudo nicolo-ribaudo merged commit 61ebde9 into babel:main Jan 31, 2026
55 checks passed
nicolo-ribaudo pushed a commit to nicolo-ribaudo/babel that referenced this pull request Jan 31, 2026
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release and removed 7.x: needs backport PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Jan 31, 2026
JLHwung pushed a commit that referenced this pull request Jan 31, 2026
)

* fix(parser): correctly parse type assertions in `extends` clause

backport of 61ebde9 (#17761)

* Update output

---------

Co-authored-by: wulu007 <130914655+wulu007@users.noreply.github.com>
@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.

Babel parser throws unexpected token when a super class is a TSAsExpression

4 participants