-
Make global names more compact when
||=
is available (#2331)With this release, the code esbuild generates for the
--global-name=
setting is now slightly shorter when you don't configure esbuild such that the||=
operator is unsupported (e.g. with--target=chrome80
or--supported:logical-assignment=false
):// Original code exports.foo = 123 // Old output (with --format=iife --global-name=foo.bar.baz --minify) var foo=foo||{};foo.bar=foo.bar||{};foo.bar.baz=(()=>{var b=(a,o)=>()=>(o||a((o={exports:{}}).exports,o),o.exports);var c=b(f=>{f.foo=123});return c();})(); // New output (with --format=iife --global-name=foo.bar.baz --minify) var foo;((foo||={}).bar||={}).baz=(()=>{var b=(a,o)=>()=>(o||a((o={exports:{}}).exports,o),o.exports);var c=b(f=>{f.foo=123});return c();})();
-
Fix
--mangle-quoted=false
with--minify-syntax=true
If property mangling is active and
--mangle-quoted
is disabled, quoted properties are supposed to be preserved. However, there was a case when this didn't happen if--minify-syntax
was enabled, since that internally transformsx['y']
intox.y
to reduce code size. This issue has been fixed:// Original code x.foo = x['bar'] = { foo: y, 'bar': z } // Old output (with --mangle-props=. --mangle-quoted=false --minify-syntax=true) x.a = x.b = { a: y, bar: z }; // New output (with --mangle-props=. --mangle-quoted=false --minify-syntax=true) x.a = x.bar = { a: y, bar: z };
Notice how the property
foo
is always used unquoted but the propertybar
is always used quoted, sofoo
should be consistently mangled whilebar
should be consistently not mangled. -
Fix a minification bug regarding
this
and property initializersWhen minification is enabled, esbuild attempts to inline the initializers of variables that have only been used once into the start of the following expression to reduce code size. However, there was a bug where this transformation could change the value of
this
when the initializer is a property access and the start of the following expression is a call expression. This release fixes the bug:// Original code function foo(obj) { let fn = obj.prop; fn(); } // Old output (with --minify) function foo(f){f.prop()} // New output (with --minify) function foo(o){let f=o.prop;f()}