chore(deps): update dependency esbuild to v0.15.4 - autoclosed #44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
0.14.44->0.15.4Release Notes
evanw/esbuild
v0.15.4Compare Source
Consider TypeScript import assignments to be side-effect free (#2468)
TypeScript has a legacy import syntax for working with TypeScript namespaces that looks like this:
Since esbuild converts TypeScript into JavaScript one file at a time, it doesn't know if
baris supposed to be a value or a type (or both, which TypeScript actually allows in this case). This is problematic because values are supposed to be kept during the conversion but types are supposed to be removed during the conversion. Currently esbuild keepsbarin the output, which is done becausesomeNamespace.foois a property access and property accesses run code that could potentially have a side effect (although there is no side effect in this case).With this release, esbuild will now consider
someNamespace.footo have no side effects. This meansbarwill now be removed when bundling and when tree shaking is enabled. Note that it will still not be removed when tree shaking is disabled. This is because in this mode, esbuild supports adding additional code to the end of the generated output that's in the same scope as the module. That code could potentially make use ofbar, so it would be incorrect to remove it. If you wantbarto be removed, you'll have to enable tree shaking (which tells esbuild that nothing else depends on the unexported top-level symbols in the generated output).Change the order of the banner and the
"use strict"directive (#2467)Previously the top of the file contained the following things in order:
"use strict"directive from the source code, if presentbannerAPI option, if specifiedThis was problematic for people that used the
bannerAPI option to insert the hashbang comment instead of using esbuild's hashbang comment preservation feature. So with this release, the order has now been changed to:bannerAPI option, if specified"use strict"directive from the source code, if presentI'm considering this change to be a bug fix instead of a breaking change because esbuild's documentation states that the
bannerAPI option can be used to "insert an arbitrary string at the beginning of generated JavaScript files". While this isn't technically true because esbuild may still insert the original hashbang comment before the banner, it's at least more correct now because the banner will now come before the"use strict"directive.For context: JavaScript files recently allowed using a hashbang comment, which starts with
#!and which must start at the very first character of the file. It allows Unix systems to execute the file directly as a script without needing to prefix it by thenodecommand. This comment typically has the value#!/usr/bin/env node. Hashbang comments will be a part of ES2023 when it's released next year.Fix
exportsmaps with Yarn PnP path resolution (#2473)The Yarn PnP specification says that to resolve a package path, you first resolve it to the absolute path of a directory, and then you run node's module resolution algorithm on it. Previously esbuild followed this part of the specification. However, doing this means that
exportsinpackage.jsonis not respected because node's module resolution algorithm doesn't interpretexportsfor absolute paths. So with this release, esbuild will now use a modified algorithm that deviates from both specifications but that should hopefully behave more similar to what Yarn actually does: node's module resolution algorithm is run with the original import path but starting from the directory returned by Yarn PnP.v0.15.3Compare Source
Change the Yarn PnP manifest to a singleton (#2463)
Previously esbuild searched for the Yarn PnP manifest in the parent directories of each file. But with Yarn's
enableGlobalCachesetting it's possible to configure Yarn PnP's implementation to reach outside of the directory subtree containing the Yarn PnP manifest. This was causing esbuild to fail to bundle projects with theenableGlobalCachesetting enabled.To handle this case, esbuild will now only search for the Yarn PnP manifest in the current working directory of the esbuild process. If you're using esbuild's CLI, this means you will now have to
cdinto the appropriate directory first. If you're using esbuild's API, you can override esbuild's value for the current working directory with theabsWorkingDirAPI option.Fix Yarn PnP resolution failures due to backslashes in paths on Windows (#2462)
Previously dependencies of a Yarn PnP virtual dependency failed to resolve on Windows. This was because Windows uses
\instead of/as a path separator, and the path manipulation algorithms used for Yarn PnP expected/. This release converts\into/in Windows paths, which fixes this issue.Fix
sideEffectspatterns containing slashes on Windows (#2465)The
sideEffectsfield inpackage.jsonlets you specify an array of patterns to mark which files have side effects (which causes all other files to be considered to not have side effects by exclusion). That looks like this:However, the presence of the
/character in the pattern meant that the pattern failed to match Windows-style paths, which brokesideEffectson Windows in this case. This release fixes this problem by adding additional code to handle Windows-style paths.v0.15.2Compare Source
Fix Yarn PnP issue with packages containing
index.js(#2455, #2461)Yarn PnP's tests require the resolved paths to end in
/. That's not how the rest of esbuild's internals work, however, and doing this messed up esbuild's node module path resolution regarding automatically-detectedindex.jsfiles. Previously packages that relied on implicitindex.jsresolution rules didn't work with esbuild under Yarn PnP. Removing this slash has fixed esbuild's path resolution behavior regardingindex.js, which should now the same both with and without Yarn PnP.Fix Yarn PnP support for
extendsintsconfig.json(#2456)Previously using
extendsintsconfig.jsonwith a path in a Yarn PnP package didn't work. This is because the process of setting up package path resolution rules requires parsingtsconfig.jsonfiles (due to thebaseUrlandpathsfeatures) and resolvingextendsto a package path requires package path resolution rules to already be set up, which is a circular dependency. This cycle is broken by using special rules forextendsintsconfig.jsonthat bypasses esbuild's normal package path resolution process. This is why usingextendswith a Yarn PnP package didn't automatically work. With this release, these special rules have been modified to check for a Yarn PnP manifest so this case should work now.Fix Yarn PnP support in
esbuild-wasm(#2458)When running esbuild via WebAssembly, Yarn PnP support previously failed because Go's file system internals return
EINVALwhen trying to read a.zipfile as a directory when run with WebAssembly. This was unexpected because Go's file system internals returnENOTDIRfor this case on native. This release updates esbuild to treatEINVALlikeENOTDIRin this case, which fixes usingesbuild-wasmto bundle a Yarn PnP project.Note that to be able to use
esbuild-wasmfor Yarn PnP successfully, you currently have to run it usingnodeinstead ofyarn node. This is because the file system shim that Yarn overwrites node's native file system API with currently generates invalid file descriptors with negative values when inside a.zipfile. This prevents esbuild from working correctly because Go's file system internals don't expect syscalls that succeed without an error to return an invalid file descriptor. Yarn is working on fixing their use of invalid file descriptors.v0.15.1Compare Source
Update esbuild's Yarn Plug'n'Play implementation to match the latest specification changes (#2452, #2453)
This release updates esbuild's implementation of Yarn Plug'n'Play to match some changes to Yarn's specification that just landed. The changes are as follows:
Check for platform-specific absolute paths instead of always for the
/prefixThe specification previously said that Yarn Plug'n'Play path resolution rules should not apply for paths that start with
/. The intent was to avoid accidentally processing absolute paths. However, absolute paths on Windows such asC:\projectstart with drive letters instead of with/. So the specification was changed to instead explicitly avoid processing absolute paths.Make
$$virtualan alias for__virtual__Supporting Yarn-style path resolution requires implementing a custom Yarn-specific path traversal scheme where certain path segments are considered no-ops. Specifically any path containing segments of the form
__virtual__/<whatever>/<n>where<n>is an integer must be treated as if they werentimes the..operator instead (the<whatever>path segment is ignored). So/path/to/project/__virtual__/xyz/2/foo.jsmaps to the underlying file/path/to/project/../../foo.js. This scheme makes it possible for Yarn to get node (and esbuild) to load the same file multiple times (which is sometimes required for correctness) without actually duplicating the file on the file system.However, old versions of Yarn used to use
$$virtualinstead of__virtual__. This was changed because$$virtualwas error-prone due to the use of the$character, which can cause bugs when it's not correctly escaped within regular expressions. Now that esbuild makes$$virtualan alias for__virtual__, esbuild should now work with manifests from these old Yarn versions.Ignore PnP manifests in virtual directories
The specification describes the algorithm for how to find the Plug'n'Play manifest when starting from a certain point in the file system: search through all parent directories in reverse order until the manifest is found. However, this interacts poorly with virtual paths since it can end up finding a virtual copy of the manifest instead of the original. To avoid this, esbuild now ignores manifests in virtual directories so that the search for the manifest will continue and find the original manifest in another parent directory later on.
These fixes mean that esbuild's implementation of Plug'n'Play now matches Yarn's implementation more closely, and esbuild can now correctly build more projects that use Plug'n'Play.
v0.15.0Compare Source
This release contains backwards-incompatible changes. Since esbuild is before version 1.0.0, these changes have been released as a new minor version to reflect this (as recommended by npm). You should either be pinning the exact version of
esbuildin yourpackage.jsonfile or be using a version range syntax that only accepts patch upgrades such as~0.14.0. See the documentation about semver for more information.Implement the Yarn Plug'n'Play module resolution algorithm (#154, #237, #1263, #2451)
Node comes with a package manager called npm, which installs packages into a
node_modulesfolder. Node and esbuild both come with built-in rules for resolving import paths to packages withinnode_modules, so packages installed via npm work automatically without any configuration. However, many people use an alternative package manager called Yarn. While Yarn can install packages usingnode_modules, it also offers a different package installation strategy called Plug'n'Play, which is often shortened to "PnP" (not to be confused with pnpm, which is an entirely different unrelated package manager).Plug'n'Play installs packages as
.zipfiles on your file system. The packages are never actually unzipped. Since Node doesn't know anything about Yarn's package installation strategy, this means you can no longer run your code with Node as it won't be able to find your packages. Instead, you need to run your code with Yarn, which applies patches to Node's file system APIs before running your code. These patches attempt to make zip files seem like normal directories. When running under Yarn, using Node's file system API to read./some.zip/lib/file.jsactually automatically extractslib/file.jsfrom./some.zipat run-time as if it was a normal file. Other file system APIs behave similarly. However, these patches don't work with esbuild because esbuild is not written in JavaScript; it's a native binary executable that interacts with the file system directly through the operating system.Previously the workaround for using esbuild with Plug'n'Play was to use the
@yarnpkg/esbuild-plugin-pnpplugin with esbuild's JavaScript API. However, this wasn't great because the plugin needed to potentially intercept every single import path and file load to check whether it was a Plug'n'Play package, which has an unusually high performance cost. It also meant that certain subtleties of path resolution rules within a.zipfile could differ slightly from the way esbuild normally works since path resolution inside.zipfiles was implemented by Yarn, not by esbuild (which is due to a limitation of esbuild's plugin API).With this release, esbuild now contains an independent implementation of Yarn's Plug'n'Play algorithm (which is used when esbuild finds a
.pnp.js,.pnp.cjs, or.pnp.data.jsonfile in the directory tree). Creating additional implementations of this algorithm recently became possible because Yarn's package manifest format was recently documented: https://yarnpkg.com/advanced/pnp-spec/. This should mean that you can now use esbuild to bundle Plug'n'Play projects without any additional configuration (so you shouldn't need@yarnpkg/esbuild-plugin-pnpanymore). Bundling these projects should now happen much faster as Yarn no longer even needs to be run at all. Bundling the Yarn codebase itself with esbuild before and after this change seems to demonstrate over a 10x speedup (3.4s to 0.24s). And path resolution rules within Yarn packages should now be consistent with how esbuild handles regular Node packages. For example, fields such asmoduleandbrowserinpackage.jsonfiles within.zipfiles should now be respected.Keep in mind that this is brand new code and there may be some initial issues to work through before esbuild's implementation is solid. Yarn's Plug'n'Play specification is also brand new and may need some follow-up edits to guide new implementations to match Yarn's exact behavior. If you try this out, make sure to test it before committing to using it, and let me know if anything isn't working as expected. Should you need to debug esbuild's path resolution, you may find
--log-level=verbosehelpful.v0.14.54Compare Source
Fix optimizations for calls containing spread arguments (#2445)
This release fixes the handling of spread arguments in the optimization of
/* @​__PURE__ */comments, empty functions, and identity functions:Previously esbuild assumed arguments with side effects could be directly inlined. This is almost always true except for spread arguments, which are not syntactically valid on their own and which have the side effect of causing iteration, which might have further side effects. Now esbuild will wrap these elements in an unused array so that they are syntactically valid and so that the iteration side effects are preserved.
v0.14.53Compare Source
This release fixes a minor issue with the previous release: I had to rename the package
esbuild-linux-loong64to@esbuild/linux-loong64in the contributed PR because someone registered the package name before I could claim it, and I missed a spot. Hopefully everything is working after this release. I plan to change all platform-specific package names to use the@esbuild/scope at some point to avoid this problem in the future.v0.14.52Compare Source
Allow binary data as input to the JS
transformandbuildAPIs (#2424)Previously esbuild's
transformandbuildAPIs could only take a string. However, some people want to use esbuild to convert binary data to base64 text. This is problematic because JavaScript strings represent UTF-16 text and esbuild internally operates on arrays of bytes, so all strings coming from JavaScript undergo UTF-16 to UTF-8 conversion before use. This meant that using esbuild in this way was doing base64 encoding of the UTF-8 encoding of the text, which was undesired.With this release, esbuild now accepts
Uint8Arrayin addition to string as an input format for thetransformandbuildAPIs. Now you can use esbuild to convert binary data to base64 text:Update the getter for
textin build results (#2423)Output files in build results returned from esbuild's JavaScript API have both a
contentsand atextproperty to return the contents of the output file. Thecontentsproperty is a binary UTF-8 Uint8Array and thetextproperty is a JavaScript UTF-16 string. Thetextproperty is a getter that does the UTF-8 to UTF-16 conversion only if it's needed for better performance.Previously if you mutate the build results object, you had to overwrite both
contentsandtextsince the value returned from thetextgetter is the original text returned by esbuild. Some people find this confusing so with this release, the getter fortexthas been updated to do the UTF-8 to UTF-16 conversion on the current value of thecontentsproperty instead of the original value.Publish builds for Linux LoongArch 64-bit (#1804, #2373)
This release upgrades to Go 1.19, which now includes support for LoongArch 64-bit processors. LoongArch 64-bit builds of esbuild will now be published to npm, which means that in theory they can now be installed with
npm install esbuild. This was contributed by @beyond-1234.v0.14.51Compare Source
Add support for React 17's
automaticJSX transform (#334, #718, #1172, #2318, #2349)This adds support for the new "automatic" JSX runtime from React 17+ to esbuild for both the build and transform APIs.
New CLI flags and API options:
--jsx,jsx— Set this to"automatic"to opt in to this new transform--jsx-dev,jsxDev— Toggles development mode for the automatic runtime--jsx-import-source,jsxImportSource— Overrides the root import for runtime functions (default"react")New JSX pragma comments:
@jsxRuntime— Sets the runtime (automaticorclassic)@jsxImportSource— Sets the import source (only valid with automatic runtime)The existing
@jsxFragmentand@jsxFactorypragma comments are only valid with "classic" runtime.TSConfig resolving:
Along with accepting the new options directly via CLI or API, option inference from
tsconfig.jsoncompiler options was also implemented:"jsx": "preserve"or"jsx": "react-native"→ Same as--jsx=preservein esbuild"jsx": "react"→ Same as--jsx=transformin esbuild (which is the default behavior)"jsx": "react-jsx"→ Same as--jsx=automaticin esbuild"jsx": "react-jsxdev"→ Same as--jsx=automatic --jsx-devin esbuildIt also reads the value of
"jsxImportSource"fromtsconfig.jsonif specified.For
react-jsxit's important to note that it doesn't implicitly disable--jsx-dev. This is to support the case where a user sets"react-jsx"in theirtsconfig.jsonbut then toggles development mode directly in esbuild.esbuild vs Babel vs TS vs...
There are a few differences between the various technologies that implement automatic JSX runtimes. The JSX transform in esbuild follows a mix of Babel's and TypeScript's behavior:
When an element has
__sourceor__selfprops:Element has an "implicit true" key prop, e.g.
<a key />:Element has spread children, e.g.
<a>{...children}</a>Also note that TypeScript has some bugs regarding JSX development mode and the generation of
lineNumberandcolumnNumbervalues. Babel's values are accurate though, so esbuild's line and column numbers match Babel. Both numbers are 1-based and columns are counted in terms of UTF-16 code units.This feature was contributed by @jgoz.
v0.14.50Compare Source
Emit
namesin source maps (#1296)The source map specification includes an optional
namesfield that can associate an identifier with a mapping entry. This can be used to record the original name for an identifier, which is useful if the identifier was renamed to something else in the generated code. When esbuild was originally written, this field wasn't widely used, but now there are some debuggers that make use of it to provide better debugging of minified code. With this release, esbuild now includes anamesfield in the source maps that it generates. To save space, the original name is only recorded when it's different from the final name.Update parser for arrow functions with initial default type parameters in
.tsxfiles (#2410)TypeScript 4.6 introduced a change to the parsing of JSX syntax in
.tsxfiles. Now a<token followed by an identifier and then a=token is parsed as an arrow function with a default type parameter instead of as a JSX element. This release updates esbuild's parser to match TypeScript's parser.Fix an accidental infinite loop with
--definesubstitution (#2407)This is a fix for a regression that was introduced in esbuild version 0.14.44 where certain
--definesubstitutions could result in esbuild crashing with a stack overflow. The problem was an incorrect fix for #2292. The fix merged the code paths for--defineand--jsx-factoryrewriting since the value substitution is now the same for both. However, doing this accidentally made--definesubstitution recursive since the JSX factory needs to be able to match against--definesubstitutions to integrate with the--injectfeature. The fix is to only do one additional level of matching against define substitutions, and to only do this for JSX factories. Now these cases are able to build successfully without a stack overflow.Include the "public path" value in hashes (#2403)
The
--public-path=configuration value affects the paths that esbuild uses to reference files from other files and is used in various situations such as cross-chunk imports in JS and references to asset files from CSS files. However, it wasn't included in the hash calculations used for file names due to an oversight. This meant that changing the public path setting incorrectly didn't result in the hashes in file names changing even though the contents of the files changed. This release fixes the issue by including a hash of the public path in all non-asset output files.Fix a cross-platform consistency bug (#2383)
Previously esbuild would minify
0xFFFF_FFFF_FFFF_FFFFas0xffffffffffffffff(18 bytes) on arm64 chips and as18446744073709552e3(19 bytes) on x86_64 chips. The reason was that the number was converted to a 64-bit unsigned integer internally for printing as hexadecimal, the 64-bit floating-point number0xFFFF_FFFF_FFFF_FFFFis actually0x1_0000_0000_0000_0180(i.e. it's rounded up, not down), and convertingfloat64touint64is implementation-dependent in Go when the input is out of bounds. This was fixed by changing the upper limit for which esbuild uses hexadecimal numbers during minification to0xFFFF_FFFF_FFFF_F800, which is the next representable 64-bit floating-point number below0x1_0000_0000_0000_0180, and which fits in auint64. As a result, esbuild will now consistently never minify0xFFFF_FFFF_FFFF_FFFFas0xffffffffffffffffanymore, which means the output should now be consistent across platforms.Fix a hang with the synchronous API when the package is corrupted (#2396)
An error message is already thrown when the esbuild package is corrupted and esbuild can't be run. However, if you are using a synchronous call in the JavaScript API in worker mode, esbuild will use a child worker to initialize esbuild once so that the overhead of initializing esbuild can be amortized across multiple synchronous API calls. However, errors thrown during initialization weren't being propagated correctly which resulted in a hang while the main thread waited forever for the child worker to finish initializing. With this release, initialization errors are now propagated correctly so calling a synchronous API call when the package is corrupted should now result in an error instead of a hang.
Fix
tsconfig.jsonfiles that collide with directory names (#2411)TypeScript lets you write
tsconfig.jsonfiles withextendsclauses that refer to another config file using an implicit.jsonfile extension. However, if the config file without the.jsonextension existed as a directory name, esbuild and TypeScript had different behavior. TypeScript ignores the directory and continues looking for the config file by adding the.jsonextension while esbuild previously terminated the search and then failed to load the config file (because it's a directory). With this release, esbuild will now ignore exact matches when resolvingextendsfields intsconfig.jsonfiles if the exact match results in a directory.Add
platformto the transform API (#2362)The
platformoption is mainly relevant for bundling because it mostly affects path resolution (e.g. activating the"browser"field inpackage.jsonfiles), so it was previously only available for the build API. With this release, it has additionally be made available for the transform API for a single reason: you can now set--platform=nodewhen transforming a string so that esbuild will add export annotations for node, which is only relevant when--format=cjsis also present.This has to do with an implementation detail of node that parses the AST of CommonJS files to discover named exports when importing CommonJS from ESM. However, this new addition to esbuild's API is of questionable usefulness. Node's loader API (the main use case for using esbuild's transform API like this) actually bypasses the content returned from the loader and parses the AST that's present on the file system, so you won't actually be able to use esbuild's API for this. See the linked issue for more information.
v0.14.49Compare Source
Keep inlined constants when direct
evalis present (#2361)Version 0.14.19 of esbuild added inlining of certain
constvariables during minification, which replaces all references to the variable with the initializer and then removes the variable declaration. However, this could generate incorrect code when directevalis present because the directevalcould reference the constant by name. This release fixes the problem by preserving theconstvariable declaration in this case:Fix an incorrect error in TypeScript when targeting ES5 (#2375)
Previously when compiling TypeScript code to ES5, esbuild could incorrectly consider the following syntax forms as a transformation error:
The error messages looked like this:
These parenthesized literals followed by a colon look like the start of an arrow function expression followed by a TypeScript return type (e.g.
([]) : 1could be the start of the TypeScript arrow function([]): 1 => 1). Unlike in JavaScript, parsing arrow functions in TypeScript requires backtracking. In this case esbuild correctly determined that this expression wasn't an arrow function after all but the check for destructuring was incorrectly not covered under the backtracking process. With this release, the error message is now only reported if the parser successfully parses an arrow function without backtracking.Fix generated TypeScript
enumcomments containing*/(#2369, #2371)TypeScript
enumvalues that are equal to a number or string literal are inlined (references to the enum are replaced with the literal value) and have a/* ... */comment after them with the original enum name to improve readability. However, this comment is omitted if the enum name contains the character sequence*/because that would end the comment early and cause a syntax error:This was originally handled correctly when TypeScript
enuminlining was initially implemented since it was only supported within a single file. However, when esbuild was later extended to support TypeScriptenuminlining across files, this special case where the enum name contains*/was not handled in that new code. Starting with this release, esbuild will now handle enums with names containing*/correctly when they are inlined across files:This fix was contributed by @magic-akari.
Allow
declareclass fields to be initialized (#2380)This release fixes an oversight in the TypeScript parser that disallowed initializers for
declareclass fields. TypeScript actually allows the following limited initializer expressions forreadonlyfields:So with this release, esbuild now allows initializers for
declareclass fields too. To future-proof this in case TypeScript allows more expressions as initializers in the future (such asnull), esbuild will allow any expression as an initializer and will leave the specifics of TypeScript's special-casing here to the TypeScript type checker.Fix a bug in esbuild's feature compatibility table generator (#2365)
Passing specific JavaScript engines to esbuild's
--targetflag restricts esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates. The data for this feature is automatically derived from this compatibility table with a script: https://kangax.github.io/compat-table/.However, the script had a bug that could incorrectly consider a JavaScript syntax feature to be supported in a given engine even when it doesn't actually work in that engine. Specifically this bug happened when a certain aspect of JavaScript syntax has always worked incorrectly in that engine and the bug in that engine has never been fixed. This situation hasn't really come up before because previously esbuild pretty much only targeted JavaScript engines that always fix their bugs, but the two new JavaScript engines that were added in the previous release (Hermes and Rhino) have many aspects of the JavaScript specification that have never been implemented, and may never be implemented. For example, the
letandconstkeywords are not implemented correctly in those engines.With this release, esbuild's compatibility table generator script has been fixed and as a result, esbuild will now correctly consider a JavaScript syntax feature to be unsupported in a given engine if there is some aspect of that syntax that is broken in all known versions of that engine. This means that the following JavaScript syntax features are no longer considered to be supported by these engines (represented using esbuild's internal names for these syntax features):
Hermes:
arrowconst-and-letdefault-argumentgeneratoroptional-catch-bindingoptional-chainrest-argumenttemplate-literalRhino:
arrowconst-and-letdestructuringfor-ofgeneratorobject-extensionstemplate-literalIE:
const-and-letv0.14.48Compare Source
Enable using esbuild in Deno via WebAssembly (#2323)
The native implementation of esbuild is much faster than the WebAssembly version, but some people don't want to give Deno the
--allow-runpermission necessary to run esbuild and are ok waiting longer for their builds to finish when using the WebAssembly backend. With this release, you can now use esbuild via WebAssembly in Deno. To do this you will need to import fromwasm.jsinstead ofmod.js:Make sure you run Deno with
--allow-netso esbuild can download the WebAssembly module. Using esbuild like this starts up a worker thread that runs esbuild in parallel (unless you callesbuild.initialize({ worker: false })to tell esbuild to run on the main thread). If you want to, you can callesbuild.stop()to terminate the worker if you won't be using esbuild anymore and you want to reclaim the memory.Note that Deno appears to have a bug where background WebAssembly optimization can prevent the process from exiting for many seconds. If you are trying to use Deno and WebAssembly to run esbuild quickly, you may need to manually call
Deno.exit(0)after your code has finished running.Add support for font file MIME types (#2337)
This release adds support for font file MIME types to esbuild, which means they are now recognized by the built-in local web server and they are now used when a font file is loaded using the
dataurlloader. The full set of newly-added file extension MIME type mappings is as follows:.eot=>application/vnd.ms-fontobject.otf=>font/otf.sfnt=>font/sfnt.ttf=>font/ttf.woff=>font/woff.woff2=>font/woff2Remove
"use strict";when targeting ESM (#2347)All ES module code is automatically in strict mode, so a
"use strict";directive is unnecessary. With this release, esbuild will now remove the"use strict";directive if the output format is ESM. This change makes the generated output file a few bytes smaller:Attempt to have esbuild work with Deno on FreeBSD (#2356)
Deno doesn't support FreeBSD, but it's possible to build Deno for FreeBSD with some additional patches on top. This release of esbuild changes esbuild's Deno installer to download esbuild's FreeBSD binary in this situation. This configuration is unsupported although in theory everything should work.
Add some more target JavaScript engines (#2357)
This release adds the Rhino and Hermes JavaScript engines to the set of engine identifiers that can be passed to the
--targetflag. You can use this to restrict esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates.v0.14.47Compare Source
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=chrome80or--supported:logical-assignment=false):Fix
--mangle-quoted=falsewith--minify-syntax=trueIf property mangling is active and
--mangle-quotedis disabled, quoted properties are supposed to be preserved. However, there was a case when this didn't happen if--minify-syntaxwas enabled, since that internally transformsx['y']intox.yto reduce code size. This issue has been fixed:Notice how the property
foois always used unquoted but the propertybaris always used quoted, sofooshould be consistently mangled whilebarshould be consistently not mangled.Fix a minification bug regarding
thisand 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
thiswhen the initializer is a property access and the start of the following expression is a call expression. This release fixes the bug:v0.14.46Compare Source
Add the ability to override support for individual syntax features (#2060, #2290, #2308)
The
targetsetting already lets you configure esbuild to restrict its output by only making use of syntax features that are known to be supported in the configured target environment. For example, settingtargettochrome50causes esbuild to automatically transform optional chain expressions into the equivalent older JavaScript and prevents you from using BigInts, among many other things. However, sometimes you may want to customize this set of unsupported syntax features at the individual feature level.Some examples of why you might want to do this:
JavaScript runtimes often do a quick implementation of newer syntax features that is slower than the equivalent older JavaScript, and you can get a speedup by telling esbuild to pretend this syntax feature isn't supported. For example, V8 has a long-standing performance bug regarding object spread that can be avoided by manually copying properties instead of using object spread syntax. Right now esbuild hard-codes this optimization if you set
targetto a V8-based runtime.There are many less-used JavaScript runtimes in addition to the ones present in browsers, and these runtimes sometimes just decide not to implement parts of the specification, which might make sense for runtimes intended for embedded environments. For example, the developers behind Facebook's JavaScript runtime Hermes have decided to not implement classes despite it being a major JavaScript feature that was added seven years ago and that is used in virtually every large JavaScript project.
You may be processing esbuild's output with another tool, and you may want esbuild to transform certain features and the other tool to transform certain other features. For example, if you are using esbuild to transform files individually to ES5 but you are then feeding the output into Webpack for bundling, you may want to preserve
import()expressions even though they are a syntax error in ES5.With this release, you can now use
--supported:feature=falseto forcefeatureto be unsupported. This will cause esbuild to either rewrite code that uses the feature into older code that doesn't use the feature (if esbuild is able to), or to emit a build error (if esbuild is unable to). For example, you can use--supported:arrow=falseto turn arrow functions into function expressions and--supported:bigint=falseto make it an error to use a BigInt literal. You can also use--supported:feature=trueto force it to be supported, which means esbuild will pass it through without transforming it. Keep in mind that this is an advanced feature. For most use cases you will probably want to just usetargetinstead of using this.The full set of currently-allowed features are as follows:
JavaScript:
arbitrary-module-namespace-namesarray-spreadarrowasync-awaitasync-generatorbigintclassclass-fieldclass-private-accessorclass-private-brand-checkclass-private-fieldclass-private-methodclass-private-static-accessorclass-private-static-fieldclass-private-static-methodclass-static-blocksclass-static-fieldconst-and-letdefault-argumentdestructuringdynamic-importexponent-operatorexport-star-asfor-awaitfor-ofgeneratorhashbangimport-assertionsimport-metalogical-assignmentnested-rest-bindingnew-targetnode-colon-prefix-importnode-colon-prefix-requirenullish-coalescingobject-accessorsobject-extensionsobject-rest-spreadoptional-catch-bindingoptional-chainregexp-dot-all-flagregexp-lookbehind-assertionsregexp-match-indicesregexp-named-capture-groupsregexp-sticky-and-unicode-flagsregexp-unicode-property-escapesrest-argumenttemplate-literaltop-level-awaittypeof-exotic-object-is-objectunicode-escapesCSS:
hex-rgbarebecca-purplemodern-rgb-hslinset-propertynestingSince you can now specify
--supported:object-rest-spread=falseyourself to work around the V8 performance issue mentioned above, esbuild will no longer automatically transform all instances of object spread when targeting a V8-based JavaScript runtime going forward.Note that JavaScript feature transformation is very complex and allowing full customization of the set of supported syntax features could cause bugs in esbuild due to new interactions between multiple features that were never possible before. Consider this to be an experimental feature.
Implement
extendsconstraints oninfertype variables (#2330)TypeScript 4.7 introduced the ability to write an
extendsconstraint after aninfertype variable, which looks like this:You can read the blog post for more details: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#extends-constraints-on-infer-type-variables. Previously this was a syntax error in esbuild but with this release, esbuild can now parse this syntax correctly.
Allow
defineto match optional chain expressions (#2324)Previously esbuild's
definefeature only matched member expressions that did not use optional chaining. With this release, esbuild will now also match those that use optional chaining:This is for compatibility with Webpack's
DefinePlugin, which behaves the same way.v0.14.45Compare Source
Add a log message for ambiguous re-exports (#2322)
In JavaScript, you can re-export symbols from another file using
export * from './another-file'. When you do this from multiple files that export different symbols with the same name, this creates an ambiguous export which is causes that name to not be exported. This is harmless if you don't plan on using the ambiguous export name, so esbuild doesn't have a warning for this. But if you do want a warning for this (or if you want to make it an error), you can now opt-in to seeing this log message with--log-override:ambiguous-reexport=warningor--log-override:ambiguous-reexport=error. The log message looks like this:Optimize the output of the JSON loader (#2161)
The
jsonloader (which is enabled by default for.jsonfiles) parses the file as JSON and generates a JavaScript file with the parsed expression as thedefaultexport. This behavior is standard and works in both node and the browser (well, as long as you use an import assertion). As an extension, esbuild also allows you to import additional top-level properties of the JSON object directly as a named export. This is beneficial for tree shaking. For example:If you bundle the above code with esbuild, you'll get something like the following:
Most of the
package.jsonfile is irrelevant and has been omitted from the output due to tree shaking. The way esbuild implements this is to have the JavaScript file that's generated from the JSON look something like this with a separate exported variable for each property on the top-level object:However, this means that if you import the
defaultexport instead of a named export, you will get non-optimal output. Thedefaultexport references all top-level properties, leading to many unnecessary variables in the output. With this release esbuild will now optimize this case to only generate additional variables for top-level object properties that are actually imported:Notice how there is no longer an unnecessary generated variable for
foosince it's never imported. And if you only import thedefaultexport, esbuild will now reproduce the original JSON object in the output with all top-level properties compactly inline.Add
idto warnings returned from the APIWith this release, warnings returned from e
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.