Repository navigation
fix: handle TSInstantiation before < - #18658
Merged
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63634 |
|
commit: |
JLHwung
force-pushed
the
jlhwung/fix-generator-ts-instantiation-before-lt
branch
2 times, most recently
from
November 21, 2026 00:26
3adac16 to
42dde89
Compare
JLHwung
force-pushed
the
jlhwung/fix-generator-ts-instantiation-before-lt
branch
2 times, most recently
from
November 21, 2026 14:21
9b81e0c to
21fa83e
Compare
Base automatically changed from
jlhwung/test-generator-compact-roundtrip
to
main
November 21, 2026 16:03
JLHwung
force-pushed
the
jlhwung/fix-generator-ts-instantiation-before-lt
branch
from
November 21, 2026 16:03
21fa83e to
f32a1fb
Compare
…us operators `(f<T>) <= x` was printed as `f<T> <= x`, which fails to parse with JSX enabled because `<` after `>` starts a JSX element. Likewise `>`, `>>` and `>>>` after type arguments are not valid instantiation expressions, and `+`, `-` and `%` can start an expression, so `f<T> + x` reparses as `(f < T) > +x`. Parenthesize the left operand when it ends with an instantiation expression, also inside a type assertion such as `(<X>f<T>) - x`, and the operator is one of these. When minified, also separate `>` from a following `=` or `>`, so that `f<T> == x` is not printed as `f<T>==x` (`f < T >= =x`), and keep the `()` of `new (f<T>)()`, so that it does not end with type arguments (`new f<T>-x`). Assisted-by: Claude Opus 5.5
…guments `(f<T>)<U>`x`` was printed as `f<T><U>`x``, which is not parsed as a tagged template of an instantiation expression. Keep the parentheses when the tagged template has its own type arguments, as already done for calls and `new`, and stop adding them around arguments of such calls: `g<U>(f<T>)` was printed as `g<U>((f<T>))`. Without type arguments on the parent, `(f<T>)()`, `new (f<T>)()` and `(f<T>)`x`` are still printed without parentheses: the type arguments move to the call or tagged template, which has the same runtime semantics. Add a fixture for them, allowed to change AST shape in the roundtrip tests; experimental_preserveFormat keeps their parentheses. Assisted-by: Claude Opus 5.5
JLHwung
force-pushed
the
jlhwung/fix-generator-ts-instantiation-before-lt
branch
from
November 22, 2026 04:11
f32a1fb to
c1c1bec
Compare
liuxingbaoyu
approved these changes
Nov 25, 2026
liuxingbaoyu
left a comment
Member
There was a problem hiding this comment.
When experimental_preserveFormat is enabled, x as A<B>>c is not currently fully consistent with the source code.
We can include this in a separate PR. :)
repl
Contributor
Author
Collaborator
|
Backported to 7.x in #18724. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR we fix issues reported during the review session in #18546.
In the first commit we handle ambiguous operators after
f<T>: When the left hand side of a binary operator ends withf<T>, the generator now adds parentheses before these operators:<(and<=,<<) with JSX, since<after>starts a JSX element.To pass the minified roundtrip, we also add a space after
f<T>when printingf<T> == xsincef<T>==xdoes not parse (tscalso rejects this case)In the second commit we handle type arguments after
f<T>: For example(f<T>)<U>x` now keeps its parentheses.f<T>within call expression arguments are no longer parenthesized, for exampleg<U>(f<T>)used to printg<U>((f<T>))and now printsg<U>(f<T>).