Skip to content

Commit 73a0b2a

Browse files
committed
fix #4286: minifier panic due to identity function
1 parent 134dadf commit 73a0b2a

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
* Fix a panic in a minification edge case ([#4286](https://github.com/evanw/esbuild/issues/4286))
6+
7+
This release fixes a panic due to a null pointer that could happen when esbuild inlines a doubly-nested identity function and the final result is empty. It was fixed by emitting the value `undefined` in this case, which avoids the panic. This case must be rare since it hasn't come up until now. Here is an example of code that previously triggered the panic (which only happened when minifying):
8+
9+
```js
10+
function identity(x) { return x }
11+
identity({ y: identity(123) })
12+
```
13+
514
* Fix `@supports` nested inside pseudo-element ([#4265](https://github.com/evanw/esbuild/issues/4265))
615

716
When transforming nested CSS to non-nested CSS, esbuild is supposed to filter out pseudo-elements such as `::placeholder` for correctness. The [CSS nesting specification](https://www.w3.org/TR/css-nesting-1/) says the following:

internal/bundler_tests/bundler_dce_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,12 @@ func TestInlineIdentityFunctionCalls(t *testing.T) {
25942594
keep(foo())
25952595
keep(1)
25962596
`,
2597+
2598+
"/identity-simplify-unused-issue-4287.js": `
2599+
function id(x) { return x }
2600+
id({ x: id([123, foo()]) })
2601+
id({ x: id(123) })
2602+
`,
25972603
},
25982604
entryPaths: []string{
25992605
"/identity.js",
@@ -2615,6 +2621,7 @@ func TestInlineIdentityFunctionCalls(t *testing.T) {
26152621
"/not-identity-object.js",
26162622
"/not-identity-rest.js",
26172623
"/not-identity-return.js",
2624+
"/identity-simplify-unused-issue-4287.js",
26182625
},
26192626
options: config.Options{
26202627
Mode: config.ModeBundle,

internal/bundler_tests/snapshots/snapshots_dce.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,11 @@ console.log(keep(1));
14831483
keep(foo());
14841484
keep(1);
14851485

1486+
---------- /out/identity-simplify-unused-issue-4287.js ----------
1487+
// identity-simplify-unused-issue-4287.js
1488+
foo();
1489+
void 0;
1490+
14861491
================================================================================
14871492
TestJSONLoaderRemoveUnused
14881493
---------- /out.js ----------

internal/js_printer/js_printer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,9 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
23332333
if _, ok := arg.Data.(*js_ast.ESpread); !ok {
23342334
if (flags & exprResultIsUnused) != 0 {
23352335
arg = p.astHelpers.SimplifyUnusedExpr(arg, p.options.UnsupportedFeatures)
2336+
if arg.Data == nil {
2337+
arg.Data = js_ast.EUndefinedShared
2338+
}
23362339
}
23372340
p.printExpr(p.guardAgainstBehaviorChangeDueToSubstitution(arg, flags), level, flags)
23382341
break

0 commit comments

Comments
 (0)