Skip to content

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

Open
steffen-heil-secforge wants to merge 4 commits into
mainfrom
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 into
mainfrom
v38.0.1+sf.1

Conversation

@steffen-heil-secforge

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

Copy link
Copy Markdown
Member

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>
steffen-heil-secforge pushed a commit that referenced this pull request Jun 28, 2026
…project#11672)

## Summary

This PR addresses the highest-impact performance hotspots from swc-project#11667 in
`swc_ecma_transformer` (`#1`-`swc-project#4` scope):

- Remove repeated front `Vec::insert(0, ...)` patterns in object-rest
lowering by using one-shot prepend materialization.
- Rewrite object-rest `exit_module_items` export-var rewriting to a
single-pass rebuild, avoiding repeated middle `remove/insert` mutations.
- Rework statement injector insertion for both `Vec<Stmt>` and
`Vec<ModuleItem>` to rebuild once while preserving insertion order and
statement-address targeting semantics.
- Switch private-in-object class membership tracking (`methods`,
`statics`) from `Vec<Atom>` to `FxHashSet<Atom>` for faster membership
checks in hot paths.

## Testing

- `git submodule update --init --recursive`
- `cargo test -p swc_ecma_transformer`
- `cargo fmt --all`
- `cargo clippy --all --all-targets -- -D warnings`
- `cargo test -p swc_ecma_transforms_compat` *(fails in this environment
because `mocha` is unavailable for existing exec tests)*
- `cargo test -p swc_ecma_transforms_compat --test
es2018_object_rest_spread -- --skip exec --skip issue_6029_1 --skip
issue_6029_2 --skip issue_4631`

## Notes

- No public API changes.
- Kept scope intentionally limited to findings `#1`-`swc-project#4`; follow-up work
(`swc-project#5`-`swc-project#7`) is not included.
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