Repository navigation
fix: only separate > from = & > after TS instantiation expression - #18723
Conversation
| this.print(node.typeArguments); | ||
| // Unlike after other type arguments, a `>` or `=` printed right after these | ||
| // would be tokenized together with the closing `>`: see Printer#token. | ||
| this.setLastChar(-4 /* LAST_CHAR_KINDS.TS_INSTANTIATION_TYPE_ARGUMENTS */); |
There was a problem hiding this comment.
Here we write the literal by hand to avoid the runtime object in this hot path. We should figure out how to make exported TS const enums works in the build pipeline.
There was a problem hiding this comment.
Lines 568 to 571 in 68cfec5
It doesn't work? I remember that before it was because Babel 7 didn't have bundled generators, so I had to use numeric literals.
There was a problem hiding this comment.
Oh you are right. I forgot about this plugin. I will update the usage here. I guess we can just make this plugin a global rollup plugin, not limited to the parser/generator.
There was a problem hiding this comment.
Hmm, that plugin does not work with negative enum values like -1 because we only have the isNumericLiteral check, I will update that plugin and push a new commit.
There was a problem hiding this comment.
Well, it shouldn't have any side effects, I just remember it being a bit slow. 🤦♂️
There was a problem hiding this comment.
It's okay, we just improved the build performance, we will have more budget for that plugin.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63820 |
|
commit: |
1baa49d to
3666960
Compare
The bundle-time inliner for `@babel/parser` and `@babel/generator` only accepted numeric literals, so a const enum with negative members (`-1` parses as a unary expression) stayed an object with property reads in the bundle. Assisted-by: Claude Opus 5.5
…n expressions The space added between a `>` and an operator starting with `=` or `>` is only needed when the `>` closes the type arguments of an instantiation expression: `f<T>==x` is tokenized as `f < T >= =x`. Any other `>` is a token on its own, so `x as A<B>>c` and `<a />==c` are valid as written. Applying it to every `>` made `experimental_preserveFormat` print `x as A<B>>c` as `x as A<B> >c`, and added a redundant space to the minified output of such expressions. `LAST_CHAR_KINDS` moves to buffer.ts and is exported, so the generators use it instead of hand-inlined literals. The bundle still contains the plain values. Assisted-by: Claude Fable 5.2
3666960 to
fc64cc1
Compare
|
Backported to 7.x in #18729. |
As a follow-up to #18658, we fix an issue reported in the review comment #18658 (review): that
x as A<B>>cdoes not roundtrip whenexperimental_preserveFormatis enabled:The space added between a
>and an operator starting with=or>is only needed when the>closes the type arguments of an instantiation expression. So we add a new last-char enum kindTS_INSTANTIATION_TYPE_ARGUMENTS.