esbuild 0.14.24
-
Allow
es2022as a target environment (#2012)TypeScript recently added support for
es2022as a compilation target so esbuild now supports this too. Support for this is preliminary as there is no published ES2022 specification yet (i.e. https://tc39.es/ecma262/2021/ exists but https://tc39.es/ecma262/2022/ is a 404 error). The meaning of esbuild'ses2022target may change in the future when the specification is finalized. Right now I have made thees2022target enable support for the syntax-related finished proposals that are marked as2022:- Class fields
- Class private members
- Class static blocks
- Ergonomic class private member checks
- Top-level await
I have also included the "arbitrary module namespace names" feature since I'm guessing it will end up in the ES2022 specification (this syntax feature was added to the specification without a proposal). TypeScript has not added support for this yet.
-
Match
defineto strings in index expressions (#2050)With this release, configuring
--define:foo.bar=baznow matches and replaces bothfoo.barandfoo['bar']expressions in the original source code. This is necessary for people who have enabled TypeScript'snoPropertyAccessFromIndexSignaturefeature, which prevents you from using normal property access syntax on a type with an index signature such as in the following code:declare let foo: { [key: string]: any } foo.bar // This is a type error if noPropertyAccessFromIndexSignature is enabled foo['bar']Previously esbuild would generate the following output with
--define:foo.bar=baz:baz; foo["bar"];Now esbuild will generate the following output instead:
baz; baz; -
Add
--mangle-quotedto mangle quoted properties (#218)The
--mangle-props=flag tells esbuild to automatically rename all properties matching the provided regular expression to shorter names to save space. Previously esbuild never modified the contents of string literals. In particular,--mangle-props=_would manglefoo._barbut notfoo['_bar']. There are some coding patterns where renaming quoted property names is desirable, such as when using TypeScript'snoPropertyAccessFromIndexSignaturefeature or when using TypeScript's discriminated union narrowing behavior:interface Foo { _foo: string } interface Bar { _bar: number } declare const value: Foo | Bar console.log('_foo' in value ? value._foo : value._bar)The
'_foo' in valuecheck tells TypeScript to narrow the type ofvaluetoFooin the true branch and toBarin the false branch. Previously esbuild didn't mangle the property name'_foo'because it was inside a string literal. With this release, you can now use--mangle-quotedto also rename property names inside string literals:// Old output (with --mangle-props=_) console.log("_foo" in value ? value.a : value.b); // New output (with --mangle-props=_ --mangle-quoted) console.log("a" in value ? value.a : value.b); -
Parse and discard TypeScript
export as namespacestatements (#2070)TypeScript
.d.tstype declaration files can sometimes contain statements of the formexport as namespace foo;. I believe these serve to declare that the module adds a property of that name to the global object. You aren't supposed to feed.d.tsfiles to esbuild so this normally doesn't matter, but sometimes esbuild can end up having to parse them. One such case is if you import a type-only package who'smainfield inpackage.jsonis a.d.tsfile.Previously esbuild only allowed
export as namespacestatements inside adeclarecontext:declare module Foo { export as namespace foo; }Now esbuild will also allow these statements outside of a
declarecontext:export as namespace foo;These statements are still just ignored and discarded.
-
Strip import assertions from unrecognized
import()expressions (#2036)The new "import assertions" JavaScript language feature adds an optional second argument to dynamic
import()expressions, which esbuild does support. However, this optional argument must be stripped when targeting older JavaScript environments for which this second argument would be a syntax error. Previously esbuild failed to strip this second argument in cases when the first argument toimport()wasn't a string literal. This problem is now fixed:// Original code console.log(import(foo, { assert: { type: 'json' } })) // Old output (with --target=es6) console.log(import(foo, { assert: { type: "json" } })); // New output (with --target=es6) console.log(import(foo)); -
Remove simplified statement-level literal expressions (#2063)
With this release, esbuild now removes simplified statement-level expressions if the simplified result is a literal expression even when minification is disabled. Previously this was only done when minification is enabled. This change was only made because some people are bothered by seeing top-level literal expressions. This change has no effect on code behavior.
-
Ignore
.d.tsrules inpathsintsconfig.jsonfiles (#2074, #2075)TypeScript's
tsconfig.jsonconfiguration file has apathsfield that lets you remap import paths to alternative files on the file system. This field is interpreted by esbuild during bundling so that esbuild's behavior matches that of the TypeScript type checker. However, people sometimes override import paths to JavaScript files to instead point to a.d.tsTypeScript type declaration file for that JavaScript file. The intent of this is to just use the remapping for type information and not to actually import the.d.tsfile during the build.With this release, esbuild will now ignore rules in
pathsthat result in a.d.tsfile during path resolution. This means code that does this should now be able to be bundled without modifying itstsconfig.jsonfile to remove the.d.tsrule. This change was contributed by @magic-akari. -
Disable Go compiler optimizations for the Linux RISC-V 64bit build (#2035)
Go's RISC-V 64bit compiler target has a fatal compiler optimization bug that causes esbuild to crash when it's run: https://github.com/golang/go/issues/51101. As a temporary workaround until a version of the Go compiler with the fix is published, Go compiler optimizations have been disabled for RISC-V. The 7.7mb esbuild binary executable for RISC-V is now 8.7mb instead. This workaround was contributed by @piggynl.