Skip to content

Comments

fix(es/parser): handle type assertions with non-callable types in binexp#1

Open
steffen-heil-secforge wants to merge 4 commits intomainfrom
v38.0.1+sf.1
Open

fix(es/parser): handle type assertions with non-callable types in binexp#1
steffen-heil-secforge wants to merge 4 commits intomainfrom
v38.0.1+sf.1

Conversation

@steffen-heil-secforge
Copy link
Member

@steffen-heil-secforge steffen-heil-secforge commented Nov 9, 2025

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.

Description:

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)
  • 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

…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 <noreply@anthropic.com>
@steffen-heil-secforge steffen-heil-secforge changed the title fix(es/parser): handle type assertions with non-callable types in bin… fix(es/parser): handle type assertions with non-callable types in binexp Nov 9, 2025
steffen-heil-secforge and others added 3 commits November 9, 2025 15:14
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 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant