Skip to content

fix: invalid minified: true output for new expression - #18324

Merged
nicolo-ribaudo merged 5 commits into
babel:mainfrom
JLHwung:fix-generator-minified-new-parens
Oct 28, 2026
Merged

nicolo-ribaudo merged 5 commits into
babel:mainfrom
JLHwung:fix-generator-minified-new-parens

Conversation

@JLHwung

@JLHwung JLHwung commented Oct 8, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Babel generates invalid output for (new F)?.p provided minified: true generator options
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

In this PR we fix an issue reported by the claude agent when fuzzing the #17785 implementation: When minified: true is provided, Babel generates invalid output because the rule only considers the call expression, while it should have re-used the hasPostfixPart helper in parentheses rules.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator labels Oct 8, 2026
@JLHwung JLHwung changed the title Fix generator minified new parens fix(generator): invalid minified: true output for new expression Oct 8, 2026
@babel-bot

babel-bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62642

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 224164a

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terser puts parentheses around the new expression, i.e. (new F).x rather than new F().x. Would it be possible to align to it?

Assisted-by: Claude Opus 5.5
This bug is triggered when `preserve_format` is used with modified AST in a way that would rendered the preserved format invalid JS code, without adding the ().
@JLHwung
JLHwung force-pushed the fix-generator-minified-new-parens branch from 38feffa to 224164a Compare October 27, 2026 19:41
@JLHwung

JLHwung commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Terser puts parentheses around the new expression, i.e. (new F).x rather than new F().x. Would it be possible to align to it?

Pushed a fix, ptal.

@nicolo-ribaudo nicolo-ribaudo changed the title fix(generator): invalid minified: true output for new expression fix: invalid minified: true output for new expression Oct 28, 2026
@nicolo-ribaudo
nicolo-ribaudo merged commit fd417e2 into babel:main Oct 28, 2026
57 of 58 checks passed
@nicolo-ribaudo
nicolo-ribaudo deleted the fix-generator-minified-new-parens branch October 28, 2026 11:24
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18461.

brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Nov 2, 2026
## pnpm-workspace.yaml (default)

## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `@babel/core` | 8.0.9 | 8.0.10 | patch |
| `@inlang/plugin-message-format` | 4.5.5 | 4.5.6 | patch |
| `@tanstack/devtools-vite` | 0.8.5 | 0.8.6 | patch |
| `ai` | 7.0.156 | 7.0.157 | patch |
| `cn` | 0.5.0 | 0.5.1 | patch |
| `seroval` | 1.7.4 | 1.7.5 | patch |

## Release Notes

<details>
<summary><b>@<!---->babel/core</b> (8.0.9 → 8.0.10)</summary>

## v8.0.10 (2026-10-29)

Thanks @<!---->dagemawinegash, @<!---->nyan-left,
@<!---->saiyam-jain-dev, and @<!---->yulman2207 for your first PRs!

#### 🐛 Bug Fix
* `babel-parser`
* [#18420](babel/babel#18420) fix(parser):
improve radix literal rounding
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18372](babel/babel#18372) fix(parser): allow
parenthesized assignment target in arrow initializer
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18410](babel/babel#18410) fix(parser): do
not record strict mode errors during lookahead
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18433](babel/babel#18433) fix(parser):
invalid expectOnePlugin usage
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18409](babel/babel#18409) fix(parser):
handle ASI after let followed by a reserved word on the next line
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18406](babel/babel#18406) fix(parser):
parser should not crash for `import defer {}`
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18407](babel/babel#18407) fix(parser):
record start location in `startNodeAt`
([@<!---->JLHwung](https://github.com/JLHwung))
* `babel-plugin-transform-block-scoping`
* [#18371](babel/babel#18371) fix: closures in
for-loop test and update capture wrong binding
([@<!---->joellemd](https://github.com/joellemd))
* `babel-generator`
* [#18418](babel/babel#18418) fix(generator):
keep aliases of string-literal module specifiers
([@<!---->JLHwung](https://github.com/JLHwung))
* [#18427](babel/babel#18427) Fix missing
parentheses around TypeScript assertion targets
([@<!---->dagemawinegash](https://github.com/dagemawinegash))
* [#18324](babel/babel#18324) fix: invalid
`minified: true` output for new expression
([@<!---->JLHwung](https://github.com/JLHwung))
  * [#18437](https://github.

…[full notes](https://github.com/babel/babel/releases/tag/v8.0.10)

</details>

<details>
<summary><b>@<!---->tanstack/devtools-vite</b> (0.8.5 → 0.8.6)</summary>

### Patch Changes

- [#539](TanStack/devtools#539)
[`ed8b314`](TanStack/devtools@ed8b314)
- Source injection no longer stops after the dev server parses a regex
literal. Before this fix, a regex literal cached `value` as a child key
of `Literal` nodes. Every later file with a string literal then threw
during the walk and got zero `data-tsd-source` attributes.

- [#540](TanStack/devtools#540)
[`012421f`](TanStack/devtools@012421f)
- Stop the console pipe feedback loop with Vite 8
`server.forwardConsole`. The server side of the pipe no longer sends
browser logs that Vite printed in the terminal back to the browser.

- [#548](TanStack/devtools#548)
[`40f32e4`](TanStack/devtools@40f32e4)
- Run source injection before the transforms of other plugins (unless
they also use `order: 'pre'`), also when `devtools()` is not first in
the plugins array. Before this fix, a framework plugin that changed the
code of only one environment shifted the line numbers, so
`data-tsd-source` differed between SSR and client and caused hydration
warnings.

- [#541](TanStack/devtools#541)
[`df1464c`](TanStack/devtools@df1464c)
- Fix "Go to Source" for files outside the current working directory,
for example a package in a monorepo or Vite run from another directory.
The editor got a path with the working directory added twice. Also
answer a missing or malformed `source` with `400` instead of leaving the
request pending.

- [#542](TanStack/devtools#542)
[`9c58288`](TanStack/devtools@9c58288)
- Remove the `intent` bin from the published packages. It took over
`node_modules/.bin/i

…[full
notes](https://github.com/TanStack/devtools/releases/tag/%40tanstack/devtools-vite%400.8.6)

</details>

<details>
<summary><b>cn</b> (0.5.0 → 0.5.1)</summary>

### Patch Changes

- [#165](shadcn-ui/cn#165)
[`5e65675`](shadcn-ui/cn@5e65675)
Thanks [@<!---->shadcn](https://github.com/shadcn)! - Group the legacy
`bg-gradient-to-*` utilities as `bg-color`, the same as tailwind-merge.
`cn("bg-background", "bg-gradient-to-r")` now returns
`bg-gradient-to-r`, and `bg-gradient-to-r` no longer replaces
`bg-linear-to-r` or an arbitrary `bg-[...]` image.

</details>

<details>
<summary><b>seroval</b> (1.7.4 → 1.7.5)</summary>

### Patch Changes

- d85ec3f: Keep two round-trip cases intact. An object whose own
`constructor` key holds a falsy value, such as `{ constructor: undefined
}`, now keeps `Object.prototype` instead of coming back with a null
prototype. A null-prototype object with an own `__proto__` key, or any
object serialized with `Feature.ObjectAssign` disabled, no longer turns
equal-looking values such as two `new Set()` into one shared object in
`serialize`, `crossSerialize` and `compileJSON` output.

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
JLHwung added a commit that referenced this pull request Nov 7, 2026
`new A<T>()` and `new A<T>` must print their type arguments followed by
`()` in minified mode instead of `new A;`. The fix itself landed with the
NewExpression rework in #18324, so only the fixture remains.

Assisted-by: Claude Fable 5.1 <[email protected]>
JLHwung added a commit that referenced this pull request Nov 17, 2026
`new A<T>()` and `new A<T>` must print their type arguments followed by
`()` in minified mode instead of `new A;`. The fix itself landed with the
NewExpression rework in #18324, so only the fixture remains.

Assisted-by: Claude Fable 5.1 <[email protected]>
JLHwung added a commit to JLHwung/babel that referenced this pull request Nov 20, 2026
* test(generator): add minified roundtrip test

Run the roundtrip test over generator and parser fixtures with
`minified: true`. `runRoundtripTests` takes extra generator and parser
fixtures whose AST changes, or whose output is rejected, in one mode
only. The fixtures that fail because of minified-only generator bugs are
listed here and removed by the commits that fix them; `not-directive`
stays, since minified prints `"\5"` as `"\x05"`, so it re-parses (with a
directive) instead of being rejected.

Assisted-by: Claude Opus 5.5

* test(generator): keep type arguments of argument-less new when minified

`new A<T>()` and `new A<T>` must print their type arguments followed by
`()` in minified mode instead of `new A;`. The fix itself landed with the
NewExpression rework in babel#18324, so only the fixture remains.

Assisted-by: Claude Fable 5.1 <[email protected]>

* fix(generator): never print Infinity or NaN identifiers for numeric literals

A NumericLiteral whose value overflows to Infinity was printed as
`Infinity` whenever that spelling was chosen: in minified mode when it is
shorter than the raw (`1e10000000` -> `Infinity;`) and in every mode when
the node has no `extra.raw`. `Infinity` is an identifier, not a numeric
literal: it can be shadowed and re-parses to an Identifier node, so the
output no longer round-trips to the same AST or semantics. Spell the
value as the numeric literal `1e999` instead (minified `1e1000` now also
becomes `1e999`), and skip jsesc for non-finite values since it prints
`Infinity` too. Non-minified output with a raw is unchanged.

A NaN value, which only a hand-built node can have, has no numeric
literal; print `(0 / 0)`, what `t.valueToNode(NaN)` builds, instead of
the `NaN` identifier.

Assisted-by: Claude Fable 5.1 <[email protected]>

* fix(generator): separate < from a following JSX element or TS assertion

In `minified`/`compact` mode a JSX element/fragment or a TypeScript type
assertion printed as the right operand of `<` was glued to the operator:
`x < <div />` became `x<<div/>` (no longer parses) and `x < <number>y`
became `x<<number>y` (silently re-parses as `x << number > y`). Both
re-tokenize the two `<` as the `<<` shift operator. Generated code must
re-parse to the same AST, so a space is required between them.

`token()` already inserts a space when the first character of the new
token would merge with the previous one into a different token
(`a+ +b`, `a- -b`, `34 .x`). Add the analogous `<` after `<` rule and
opt the leading `<` of JSXOpeningElement, JSXOpeningFragment and
TSTypeAssertion into it.

Assisted-by: Claude Fable 5.1 <[email protected]>

* fix(generator): do not backslash-escape JSX attribute strings

`StringLiteral` printed JSX attribute strings through jsesc in `minified`
mode or when the node has no `extra.raw`, but JSX attribute strings have
no escape sequences: a backslash is literal and quotes can only be
written as HTML entities. So `<a b='\w' c="&quot;" />` was minified to
`<a b="\\w"c="\""/>`, which changes the value of `b` and is a syntax
error for `c`.

When the parent is a JSXAttribute, print the raw text if it decodes to
the value; a string parsed as JS and moved into an attribute has a raw
with JS escapes. Otherwise quote the value with the `jsescOption.quotes`
quote (the other quote if the value contains it, or `&quot;`/`&apos;` if
it contains both) and encode an `&` that would start an entity. The
string may contain newlines, which are now counted for `retainLines`.

Assisted-by: Claude Fable 5.1 <[email protected]>

* fix(generator): print semicolon after Flow `declare module.exports`

`declare module.exports: T` was printed without a semicolon, which only
worked thanks to ASI; in minified output the next statement was glued to
it (`declare module.exports:T declare var a:T` is a syntax error).

Assisted-by: Claude Opus 5.5

* fix(generator): separate hack pipe topic tokens from operators

In minified output `x |> ^^ ^ 2` was printed as `x|>^^^2`,
`x |> % % 2` as `x|>%%2` and `x |> # in y` as `x|>#in y`, which are
tokenized differently.

Assisted-by: Claude Opus 5.5

* test(generator): cover negative overflowing numeric literal when minified

`-1e1000` parses as a unary minus applied to a NumericLiteral whose value
is Infinity, so it goes through the same `1e999` spelling and prints
`-1e999`.

Assisted-by: Claude Opus 5.5

* refactor: move isJSXAttributeRaw, jsxAttributeString to utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants