esbuild 0.8.35
-
Fix a commonly-missed corner case with
awaitinside**I recently discovered an interesting discussion about JavaScript syntax entitled "Most implementations seem to have missed that
await x ** 2is not legal". Indeed esbuild has missed this, but this is not surprising because V8 has missed this as well and I usually test esbuild against V8 to test if esbuild is conformant with the JavaScript standard. Regardless, it sounds like the result of the discussion is that the specification should stay the same and implementations should be fixed. This release fixes this bug in esbuild's parser. The syntaxawait x ** 2is no longer allowed and parentheses are now preserved for the syntax(await x) ** 2. -
Allow namespaced names in JSX syntax (#702)
XML-style namespaced names with a
:in the middle are a part of the JSX specification but they are explicitly unimplemented by React and TypeScript so esbuild doesn't currently support them. However, there was a user request to support this feature since it's part of the JSX specification and esbuild's JSX support can be used for non-React purposes. So this release now supports namespaced names in JSX expressions:let xml = <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <rdf:Description rdf:ID="local-record"> <dc:title>Local Record</dc:title> </rdf:Description> </rdf:RDF>This JSX expression is now transformed by esbuild to the following JavaScript:
let xml = React.createElement("rdf:RDF", { "xmlns:rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "xmlns:dc": "http://purl.org/dc/elements/1.1/" }, React.createElement("rdf:Description", { "rdf:ID": "local-record" }, React.createElement("dc:title", null, "Local Record")));Note that if you are trying to namespace your React components, this is not the feature to use. You should be using a
.instead of a:for namespacing your React components since.resolves to a JavaScript property access. -
Fix
worker: falsein esbuild's browser-based JavaScript APIThe browser-based JavaScript API creates a web worker by default but this can be disabled by passing
worker: false. When you do this the WebAssembly code is run in the current thread which will lock up the thread. This is mainly useful if you're calling the JavaScript API from within a web worker and you want to avoid creating another nested web worker.This option was unintentionally broken when the internal JavaScript web worker source code was moved from an inline function to a string in version 0.5.20. The regression has been fixed and the
worker: falsescenario now has test coverage. -
Fix absolute paths with the
esbuild-wasmpackage on Windows (#687)The package
esbuild-wasmhas anesbuildcommand implemented using WebAssembly instead of using native code. It uses node's WebAssembly implementation and calls methods on node'sfsmodule to access the file system.Go's
path/filepathmodule has a bug where Windows paths are interpreted as Unix paths when targeting WebAssembly: golang/go#43768. This causes multiple issues including absolute paths such asC:\path\to\file.jsbeing interpreted as relative paths (since they don't start with a/) and being joined onto the end of other paths.To fix this, esbuild now does all of its own path handling instead of using Go's path handling code. The esbuild code base now contains a forked copy of
path/filepaththat can handle both Windows and Unix paths. The decision about which one to use is made at run-time. When targeting WebAssembly, the presence of theC:\directory is used to determine if Windows-style paths should be used.With this release, it should now be possible to use Windows-style paths with esbuild's WebAssembly implementation on Windows.
-
Fix using stdin with the
esbuild-wasmpackage on Windows (#687)Node has an old bug (nodejs/node#19831, nodejs/node#35997) where
fs.readreturns an EOF error at the end of stdin on Windows. This causes Go's WebAssembly implementation to panic when esbuild tries to read from stdin.The workaround was to manually check for this case and then ignore the error in this specific case. With this release, it should now be possible to pipe something to the
esbuildcommand on Windows. -
Fix stdout and stderr not supporting Unicode in the
esbuild-wasmpackage on Windows (#687)Node's
fs.writeAPI is broken when writing Unicode to stdout and stderr on Windows, and this will never be fixed: nodejs/node#24550. This is problematic for Go's WebAssembly implementation because it uses this API for writing to all file descriptors.The workaround is to manually intercept the file descriptors for stdout and stderr and redirect them to
process.stdoutandprocess.stderrrespectively. Passing Unicode text towrite()on these objects instead of on thefsAPI strangely works fine. So with this release, Unicode text should now display correctly when using esbuild's WebAssembly implementation on Windows (or at least, as correctly as the poor Unicode support in Windows Command Prompt allows). -
Add a hack for faster command-line execution for the WebAssembly module in certain cases
Node has an unfortunate bug where the node process is unnecessarily kept open while a WebAssembly module is being optimized: https://github.com/nodejs/node/issues/36616. This means cases where running
esbuildshould take a few milliseconds can end up taking many seconds instead.The workaround is to force node to exit by ending the process early. This is done in one of two ways depending on the exit code. For non-zero exit codes (i.e. when there is a build error), the
esbuildcommand now callsprocess.kill(process.pid)to avoid the hang.For zero exit codes, the
esbuildcommand now loads a N-API native node extension that calls the operating system'sexit(0)function. This is done without requiringnode-gypby precompiling each supported platform and just including all of them in theesbuild-wasmpackage since they are so small. If this hack doesn't work in certain cases, the process should exit anyway just potentially many seconds later. Currently the only supported platforms for this hack are 64-bit macOS, Windows, and Linux. -
Fix non-absolute paths with the
esbuild-wasmpackage in the browser (#693)When using esbuild in the browser via WebAssembly, it was not possible to specify an non-absolute output path. Normally you can do this and esbuild will just convert it to an absolute path by resolving it as a relative path from the current working directory. However, Go's WebAssembly implementation has no current working directory so the conversion operation to an absolute path failed, causing esbuild's API to fail.
With this release, esbuild should now behave as if the current working directory is
/in the browser. For example, this means calling thebuild()API withoutfile: 'file.js'should now generate an output file called/file.jsinstead of causing an error.