-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(es/parser): handle type assertions with non-callable types in binexp #11251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(es/parser): handle type assertions with non-callable types in binexp #11251
Conversation
…ary expressions
After type assertions (`as`) and satisfies expressions, the parser needs to
determine whether a following `<` token is a comparison operator or the start
of type parameters. This fix ensures that `<` is lexed as a comparison operator
when the type cannot have type parameters.
Previously only primitive keyword types and literals were handled. This extends
the logic to cover all non-callable type constructs:
- Primitive keyword types (number, string, boolean, etc.)
- Literal types (2, "x", true, 10n)
- this type
- Array types (number[], Array<number>)
- Tuple types ([number, string])
- Union/intersection types (A | B, A & B)
- Type operators (keyof T, readonly T, unique symbol)
- Indexed access types (T[K])
- Conditional types (T extends U ? X : Y)
- Mapped types ({ [K in keyof T]: V })
- Type predicates (x is string)
This prevents parsing errors when these type assertions are followed by
comparison operators.
Examples that now parse correctly:
- (i as number[]) < 5
- (i as [number, string]) < 5
- (i as number | string) < 5
- (i as keyof T) < 5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
|
|
|
|
|
Binary Sizes
Commit: 64a931a |
CodSpeed Performance ReportMerging #11251 will not alter performanceComparing Summary
Footnotes |
|
Could do please provide an example with https://play.swc.rs/ to show the parsing errors? |
|
Note, I will update the tests shortly |
Only test files were modified to verify the type assertion handling behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
The point is that there is no explicit bug in swc alone. Examples of dprint typescript failing because of this: |
|
I don't think it's a bug of the ES parser. You added tests to a wrong place, meaning that it was already working |
Description:
After type assertions (
as) and satisfies expressions, the parser needs to determine whether a following<token is a comparison operator or the start of type parameters. This fix ensures that<is lexed as a comparison operator when the type cannot have type parameters.Previously only primitive keyword types and literals were handled. This extends the logic to cover all non-callable type constructs:
This prevents parsing errors when these type assertions are followed by comparison operators.
Examples that now parse correctly: