github.com/evanw/esbuild@v0.21.4/CHANGELOG-2020.md (about) 1 # Changelog: 2020 2 3 This changelog documents all esbuild versions published in the year 2020 (versions 0.3.0 through 0.8.28). 4 5 ## 0.8.28 6 7 * Add a `--summary` flag that prints helpful information after a build ([#631](https://github.com/evanw/esbuild/issues/631)) 8 9 Normally esbuild's CLI doesn't print anything after doing a build if nothing went wrong. This allows esbuild to be used as part of a more complex chain of tools without the output cluttering the terminal. However, sometimes it is nice to have a quick overview in your terminal of what the build just did. You can now add the `--summary` flag when using the CLI and esbuild will print a summary of what the build generated. It looks something like this: 10 11 ``` 12 $ ./esbuild --summary --bundle src/Three.js --outfile=build/three.js --sourcemap 13 14 build/three.js 1.0mb ⚠️ 15 build/three.js.map 1.8mb 16 17 ⚡ Done in 43ms 18 ``` 19 20 * Keep unused imports in TypeScript code in one specific case ([#604](https://github.com/evanw/esbuild/issues/604)) 21 22 The official TypeScript compiler always removes imported symbols that aren't used as values when converting TypeScript to JavaScript. This is because these symbols could be types and not removing them could result in a run-time module instantiation failure because of missing exports. This even happens when the `tsconfig.json` setting `"importsNotUsedAsValues"` is set to `"preserve"`. Doing this just keeps the import statement itself but confusingly still removes the imports that aren't used as values. 23 24 Previously esbuild always exactly matched the behavior of the official TypeScript compiler regarding import removal. However, that is problematic when trying to use esbuild to compile a partial module such as when converting TypeScript to JavaScript inside a file written in the [Svelte](https://svelte.dev/) programming language. Here is an example: 25 26 ```html 27 <script lang="ts"> 28 import Counter from './Counter.svelte'; 29 export let name: string = 'world'; 30 </script> 31 <main> 32 <h1>Hello {name}!</h1> 33 <Counter /> 34 </main> 35 ``` 36 37 The current Svelte compiler plugin for TypeScript only provides esbuild with the contents of the `<script>` tag so to esbuild, the import `Counter` appears to be unused and is removed. 38 39 In this release, esbuild deliberately deviates from the behavior of the official TypeScript compiler if all of these conditions are met: 40 41 * The `"importsNotUsedAsValues"` field in `tsconfig.json` must be present and must not be set to `"remove"`. This is necessary because this is the only case where esbuild can assume that all imports are values instead of types. Any imports that are types will cause a type error when the code is run through the TypeScript type checker. To import types when the `importsNotUsedAsValues` setting is active, you must use the TypeScript-specific `import type` syntax instead. 42 43 * You must not be using esbuild as a bundler. When bundling, esbuild needs to assume that it's not seeing a partial file because the bundling process requires renaming symbols to avoid cross-file name collisions. 44 45 * You must not have identifier minification enabled. It's useless to preserve unused imports in this case because referencing them by name won't work anyway. And keeping the unused imports would be counter-productive to minification since they would be extra unnecessary data in the output file. 46 47 This should hopefully allow esbuild to be used as a TypeScript-to-JavaScript converter for programming languages such as Svelte, at least in many cases. The build pipeline in esbuild wasn't designed for compiling partial modules and this still won't be a fully robust solution (e.g. some variables may be renamed to avoid name collisions in rare cases). But it's possible that these cases are very unlikely to come up in practice. Basically this change to keep unused imports in this case should be useful at best and harmless at worst. 48 49 ## 0.8.27 50 51 * Mark `import.meta` as supported in node 10.4+ ([#626](https://github.com/evanw/esbuild/issues/626)) 52 53 It was previously marked as unsupported due to a typo in esbuild's compatibility table, which meant esbuild generated a shim for `import.meta` even when it's not necessary. It should now be marked as supported in node 10.4 and above so the shim will no longer be included when using a sufficiently new target environment such as `--target=node10.4`. 54 55 * Fix for when the working directory ends with `/` ([#627](https://github.com/evanw/esbuild/issues/627)) 56 57 If the working directory ended in `/`, the last path component would be incorrectly duplicated. This was the case when running esbuild with Yarn 2 (but not Yarn 1) and is problematic because some externally-facing directories reference the current working directory in plugins and in output files. The problem has now been fixed and the last path component is no longer duplicated in this case. This fix was contributed by [@remorses](https://github.com/remorses). 58 59 * Add an option to omit `sourcesContent` from generated source maps ([#624](https://github.com/evanw/esbuild/issues/624)) 60 61 You can now pass `--sources-content=false` to omit the `sourcesContent` field from generated source maps. The field embeds the original source code inline in the source map and is the largest part of the source map. This is useful if you don't need the original source code and would like a smaller source map (e.g. you only care about stack traces and don't need the source code for debugging). 62 63 * Fix exports from ESM files converted to CJS during code splitting ([#617](https://github.com/evanw/esbuild/issues/617)) 64 65 This release fixes an edge case where files in ECMAScript module format that are converted to CommonJS format during bundling can generate exports to non-top-level symbols when code splitting is active. These files must be converted to CommonJS format if they are referenced by a `require()` call. When that happens, the symbols in that file are placed inside the CommonJS wrapper closure and are no longer top-level symbols. This means they should no longer be considered exportable for cross-chunk export generation due to code splitting. The result of this fix is that these cases no longer generate output files with module instantiation errors. 66 67 * Allow `--define` with array and object literals ([#581](https://github.com/evanw/esbuild/issues/581)) 68 69 The `--define` feature allows you to replace identifiers such as `DEBUG` with literal expressions such as `false`. This is valuable because the substitution can then participate in constant folding and dead code elimination. For example, `if (DEBUG) { ... }` could become `if (false) { ... }` which would then be completely removed in minified builds. However, doing this with compound literal expressions such as array and object literals is an anti-pattern because it could easily result in many copies of the same object in the output file. 70 71 This release adds support for array and object literals with `--define` anyway, but they work differently than other `--define` expressions. In this case a separate virtual file is created and configured to be injected into all files similar to how the `--inject` feature works. This means there is only at most one copy of the value in a given output file. However, these values do not participate in constant folding and dead code elimination, since the object can now potentially be mutated at run-time. 72 73 ## 0.8.26 74 75 * Ensure the current working directory remains unique per `startService()` call 76 77 The change in version 0.8.24 to share service instances caused problems for code that calls `process.chdir()` before calling `startService()` to be able to get a service with a different working directory. With this release, calls to `startService()` no longer share the service instance if the working directory was different at the time of creation. 78 79 * Consider import references to be side-effect free ([#613](https://github.com/evanw/esbuild/issues/613)) 80 81 This change improves tree shaking for code containing top-level references to imported symbols such as the following code: 82 83 ```js 84 import {Base} from './base' 85 export class Derived extends Base {} 86 ``` 87 88 Identifier references are considered side-effect free if they are locally-defined, but esbuild special-cases identifier references to imported symbols in its AST (the identifier `Base` in this example). This meant they did not trigger this check and so were not considered locally-defined and therefore side-effect free. That meant that `Derived` in this example would never be tree-shaken. 89 90 The reason for this is that the side-effect determination is made during parsing and during parsing it's not yet known if `./base` is a CommonJS module or not. If it is, then `Base` would be a dynamic run-time property access on `exports.Base` which could hypothetically be a property with a getter that has side effects. Therefore it could be considered incorrect to remove this code due to tree-shaking because there is technically a side effect. 91 92 However, this is a very unlikely edge case and not tree-shaking this code violates developer expectations. So with this release, esbuild will always consider references to imported symbols as being side-effect free. This also aligns with ECMAScript module semantics because with ECMAScript modules, it's impossible to have a user-defined getter for an imported symbol. This means esbuild will now tree-shake unused code in cases like this. 93 94 * Warn about calling an import namespace object 95 96 The following code is an invalid use of an import statement: 97 98 ```js 99 import * as express from "express" 100 express() 101 ``` 102 103 The `express` symbol here is an import namespace object, not a function, so calling it will fail at run-time. This code should have been written like this instead: 104 105 ```js 106 import express from "express" 107 express() 108 ``` 109 110 This comes up because for legacy reasons, the TypeScript compiler defaults to a compilation mode where the `import * as` statement is converted to `const express = require("express")` which means you can actually call `express()` successfully. Doing this is incompatible with standard ECMAScript module environments such as the browser, node, and esbuild because an import namespace object is never a function. The TypeScript compiler has a setting to disable this behavior called `esModuleInterop` and they highly recommend applying it both to new and existing projects to avoid these compatibility problems. See [the TypeScript documentation](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#support-for-import-d-from-cjs-from-commonjs-modules-with---esmoduleinterop) for more information. 111 112 With this release, esbuild will now issue a warning when you do this. The warning indicates that your code will crash when run and that your code should be fixed. 113 114 ## 0.8.25 115 116 * Fix a performance regression from version 0.8.4 specific to Yarn 2 117 118 Code using esbuild's `transformSync` function via Yarn 2 experienced a dramatic slowdown in esbuild version 0.8.4 and above. This version added a wrapper script to fix Yarn 2's incompatibility with binary packages. Some code that tries to avoid unnecessarily calling into the wrapper script contained a bug that caused it to fail, which meant that using `transformSync` with Yarn 2 called into the wrapper script unnecessarily. This launched an extra node process every time the esbuild executable was invoked which can be over 6x slower than just invoking the esbuild executable directly. This release should now invoke the esbuild executable directly without going through the wrapper script, which fixes the performance regression. 119 120 * Fix a size regression from version 0.7.9 with certain source maps ([#611](https://github.com/evanw/esbuild/issues/611)) 121 122 Version 0.7.9 added a new behavior to esbuild where in certain cases a JavaScript file may be split into multiple pieces during bundling. Pieces of the same input file may potentially end up in multiple discontiguous regions in the output file. This was necessary to fix an import ordering bug with CommonJS modules. However, it had the side effect of duplicating that file's information in the resulting source map. This didn't affect source map correctness but it made source maps unnecessarily large. This release corrects the problem by ensuring that a given file's information is only ever represented once in the corresponding source map. 123 124 ## 0.8.24 125 126 * Share reference-counted service instances internally ([#600](https://github.com/evanw/esbuild/issues/600)) 127 128 Now calling `startService()` multiple times will share the underlying esbuild child process as long as the lifetimes of the service objects overlap (i.e. the time from `startService()` to `service.stop()`). This is just an internal change; there is no change to the public API. It should result in a faster implementation that uses less memory if your code calls `startService()` multiple times. Previously each call to `startService()` generated a separate esbuild child process. 129 130 * Fix re-exports of a side-effect free CommonJS module ([#605](https://github.com/evanw/esbuild/issues/605)) 131 132 This release fixes a regression introduced in version 0.8.19 in which an `import` of an `export {...} from` re-export of a CommonJS module does not include the CommonJS module if it has been marked as `"sideEffects": false` in its `package.json` file. This was the case with the [Ramda](https://ramdajs.com/) library, and was due to an unhandled case in the linker. 133 134 * Optionally take binary executable path from environment variable ([#592](https://github.com/evanw/esbuild/issues/592)) 135 136 You can now set the `ESBUILD_BINARY_PATH` environment variable to cause the JavaScript API to use a different binary executable path. This is useful if you want to substitute a modified version of the `esbuild` binary that contains some extra debugging information. This feature was contributed by [@remorses](https://github.com/remorses). 137 138 ## 0.8.23 139 140 * Fix non-string objects being passed to `transformSync` ([#596](https://github.com/evanw/esbuild/issues/596)) 141 142 The transform function is only supposed to take a string. The type definitions also specify that the input must be a string. However, it happened to convert non-string inputs to a string and some code relied on that behavior. A change in 0.8.22 broke that behavior for `transformSync` specifically for `Uint8Array` objects, which became an array of numbers instead of a string. This release ensures that the conversion to a string is done up front to avoid something unexpected happening in the implementation. Future releases will likely enforce that the input is a string and throw an error otherwise. 143 144 * Revert the speedup to `transformSync` and `buildSync` ([#595](https://github.com/evanw/esbuild/issues/595)) 145 146 This speedup relies on the `worker_threads` module in node. However, when esbuild is used via `node -r` as in `node -r esbuild-register file.ts`, the worker thread created by esbuild somehow ends up being completely detached from the main thread. This may be a bug in node itself. Regardless, the approach esbuild was using to improve speed doesn't work in all cases so it has been reverted. It's unclear if it's possible to work around this issue. This approach for improving the speed of synchronous APIs may be a dead end. 147 148 ## 0.8.22 149 150 * Escape fewer characters in virtual module paths ([#588](https://github.com/evanw/esbuild/issues/588)) 151 152 If a module's path is not in the `file` namespace (i.e. it was created by a plugin), esbuild doesn't assume it's a file system path. The meaning of these paths is entirely up to the plugin. It could be anything including a HTTP URL, a string of code, or randomly-generated characters. 153 154 Currently esbuild generates a file name for these virtual modules using an internal "human-friendly identifier" that can also be used as a valid JavaScript identifier, which is sometimes used to for example derive the name of the default export of a bundled module. But that means virtual module paths which _do_ happen to represent file system paths could cause more characters to be escaped than necessary. For example, esbuild escapes `-` to `_` because `-` is not valid in a JavaScript identifier. 155 156 This release separates the file names derived from virtual module paths from the internal "human-friendly identifier" concept. Characters in the virtual module path that are valid in file paths are no longer escaped. 157 158 In the future the output file name of a virtual module will likely be completely customizable with a plugin, so it will be possible to have different behavior for this if desired. But that isn't possible quite yet. 159 160 * Speed up the JavaScript `buildSync` and `transformSync` APIs ([#590](https://github.com/evanw/esbuild/issues/590)) 161 162 Previously the `buildSync` and `transformSync` API calls created a new child esbuild process on every call because communicating with a long-lived child process is asynchronous in node. However, there's a trick that can work around this limitation: esbuild can communicate with the long-lived child process from a child thread using node's [`worker_threads`](https://nodejs.org/api/worker_threads.html) module and block the main thread using JavaScript's new [Atomics API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait). This was a tip from [@cspotcode](https://github.com/cspotcode). 163 164 This approach has now been implemented. A quick benchmark shows that `transformSync` is now **1.5x to 15x faster** than it used to be. The speedup depends on the size of the input (smaller inputs get a bigger speedup). The worker thread and child process should automatically be terminated when there are no more event handlers registered on the main thread, so there is no explicit `stop()` call like there is with a service object. 165 166 * Distribute a 32-bit Linux ARM binary executable via npm ([#528](https://github.com/evanw/esbuild/issues/528)) 167 168 You should now be able to use npm to install esbuild on a 32-bit Linux ARM device. This lets you run esbuild on a Raspberry Pi. Note that this target isn't officially supported because it's not covered by any automated tests. 169 170 ## 0.8.21 171 172 * On-resolve plugins now apply to entry points ([#546](https://github.com/evanw/esbuild/issues/546)) 173 174 Previously entry points were required to already be resolved to valid file system paths. This meant that on-resolve plugins didn't run, which breaks certain workflows. Now entry point paths are resolved using normal import resolution rules. 175 176 To avoid making this a breaking change, there is now special behavior for entry point path resolution. If the entry point path exists relative to the current working directory and the path does not start with `./` or `../`, esbuild will now automatically insert a leading `./` at the start of the path to prevent the path from being interpreted as a `node_modules` package path. This is only done if the file actually exists to avoid introducing `./` for paths with special plugin-specific syntax. 177 178 * Enable the build API in the browser ([#527](https://github.com/evanw/esbuild/issues/527)) 179 180 Previously you could only use the transform API in the browser, not the build API. You can now use the build API in the browser too. There is currently no in-browser file system so the build API will not do anything by default. Using this API requires you to use plugins to provide your own file system. Instructions for running esbuild in the browser can be found here: https://esbuild.github.io/api/#running-in-the-browser. 181 182 * Set the importer to `sourcefile` in on-resolve plugins for stdin 183 184 When the stdin feature is used with on-resolve plugins, the importer for any import paths in stdin is currently always set to `<stdin>`. The `sourcefile` option provides a way to set the file name of stdin but it wasn't carried through to on-resolve plugins due to an oversight. This release changes this behavior so now `sourcefile` is used instead of `<stdin>` if present. In addition, if the stdin resolve directory is also specified the importer will be placed in the `file` namespace similar to a normal file. 185 186 ## 0.8.20 187 188 * Fix an edge case with class body initialization 189 190 When bundling, top-level class statements are rewritten to variable declarations initialized to a class expression. This avoids a severe performance pitfall in Safari when there are a large number of class statements. However, this transformation was done incorrectly if a class contained a static field that references the class name in its own initializer: 191 192 ```js 193 class Foo { 194 static foo = new Foo 195 } 196 ``` 197 198 In that specific case, the transformed code could crash when run because the class name is not yet initialized when the static field initializer is run. Only JavaScript code was affected. TypeScript code was not affected. This release fixes this bug. 199 200 * Remove more types of statements as dead code ([#580](https://github.com/evanw/esbuild/issues/580)) 201 202 This change improves dead-code elimination in the case where unused statements follow an unconditional jump, such as a `return`: 203 204 ```js 205 if (true) return 206 if (something) thisIsDeadCode() 207 ``` 208 209 These unused statements are removed in more cases than in the previous release. Some statements may still be kept that contain hoisted symbols (`var` and `function` statements) because they could potentially impact the code before the conditional jump. 210 211 ## 0.8.19 212 213 * Handle non-ambiguous multi-path re-exports ([#568](https://github.com/evanw/esbuild/pull/568)) 214 215 Wildcard re-exports using the `export * from 'path'` syntax can potentially result in name collisions that cause an export name to be ambiguous. For example, the following code would result in an ambiguous export if both `a.js` and `b.js` export a symbol with the same name: 216 217 ```js 218 export * from './a.js' 219 export * from './b.js' 220 ``` 221 222 Ambiguous exports have two consequences. First, any ambiguous names are silently excluded from the set of exported names. If you use an `import * as` wildcard import, the excluded names will not be present. Second, attempting to explicitly import an ambiguous name using an `import {} from` import clause will result in a module instantiation error. 223 224 This release fixes a bug where esbuild could in certain cases consider a name ambiguous when it actually isn't. Specifically this happens with longer chains of mixed wildcard and named re-exports. Here is one such case: 225 226 ```js 227 // entry.js 228 import {x, y} from './not-ambiguous.js' 229 console.log(x, y) 230 ``` 231 232 ```js 233 // /not-ambiguous.js 234 export * from './a.js' 235 export * from './b.js' 236 ``` 237 238 ```js 239 // /a.js 240 export * from './c.js' 241 ``` 242 243 ```js 244 // /b.js 245 export {x} from './c.js' 246 ``` 247 248 ```js 249 // /c.js 250 export let x = 1, y = 2 251 ``` 252 253 Previously bundling `entry.js` with esbuild would incorrectly generate an error about an ambiguous `x` export. Now this case builds successfully without an error. 254 255 * Omit warnings about non-string paths in `await import()` inside a `try` block ([#574](https://github.com/evanw/esbuild/issues/574)) 256 257 Bundling code that uses `require()` or `import()` with a non-string path currently generates a warning, because the target of that import will not be included in the bundle. This is helpful to warn about because other bundlers handle this case differently (e.g. Webpack bundles the entire directory tree and emulates a file system lookup) so existing code may expect the target of the import to be bundled. 258 259 You can avoid the warning with esbuild by surrounding the call to `require()` with a `try` block. The thinking is that if there is a surrounding `try` block, presumably the code is expecting the `require()` call to possibly fail and is prepared to handle the error. However, there is currently no way to avoid the warning for `import()` expressions. This release introduces an analogous behavior for `import()` expressions. You can now avoid the warning with esbuild if you use `await import()` and surround it with a `try` block. 260 261 ## 0.8.18 262 263 * Fix a bug with certain complex optional chains ([#573](https://github.com/evanw/esbuild/issues/573)) 264 265 The `?.` optional chaining operator only runs the right side of the operator if the left side is undefined, otherwise it returns undefined. This operator can be applied to both property accesses and function calls, and these can be combined into long chains of operators. These expressions must be transformed to a chain of `?:` operators if the `?.` operator isn't supported in the configured target environment. However, esbuild had a bug where an optional call of an optional property with a further property access afterward didn't preserve the value of `this` for the call. This bug has been fixed. 266 267 * Fix a renaming bug with external imports 268 269 There was a possibility of a cross-module name collision while bundling in a certain edge case. Specifically, when multiple files both contained an `import` statement to an external module and then both of those files were imported using `require`. For example: 270 271 ```js 272 // index.js 273 console.log(require('./a.js'), require('./b.js')) 274 ``` 275 276 ```js 277 // a.js 278 export {exists} from 'fs' 279 ``` 280 281 ```js 282 // b.js 283 export {exists} from 'fs' 284 ``` 285 286 In this case the files `a.js` and `b.js` are converted to CommonJS format so they can be imported using `require`: 287 288 ```js 289 // a.js 290 import {exists} from "fs"; 291 var require_a = __commonJS((exports) => { 292 __export(exports, { 293 exists: () => exists 294 }); 295 }); 296 297 // b.js 298 import {exists} from "fs"; 299 var require_b = __commonJS((exports) => { 300 __export(exports, { 301 exists: () => exists 302 }); 303 }); 304 305 // index.js 306 console.log(require_a(), require_b()); 307 ``` 308 309 However, the `exists` symbol has been duplicated without being renamed. This is will result in a syntax error at run-time. The reason this happens is that the statements in the files `a.js` and `b.js` are placed in a nested scope because they are inside the CommonJS closure. The `import` statements were extracted outside the closure but the symbols they declared were incorrectly not added to the outer scope. This problem has been fixed, and this edge case should no longer result in name collisions. 310 311 ## 0.8.17 312 313 * Get esbuild working on the Apple M1 chip via Rosetta 2 ([#564](https://github.com/evanw/esbuild/pull/564)) 314 315 The Go compiler toolchain does not yet support the new Apple M1 chip. Go version 1.15 is currently in a feature freeze period so support will be added in the next version, Go 1.16, which will be [released in February](https://blog.golang.org/11years#TOC_3.). 316 317 This release changes the install script to install the executable for macOS `x64` on macOS `arm64` too. Doing this should still work because of the executable translation layer built into macOS. This change was contributed by [@sod](https://github.com/sod). 318 319 ## 0.8.16 320 321 * Improve TypeScript type definitions ([#559](https://github.com/evanw/esbuild/issues/559)) 322 323 The return value of the `build` API has some optional fields that are undefined unless certain arguments are present. That meant you had to use the `!` null assertion operator to avoid a type error if you have the TypeScript `strictNullChecks` setting enabled in your project. This release adds additional type information so that if the relevant arguments are present, the TypeScript compiler can tell that these optional fields on the return value will never be undefined. This change was contributed by [@lukeed](https://github.com/lukeed). 324 325 * Omit a warning about `require.main` when targeting CommonJS ([#560](https://github.com/evanw/esbuild/issues/560)) 326 327 A common pattern in code that's intended to be run in node is to check if `require.main === module`. That will be true if the current file is being run from the command line but false if the current file is being run because some other code called `require()` on it. Previously esbuild generated a warning about an unexpected use of `require`. Now this warning is no longer generated for `require.main` when the output format is `cjs`. 328 329 * Warn about defining `process.env.NODE_ENV` as an identifier ([#466](https://github.com/evanw/esbuild/issues/466)) 330 331 The define feature can be used to replace an expression with either a JSON literal or an identifier. Forgetting to put quotes around a string turns it into an identifier, which is a common mistake. This release introduces a warning when you define `process.env.NODE_ENV` as an identifier instead of a string. It's very common to use define to replace `process.env.NODE_ENV` with either `"production"` or `"development"` and sometimes people accidentally replace it with `production` or `development` instead. This is worth warning about because otherwise there would be no indication that something is wrong until the code crashes when run. 332 333 * Allow starting a local server at a specific host address ([#563](https://github.com/evanw/esbuild/pull/563)) 334 335 By default, esbuild's local HTTP server is only available on the internal loopback address. This is deliberate behavior for security reasons, since the local network environment may not be trusted. However, it can be useful to run the server on a different address when developing with esbuild inside of a virtual machine/docker container or to request development assets from a remote testing device on the same network at a different IP address. With this release, you can now optionally specify the host in addition to the port: 336 337 ``` 338 esbuild --serve=192.168.0.1:8000 339 ``` 340 341 ```js 342 esbuild.serve({ 343 host: '192.168.0.1', 344 port: 8000, 345 }, { 346 ... 347 }) 348 ``` 349 350 ```go 351 server, err := api.Serve(api.ServeOptions{ 352 Host: "192.168.0.1", 353 Port: 8000, 354 }, api.BuildOptions{ 355 ... 356 }) 357 ``` 358 359 This change was contributed by [@jamalc](https://github.com/jamalc). 360 361 ## 0.8.15 362 363 * Allow `paths` without `baseUrl` in `tsconfig.json` 364 365 This feature was [recently released in TypeScript 4.1](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#paths-without-baseurl). The `paths` feature in `tsconfig.json` allows you to do custom import path rewriting. For example, you can map paths matching `@namespace/*` to the path `./namespace/src/*` relative to the `tsconfig.json` file. Previously using the `paths` feature required you to additionally specify `baseUrl` so that the compiler could know which directory the path aliases were supposed to be relative to. 366 367 However, specifying `baseUrl` has the potentially-problematic side effect of causing all import paths to be looked up relative to the `baseUrl` directory, which could potentially cause package paths to accidentally be redirected to non-package files. Specifying `baseUrl` also causes Visual Studio Code's auto-import feature to generate paths relative to the `baseUrl` directory instead of relative to the directory containing the current file. There is more information about the problems this causes here: https://github.com/microsoft/TypeScript/issues/31869. 368 369 With TypeScript 4.1, you can now omit `baseUrl` when using `paths`. When you do this, it as if you had written `"baseUrl": "."` instead for the purpose of the `paths` feature, but the `baseUrl` value is not actually set and does not affect path resolution. These `tsconfig.json` files are now supported by esbuild. 370 371 * Fix evaluation order issue with import cycles and CommonJS-style output formats ([#542](https://github.com/evanw/esbuild/issues/542)) 372 373 Previously entry points involved in an import cycle could cause evaluation order issues if the output format was `iife` or `cjs` instead of `esm`. This happened because this edge case was handled by treating the entry point file as a CommonJS file, which extracted the code into a CommonJS wrapper. Here's an example: 374 375 Input files: 376 377 ```js 378 // index.js 379 import { test } from './lib' 380 export function fn() { return 42 } 381 if (test() !== 42) throw 'failure' 382 ``` 383 384 ```js 385 // lib.js 386 import { fn } from './index' 387 export let test = fn 388 ``` 389 390 Previous output (problematic): 391 392 ```js 393 // index.js 394 var require_esbuild = __commonJS((exports) => { 395 __export(exports, { 396 fn: () => fn2 397 }); 398 function fn2() { 399 return 42; 400 } 401 if (test() !== 42) 402 throw "failure"; 403 }); 404 405 // lib.js 406 var index = __toModule(require_esbuild()); 407 var test = index.fn; 408 module.exports = require_esbuild(); 409 ``` 410 411 This approach changed the evaluation order because the CommonJS wrapper conflates both binding and evaluation. Binding and evaluation need to be separated to correctly handle this edge case. This edge case is now handled by inlining what would have been the contents of the CommonJS wrapper into the entry point location itself. 412 413 Current output (fixed): 414 415 ```js 416 // index.js 417 __export(exports, { 418 fn: () => fn 419 }); 420 421 // lib.js 422 var test = fn; 423 424 // index.js 425 function fn() { 426 return 42; 427 } 428 if (test() !== 42) 429 throw "failure"; 430 ``` 431 432 ## 0.8.14 433 434 * Fix a concurrency bug caused by an error message change ([#556](https://github.com/evanw/esbuild/issues/556)) 435 436 An improvement to the error message for path resolution was introduced in version 0.8.12. It detects when a relative path is being interpreted as a package path because you forgot to start the path with `./`: 437 438 ``` 439 > src/posts/index.js: error: Could not resolve "PostCreate" (use "./PostCreate" to import "src/posts/PostCreate.js") 440 2 │ import PostCreate from 'PostCreate'; 441 ╵ ~~~~~~~~~~~~ 442 ``` 443 444 This is implemented by re-running path resolution for package path resolution failures as a relative path instead. Unfortunately, this second path resolution operation wasn't guarded by a mutex and could result in concurrency bugs. This issue only occurs when path resolution fails. It is fixed in this release. 445 446 ## 0.8.13 447 448 * Assigning to a `const` symbol is now an error when bundling 449 450 This change was made because esbuild may need to change a `const` symbol into a non-constant symbol in certain situations. One situation is when the "avoid TDZ" option is enabled. Another situation is some potential upcoming changes to lazily-evaluate certain modules for code splitting purposes. Making this an error gives esbuild the freedom to do these code transformations without potentially causing problems where constants are mutated. This has already been a warning for a while so code that does this should already have been obvious. This warning was made an error in a patch release because the expectation is that no real code relies on this behavior outside of conformance tests. 451 452 * Fix for the `--keep-names` option and anonymous lowered classes 453 454 This release fixes an issue where names were not preserved for anonymous classes that contained newer JavaScript syntax when targeting an older version of JavaScript. This was because that causes the class expression to be transformed into a sequence expression, which was then not recognized as a class expression. For example, the class did not have the name `foo` in the code below when the target was set to `es6`: 455 456 ```js 457 let foo = class { 458 #privateMethod() {} 459 } 460 ``` 461 462 The `name` property of this class object is now `foo`. 463 464 * Fix captured class names when class name is re-assigned 465 466 This fixes a corner case with class lowering to better match the JavaScript specification. In JavaScript, the body of a class statement contains an implicit constant symbol with the same name as the symbol of the class statement itself. Lowering certain class features such as private methods means moving them outside the class body, in which case the contents of the private method are no longer within the scope of the constant symbol. This can lead to a behavior change if the class is later re-assigned: 467 468 ```js 469 class Foo { 470 static test() { return this.#method() } 471 static #method() { return Foo } 472 } 473 let old = Foo 474 Foo = class Bar {} 475 console.log(old.test() === old) // This should be true 476 ``` 477 478 Previously this would print `false` when transformed to ES6 by esbuild. This now prints `true`. The current transformed output looks like this: 479 480 ```js 481 var _method, method_fn; 482 const Foo2 = class { 483 static test() { 484 return __privateMethod(this, _method, method_fn).call(this); 485 } 486 }; 487 let Foo = Foo2; 488 _method = new WeakSet(); 489 method_fn = function() { 490 return Foo2; 491 }; 492 _method.add(Foo); 493 let old = Foo; 494 Foo = class Bar { 495 }; 496 console.log(old.test() === old); 497 ``` 498 499 * The `--allow-tdz` option is now always applied during bundling 500 501 This option turns top-level `let`, `const`, and `class` statements into `var` statements to work around some severe performance issues in the JavaScript run-time environment in Safari. Previously you had to explicitly enable this option. Now this behavior will always happen, and there is no way to turn it off. This means the `--allow-tdz` option is now meaningless and no longer does anything. It will be removed in a future release. 502 503 * When bundling and minifying, `const` is now converted into `let` 504 505 This was done because it's semantically equivalent but shorter. It's a valid transformation because assignment to a `const` symbol is now a compile-time error when bundling, so changing `const` to `let` should now not affect run-time behavior. 506 507 ## 0.8.12 508 509 * Added an API for incremental builds ([#21](https://github.com/evanw/esbuild/issues/21)) 510 511 There is now an API for incremental builds. This is what using the API looks like from JavaScript: 512 513 ```js 514 require('esbuild').build({ 515 entryPoints: ['app.js'], 516 bundle: true, 517 outfile: 'out.js', 518 incremental: true, 519 }).then(result => { 520 // The "rebuild" method is present if "incremental" is true. It returns a 521 // promise that resolves to the same kind of object that "build" returns. 522 // You can call "rebuild" as many times as you like. 523 result.rebuild().then(result2 => { 524 // Call "dispose" when you're done to free up resources. 525 result.rebuild.dispose() 526 }) 527 }) 528 ``` 529 530 Using the API from Go is similar, except there is no need to manually dispose of the rebuild callback: 531 532 ```go 533 result := api.Build(api.BuildOptions{ 534 EntryPoints: []string{"app.js"}, 535 Bundle: true, 536 Outfile: "out.js", 537 Incremental: true, 538 }) 539 result2 := result.Rebuild() 540 ``` 541 542 Incremental builds are more efficient than regular builds because some data is cached and can be reused if the original files haven't changed since the last build. There are currently two forms of caching used by the incremental build API: 543 544 * Files are stored in memory and are not re-read from the file system if the file metadata hasn't changed since the last build. This optimization only applies to file system paths. It does not apply to virtual modules created by plugins. 545 546 * Parsed ASTs are stored in memory and re-parsing the AST is avoided if the file contents haven't changed since the last build. This optimization applies to virtual modules created by plugins in addition to file system modules, as long as the virtual module path remains the same. 547 548 This is just the initial release of the incremental build API. Incremental build times still have room for improvement. Right now esbuild still re-resolves, re-loads, and re-links everything even if none of the input files have changed. Improvements to the incremental build mechanism will be coming in later releases. 549 550 * Support for a local file server ([#537](https://github.com/evanw/esbuild/issues/537)) 551 552 You can now run esbuild with the `--serve` flag to start a local server that serves the output files over HTTP. This is intended to be used during development. You can point your `<script>` tag to a local server URL and your JavaScript and CSS files will be automatically built by esbuild whenever that URL is accessed. The server defaults to port 8000 but you can customize the port with `--serve=...`. 553 554 There is also an equivalent API for JavaScript: 555 556 ```js 557 require('esbuild').serve({ 558 port: 8000, 559 },{ 560 entryPoints: ['app.js'], 561 bundle: true, 562 outfile: 'out.js', 563 }).then(server => { 564 // Call "stop" on the server when you're done 565 server.stop() 566 }) 567 ``` 568 569 and for Go: 570 571 ```go 572 server, err := api.Serve(api.ServeOptions{ 573 Port: 8000, 574 }, api.BuildOptions{ 575 EntryPoints: []string{"app.js"}, 576 Bundle: true, 577 Outfile: "out.js", 578 }) 579 580 // Call "stop" on the server when you're done 581 server.Stop() 582 ``` 583 584 This is a similar use case to "watch mode" in other tools where something automatically rebuilds your code when a file has changed on disk. The difference is that you don't encounter the problem where you make an edit, switch to your browser, and reload only to load the old files because the rebuild hasn't finished yet. Using a HTTP request instead of a file system access gives the rebuild tool the ability to delay the load until the rebuild operation has finished so your build is always up to date. 585 586 * Install to a temporary directory for Windows ([#547](https://github.com/evanw/esbuild/issues/547)) 587 588 The install script runs `npm` in a temporary directory to download the correct binary executable for the current architecture. It then removes the temporary directory after the installation. However, removing a directory is sometimes impossible on Windows. To work around this problem, the install script now installs to the system's temporary directory instead of a directory inside the project itself. That way it's not problematic if a directory is left behind by the install script. This change was contributed by [@Djaler](https://github.com/Djaler). 589 590 * Fix the public path ending up in the metafile ([#549](https://github.com/evanw/esbuild/issues/549)) 591 592 The change in version 0.8.7 to include the public path in import paths of code splitting chunks caused a regression where the public path was also included in the list of chunk imports in the metafile. This was unintentional. Now the public path setting should not affect the metafile contents. 593 594 ## 0.8.11 595 596 * Fix parsing of casts in TypeScript followed by certain tokens 597 598 This aligns esbuild's TypeScript parser with the official TypeScript parser as far as parsing of `as` casts. It's not valid to form an expression after an `as` cast if the next token is a `(`, `[`, `++`, `--`, `?.`, assignment operator, or template literal. Previously esbuild wouldn't generate an error for these expressions. This is normally not a problem because the TypeScript compiler itself would reject the code as invalid. However, if the next token starts on a new line, that new token may be the start of another statement. In that case the code generated by esbuild was different than the code generated by the TypeScript compiler. This difference has been fixed. 599 600 * Implement wildcards for external paths ([#406](https://github.com/evanw/esbuild/issues/406)) 601 602 You can now use a `*` wildcard character with the `--external` option to mark all files matching a certain pattern as external, which will remove them from the bundle. For example, you can now do `--external:*.png` to remove all `.png` files. When a `*` wildcard character is present in an external path, that pattern will be applied to the original path in the source code instead of to the path after it has been resolved to a real file system path. This lets you match on paths that aren't real file system paths. 603 604 * Add a warning about self-assignment 605 606 This release adds a warning for code that assigns an identifier to itself (e.g. `x = x`). This code is likely a mistake since doing this has no effect. This warning is not generated for assignments to global variables, since that can have side effects, and self-assignments with TypeScript casts, since those can be useful for changing the type of a variable in TypeScript. The warning is also not generated for code inside a `node_modules` folder. 607 608 ## 0.8.10 609 610 * Fix parsing of conditional types in TypeScript ([#541](https://github.com/evanw/esbuild/issues/541)) 611 612 Conditional types in TypeScript take the form `A extends B ? C : D`. Parsing of conditional types in esbuild was incorrect. The `?` can only follow an `extends` clause but esbuild didn't require the `extends` clause, which potentially led to build failures or miscompilation. The parsing for this syntax has been fixed and should now match the behavior of the TypeScript compiler. This fix was contributed by [@rtsao](https://github.com/rtsao). 613 614 * Ignore comments for character frequency analysis ([#543](https://github.com/evanw/esbuild/issues/543)) 615 616 Character frequency analysis is used to derive the order of minified names for better gzip compression. The idea is to prefer using the most-used characters in the non-symbol parts of the document (keywords, strings, etc.) over characters that are less-used or absent. This is a very slight win, and is only approximate based on the input text instead of the output text because otherwise it would require minifying twice. 617 618 Right now comments are included in this character frequency histogram. This is not a correctness issue but it does mean that documents with the same code but different comments may be minified to different output files. This release fixes this difference by removing comments from the character frequency histogram. 619 620 * Add an option to ignore tree-shaking annotations ([#458](https://github.com/evanw/esbuild/issues/458)) 621 622 Tree shaking is the term the JavaScript community uses for dead code elimination, a common compiler optimization that automatically removes unreachable code. Since JavaScript is a dynamic language, identifying unused code is sometimes very difficult for a compiler, so the community has developed certain annotations to help tell compilers what code should be considered unused. Currently there two forms of tree-shaking annotations that esbuild supports: inline `/* @__PURE__ */` comments before function calls and the `sideEffects` field in `package.json`. 623 624 These annotations can be problematic because the compiler depends completely on developers for accuracy and the annotations are occasionally incorrect. The `sideEffects` field is particularly error-prone because by default it causes all files in your package to be considered dead code if no imports are used. If you add a new file containing side effects and forget to update that field, your package will break when people try to bundle it. 625 626 This release adds a new flag `--tree-shaking=ignore-annotations` to allow you to bundle code that contains incorrect tree-shaking annotations with esbuild. An example of such code is [@tensorflow/tfjs](https://github.com/tensorflow/tfjs). Ideally the `--tree-shaking=ignore-annotations` flag is only a temporary workaround. You should report these issues to the maintainer of the package to get them fixed since they will trip up other people too. 627 628 * Add support for absolute `baseUrl` paths in `tsconfig.json` files 629 630 Previously esbuild always joined the `baseUrl` path to the end of the current directory path. However, if the `baseUrl` was an absolute path, that would end up including the current directory path twice. This situation could arise internally in certain cases involving multiple `tsconfig.json` files and `extends` fields even if the `tsconfig.json` files themselves didn't have absolute paths. Absolute paths are now not modified and should work correctly. 631 632 * Fix crash for modules that do `module.exports = null` ([#532](https://github.com/evanw/esbuild/issues/532)) 633 634 The code generated by esbuild would crash at run-time if a module overwrote `module.exports` with null or undefined. This has been fixed and no longer crashes. 635 636 ## 0.8.9 637 638 * Add support for the `mips64le` architecture ([#523](https://github.com/evanw/esbuild/issues/523)) 639 640 You should now be able to install esbuild on the `mips64le` architecture. This build target is second-tier as it's not covered by CI, but I tested it in an emulator and it appears to work at the moment. 641 642 * Fix for packages with inconsistent side effect markings 643 644 Packages can have multiple entry points in their `package.json` file. Two commonly-used ones are specified using the fields `main` and `module`. Packages can also mark files in the package as not having side effects using the `sideEffects` field. Some packages have one entry point marked as having side effects and the other entry point as not having side effects. This is arguably a problem with the package itself. However, this caused an issue with esbuild's automatic entry point field selection method where it would incorrectly consider both `main` and `module` to not have side effects if one of them was marked as not having side effects. Now `main` and `module` will only be considered to not have side effects if the individual file was marked as not having side effects. 645 646 * Warn about `import './file'` when `./file` was marked as having no side effects 647 648 Files in packages containing `"sideEffects": false` in the enclosing `package.json` file are intended to be automatically removed from the bundle if they aren't used. However, code containing `import './file'` is likely trying to import that file for a side effect. This is a conflict of intentions so it seems like a good idea to warn about this. It's likely a configuration error by the author of the package. The warning points to the location in `package.json` that caused this situation. 649 650 * Add support for glob-style tests in `sideEffects` arrays 651 652 The `sideEffects` field in `package.json` can optionally contain an array of files that are considered to have side effects. Any file not in that list will be removed if the import isn't used. Webpack supports the `*` and `?` wildcard characters in these file strings. With this release, esbuild supports these wildcard characters too. 653 654 ## 0.8.8 655 656 * Add the `--banner` and `--footer` options ([#482](https://github.com/evanw/esbuild/issues/482)) 657 658 You can now use the `--banner` and `--footer` options to insert code before and/or after the code that esbuild generates. This is usually used to insert a banner comment at the top of your bundle. However, you can also use this for other purposes such as wrapping your whole bundle in `--banner='try {'` and `--footer='} catch (e) { reportError(e) }'`. Note that since these strings can contain partial JavaScript syntax, esbuild will not do anything to ensure the result is valid JavaScript syntax. This feature was contributed by [@Gelio](https://github.com/Gelio). 659 660 * Be more permissive inside TypeScript `declare` contexts 661 662 These cases are now allowed by esbuild: 663 664 * TypeScript supports a special `global { ... }` block inside `declare module` 665 * TypeScript allows arbitrary import and export statements inside `declare module` 666 * The TypeScript-specific `export as namespace name;` syntax is now ignored inside `declare module`. 667 * A trailing comma after a rest argument is disallowed in JavaScript but is allowed in TypeScript if you use `declare function` 668 669 * Log output to stderr has been overhauled 670 671 The formatting is now slightly different. Line numbers are now displayed to the left of the source text and source text is now dimmed to make the log messages themselves stand out more. And log messages now support "notes" which are additional messages with different attached locations. 672 673 Before: 674 675 ``` 676 example.ts:13:6: error: "test" has already been declared 677 class test extends BaseTest { 678 ~~~~ 679 ``` 680 681 After: 682 683 ``` 684 > example.ts: error: "test" has already been declared 685 13 │ class test extends BaseTest { 686 ╵ ~~~~ 687 example.ts: note: "test" was originally declared here 688 4 │ function test(name: string, callback: () => void) { 689 ╵ ~~~~ 690 ``` 691 692 ## 0.8.7 693 694 * `--public-path` now affects code splitting chunk imports ([#524](https://github.com/evanw/esbuild/issues/524)) 695 696 The public path setting is a path prefix that bakes in the path where your code is hosted. It can currently be used with the `file` loader to turn the exported URLs into absolute URLs. Previously this path prefix didn't apply to the cross-chunk imports generated by code splitting. This was an oversight. The public path setting now also works for cross-chunk imports in this release. 697 698 * Add `exports` for output files in metafile ([#487](https://github.com/evanw/esbuild/issues/487)) 699 700 The metafile JSON data now contains a list of export names for all generated output files. This only affects builds that use the `esm` output format. It includes the names of all exports declared using the `export` keyword, including transitive exports that use the `export * from` syntax. If the entry point is in CommonJS format, there will be a single export called `default`. 701 702 * Fix values in metafile `inputs` object 703 704 This fixes a regression in the `inputs` object in generated metafile JSON data. Version 0.7.9 introduced the ability for a module to be split into multiple parts to correctly emulate ECMAScript module instantiation order. However, that caused split files to be present in the `inputs` object multiple times, once for each split part. That looked something like this: 705 706 ```json 707 "outputs": { 708 "out/a.js": { 709 "imports": [ 710 { 711 "path": "out/chunk.QXHH4FDI.js" 712 } 713 ], 714 "inputs": { 715 "a.js": { 716 "bytesInOutput": 21 717 }, 718 "a.js": { 719 "bytesInOutput": 0 720 } 721 }, 722 "bytes": 120 723 } 724 } 725 ``` 726 727 This is problematic because duplicate keys are allowed in JSON and overwrite the previous key. The fix in this release is to accumulate the `bytesInOutput` values for all parts of a file and then only write out the accumulated values at the end. 728 729 * Avoid arrow functions when `import()` is converted to `require()` for `es5` 730 731 Setting the target to `es5` is supposed to remove arrow functions, since they are only supported in `es6` and above. However, arrow functions would still be generated if an `import()` expression pointed to an external module and the output format was `iife` or `cjs`. Now these arrow functions are replaced by function expressions instead. 732 733 * Convert `import()` to `require()` even if the argument isn't a string literal 734 735 The `import()` syntax is supposed to be converted to `require()` if the target is `cjs` instead of `esm`. However, this was previously only done if the argument was a string literal. This is now done for all `import()` expressions regardless of what the argument looks like. 736 737 * Transpose `require(a ? 'b' : 'c')` into `a ? require('b') : require('c')` 738 739 The reverse transformation is sometimes done by JavaScript minifiers such as [Terser](https://github.com/terser/terser) even if the original source code used the form `a ? require('b') : require('c')`. This messes up esbuild's import resolution which needs `require()` to take a single string as an argument. The transformation done here is a simple way to make sure esbuild still works on minified code. This transformation is also performed on `import()` and `require.resolve()`. 740 741 ## 0.8.6 742 743 * Changes to TypeScript's `import name =` syntax 744 745 The parsing of TypeScript's `import name =` syntax should now match the official TypeScript parser. Previously esbuild incorrectly allowed any kind of expression after the equals sign. Now you can only use either a sequence of identifiers separated by periods or a call to the `require` function with a string literal. 746 747 * Do not report warnings about `require()` inside `try` ([#512](https://github.com/evanw/esbuild/issues/512)) 748 749 This release no longer reports warnings about un-bundled calls to `require()` if they are within a `try` block statement. Presumably the try/catch statement is there to handle the potential run-time error from the unbundled `require()` call failing, so the potential failure is expected and not worth warning about. 750 751 * Add the `--keep-names` option ([#510](https://github.com/evanw/esbuild/issues/510)) 752 753 In JavaScript the `name` property on functions and classes defaults to a nearby identifier in the source code. These syntax forms all set the `name` property of the function to `'fn'`: 754 755 ```js 756 function fn() {} 757 let fn = function() {}; 758 obj.fn = function() {}; 759 fn = function() {}; 760 let [fn = function() {}] = []; 761 let {fn = function() {}} = {}; 762 [fn = function() {}] = []; 763 ({fn = function() {}} = {}); 764 ``` 765 766 However, minification renames symbols to reduce code size. That changes value of the `name` property for many of these cases. This is usually fine because the `name` property is normally only used for debugging. However, some frameworks rely on the `name` property for registration and binding purposes. If this is the case, you can now enable `--keep-names` to preserve the original `name` values even in minified code. 767 768 * Omit unused TypeScript import assignment aliases ([#474](https://github.com/evanw/esbuild/issues/474)) 769 770 In TypeScript, `import x = y` is an alias statement that works for both values and types and can reach across files. Because esbuild doesn't replicate TypeScript's type system and because esbuild converts each file from TypeScript to JavaScript independently, it's not clear to esbuild if the alias refers to a value and should be kept as JavaScript or if the alias refers to a type and should be removed. 771 772 Previously all import aliases were kept in the generated JavaScript. This could lead to problems if the alias actually referred to a type. Now import aliases are only kept if they are used as values. This way import aliases that are only used as types will be automatically removed. This doesn't exactly match what the TypeScript compiler does in complex scenarios but it should work for many real-world cases. 773 774 * Validate that on-resolve plugins return absolute paths in the `file` namespace 775 776 The default path namespace for on-resolve plugins is the `file` namespace. Paths in this namespace are expected to be absolute paths. This is now enforced. If the returned path is not supposed to be a file system path, you should set a namespace other than `file` so esbuild doesn't treat it as a file system path. 777 778 * External paths returned by a plugin do not default to the `file` namespace 779 780 The `file` namespace is normally implied if it's not specified. However, that probably does not match the intent of the plugin for paths that have been marked as external. Such paths will now have an empty namespace instead of the namespace `file`. You now have to explicitly specify the `file` namespace in your plugin if you want it for external paths. 781 782 ## 0.8.5 783 784 * Direct `eval()` now causes the module to be considered CommonJS ([#175](https://github.com/evanw/esbuild/pull/175)) 785 786 Code containing a direct call to `eval()` can potentially access any name in the current scope or in any parent scope. Therefore all symbols in all of these scopes must not be renamed or minified. This was already the case for all non-top-level symbols, but it accidentally wasn't the case for top-level symbols. 787 788 Preventing top-level symbols from being renamed is problematic because they may be merged in with symbols from other files due to the scope hoisting optimization that applies to files in the ECMAScript module format. That could potentially cause the names to collide and cause a syntax error if they aren't renamed. This problem is now avoided by treating files containing direct `eval()` as CommonJS modules instead, which causes these files to each be wrapped in their own closure with a separate scope. 789 790 Note that this change means that tree shaking is disabled for these files. There is rarely a reason to use direct `eval()` and it is almost always a mistake. You likely want to use a form of indirect eval such as `(0, eval)('code')` instead. That also has the benefit of not disabling symbol minification for that file. 791 792 * Add a `text` property to output files in build results ([#496](https://github.com/evanw/esbuild/issues/496)) 793 794 If you pass `write: false` to the JavaScript `build` API, the output files that would have been written to the file system are instead returned as an array of objects. Each object has a `Uint8Array` property called `contents` with the bytes of the file. It does not contain a string because the bytes of the file may not be valid UTF-8 (e.g. a PNG image) and it's not safe to decode output files as UTF-8 text in all cases. 795 796 This release adds a convenience property called `text` that lazily evaluates and returns `new TextDecoder().decode(contents)` the first time it's accessed. You should only use this in cases where you are sure the contents of the file are encoded using UTF-8 encoding. Invalid code point sequences will be replaced by the U+FFFD replacement character. 797 798 ## 0.8.4 799 800 * Using `delete` on an import namespace object is now an error 801 802 This release makes the following code forbidden when bundling is active: 803 804 ```js 805 import * as ns from './some-file'; 806 delete ns.prop; 807 ``` 808 809 Doing this does not delete the property because properties on ECMAScript module objects are not mutable. Assigning to a property of an import namespace object is already an error and not including the `delete` operator as an assignment was an oversight. This release just makes `delete` assignment consistent with other forms of assignment. 810 811 * Mark dead code inside branching expressions 812 813 Code inside branching expressions where the branch is statically determined to never be taken is now marked as dead code. Previously this was only the case for statements, not expressions. This change means `false && require('pkg')` will no longer generate an error about `pkg` being missing even if it is indeed missing. This change affects the `||`, `&&`, `??`, and `?:` operators. 814 815 * Fix metafile when importing CSS from JS ([#504](https://github.com/evanw/esbuild/pull/504)) 816 817 This release fixes a bug where importing a CSS file from JavaScript caused esbuild to generate invalid JSON in the resulting metafile. It was only a problem if you were importing CSS from JS and enabled metafile output. This fix was contributed by [@nitsky](https://github.com/nitsky). 818 819 * Fix downloads for Yarn 2 ([#505](https://github.com/evanw/esbuild/pull/505)) 820 821 The change related to Yarn 2 in the previous release had a bug that prevented downloads from succeeding when installing esbuild with Yarn 2. This fix was contributed by [@mathieudutour](https://github.com/mathieudutour). 822 823 ## 0.8.3 824 825 * Fix name collision with TypeScript namespaces containing their own name 826 827 This fixes a bug where TypeScript namespaces containing a declaration that re-uses the name of the enclosing namespace incorrectly failed the build with a duplicate declaration error. Here is an example: 828 829 ```ts 830 namespace foo { 831 export let foo 832 } 833 ``` 834 835 This happened because esbuild compiles that code into something like this: 836 837 ```ts 838 var foo; 839 (function (foo) { 840 foo.foo = 123; 841 console.log(foo.foo); 842 })(foo || (foo = {})); 843 ``` 844 845 The exported name `foo` was colliding with the automatically-declared function argument also named `foo`, which normally must be declared in that scope to shadow the outer namespace variable. This release fixes the problem by not declaring the function argument in the scope if there is already a declaration with that name in that scope. 846 847 * Prefer `.css` files for `@import` in CSS 848 849 People sometimes create a `.js`-related file and an adjacent `.css` file with the same name when creating a component (e.g. `button.tsx` and `button.css`). They also sometimes use `@import "./button"` in CSS and omit the file extension. Currently esbuild uses a single global order of extensions to try when an extension is omitted. This is configured with `--resolve-extensions` and defaults to `.tsx, .ts, .jsx, .mjs, .cjs, .js, .css, .json`. This means the `.tsx` file will be matched because `.tsx` comes before `.css` in the order. 850 851 This release changes the behavior to use a different order of extensions for `@import` statements in CSS files. The order is the list given by `--resolve-extensions` with all extensions removed that have `.js`-related loaders configured. In this case the filtered list would just be `.css` since all other default resolve extensions have JavaScript loaders, but if you also configure another resolve extension to use the `css` loader that will also qualify for implicit extension support with `@import` statements in CSS. 852 853 * Add support for `paths` in `tsconfig.json` for absolute paths 854 855 Previously it wasn't possible to use `paths` in `tsconfig.json` to remap paths starting with `/` on systems that considered that an absolute path (so not Windows). This is because absolute paths are handled before normal path resolution logic. Now this should work correctly. 856 857 * Hack around lack of support for binary packages in Yarn 2 ([#467](https://github.com/evanw/esbuild/issues/467)) 858 859 The Yarn 2 package manager is deliberately incompatible with binary modules because the Yarn 2 developers don't think they should be used. See [yarnpkg/berry#882](https://github.com/yarnpkg/berry/issues/882) for details. This means running esbuild with Yarn 2 currently doesn't work (Yarn 2 tries to load the esbuild binary as a JavaScript file). 860 861 The suggested workaround from the Yarn 2 team is to replace the binary with a JavaScript file wrapper that invokes the esbuild binary using node's `child_process` module. However, doing that would slow down esbuild for everyone. The `esbuild` command that is exported from the main package is intentionally a native executable instead of a JavaScript wrapper script because starting up a new node process just to invoke a native binary is unnecessary additional overhead. 862 863 The hack added in this release is to detect whether esbuild is being installed with Yarn 2 during the install script and only install a JavaScript file wrapper for Yarn 2 users. Doing this should make it possible to run the esbuild command from Yarn 2 without slowing down esbuild for everyone. This change was contributed by [@rtsao](https://github.com/rtsao). 864 865 ## 0.8.2 866 867 * Fix the omission of `outbase` in the JavaScript API ([#471](https://github.com/evanw/esbuild/pull/471)) 868 869 The original PR for the `outbase` setting added it to the CLI and Go APIs but not the JavaScript API. This release adds it to the JavaScript API too. 870 871 * Fix the TypeScript type definitions ([#499](https://github.com/evanw/esbuild/pull/499)) 872 873 The newly-released `plugins` option in the TypeScript type definitions was incorrectly marked as non-optional. It is now optional. This fix was contributed by [@remorses](https://github.com/remorses). 874 875 ## 0.8.1 876 877 * The initial version of the plugin API ([#111](https://github.com/evanw/esbuild/pull/111)) 878 879 The plugin API lets you inject custom code inside esbuild's build process. You can write plugins in either JavaScript or Go. Right now you can add an "on resolve" callback to determine where import paths go and an "on load" callback to determine what the imported file contains. These two primitives are very powerful, especially in combination with each other. 880 881 Here's a simple example plugin to show off the API in action. Let's say you wanted to enable a workflow where you can import environment variables like this: 882 883 ```js 884 // app.js 885 import { NODE_ENV } from 'env' 886 console.log(`NODE_ENV is ${NODE_ENV}`) 887 ``` 888 889 This is how you might do that from JavaScript: 890 891 ```js 892 let envPlugin = { 893 name: 'env-plugin', 894 setup(build) { 895 build.onResolve({ filter: /^env$/ }, args => ({ 896 path: args.path, 897 namespace: 'env', 898 })) 899 900 build.onLoad({ filter: /.*/, namespace: 'env' }, () => ({ 901 contents: JSON.stringify(process.env), 902 loader: 'json', 903 })) 904 }, 905 } 906 907 require('esbuild').build({ 908 entryPoints: ['app.js'], 909 bundle: true, 910 outfile: 'out.js', 911 plugins: [envPlugin], 912 logLevel: 'info', 913 }).catch(() => process.exit(1)) 914 ``` 915 916 This is how you might do that from Go: 917 918 ```go 919 package main 920 921 import ( 922 "encoding/json" 923 "os" 924 "strings" 925 926 "github.com/evanw/esbuild/pkg/api" 927 ) 928 929 var envPlugin = api.Plugin{ 930 Name: "env-plugin", 931 Setup: func(build api.PluginBuild) { 932 build.OnResolve(api.OnResolveOptions{Filter: `^env$`}, 933 func(args api.OnResolveArgs) (api.OnResolveResult, error) { 934 return api.OnResolveResult{ 935 Path: args.Path, 936 Namespace: "env", 937 }, nil 938 }) 939 940 build.OnLoad(api.OnLoadOptions{Filter: `.*`, Namespace: "env"}, 941 func(args api.OnLoadArgs) (api.OnLoadResult, error) { 942 mappings := make(map[string]string) 943 for _, item := range os.Environ() { 944 if equals := strings.IndexByte(item, '='); equals != -1 { 945 mappings[item[:equals]] = item[equals+1:] 946 } 947 } 948 bytes, _ := json.Marshal(mappings) 949 contents := string(bytes) 950 return api.OnLoadResult{ 951 Contents: &contents, 952 Loader: api.LoaderJSON, 953 }, nil 954 }) 955 }, 956 } 957 958 func main() { 959 result := api.Build(api.BuildOptions{ 960 EntryPoints: []string{"app.js"}, 961 Bundle: true, 962 Outfile: "out.js", 963 Plugins: []api.Plugin{envPlugin}, 964 Write: true, 965 LogLevel: api.LogLevelInfo, 966 }) 967 968 if len(result.Errors) > 0 { 969 os.Exit(1) 970 } 971 } 972 ``` 973 974 Comprehensive documentation for the plugin API is not yet available but is coming soon. 975 976 * Add the `outbase` option ([#471](https://github.com/evanw/esbuild/pull/471)) 977 978 Currently, esbuild uses the lowest common ancestor of the entrypoints to determine where to place each entrypoint's output file. This is an excellent default, but is not ideal in some situations. Take for example an app with a folder structure similar to Next.js, with js files at `pages/a/b/c.js` and `pages/a/b/d.js`. These two files correspond to the paths `/a/b/c` and `/a/b/d`. Ideally, esbuild would emit `out/a/b/c.js` and `out/a/b/d.js`. However, esbuild identifies `pages/a/b` as the lowest common ancestor and emits `out/c.js` and `out/d.js`. This release introduces an `--outbase` argument to the cli that allows the user to choose which path to base entrypoint output paths on. With this change, running esbuild with `--outbase=pages` results in the desired behavior. This change was contributed by [@nitsky](https://github.com/nitsky). 979 980 ## 0.8.0 981 982 **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](https://docs.npmjs.com/misc/semver)). You should either be pinning the exact version of `esbuild` in your `package.json` file or be using a version range syntax that only accepts patch upgrades such as `^0.7.0`. See the documentation about [semver](https://docs.npmjs.com/misc/semver) for more information. 983 984 The breaking changes are as follows: 985 986 * Changed the transform API result object 987 988 For the transform API, the return values `js` and `jsSourceMap` have been renamed to `code` and `map` respectively. This is because esbuild now supports CSS as a first-class content type, and returning CSS code in a variable called `js` made no sense. 989 990 * The class field transform is now more accurate 991 992 Class fields look like this: 993 994 ```js 995 class Foo { 996 foo = 123 997 } 998 ``` 999 1000 Previously the transform for class fields used a normal assignment for initialization: 1001 1002 ```js 1003 class Foo { 1004 constructor() { 1005 this.foo = 123; 1006 } 1007 } 1008 ``` 1009 1010 However, this doesn't exactly follow the initialization behavior in the JavaScript specification. For example, it can cause a setter to be called if one exists with that property name, which isn't supposed to happen. A more accurate transform that used `Object.defineProperty()` instead was available under the `--strict:class-fields` option. 1011 1012 This release removes the `--strict:class-fields` option and makes that the default behavior. There is no longer a way to compile class fields to normal assignments instead, since that doesn't follow JavaScript semantics. Note that for legacy reasons, TypeScript code will still compile class fields to normal assignments unless `useDefineForClassFields` is enabled in `tsconfig.json` just like the official TypeScript compiler. 1013 1014 * When bundling stdin using the API, `resolveDir` is now required to resolve imports 1015 1016 The `resolveDir` option specifies the directory to resolve relative imports against. Previously it defaulted to the current working directory. Now it no longer does, so you must explicitly specify it if you need it: 1017 1018 ```js 1019 const result = await esbuild.build({ 1020 stdin: { 1021 contents, 1022 resolveDir, 1023 }, 1024 bundle: true, 1025 outdir, 1026 }) 1027 ``` 1028 1029 This was changed because the original behavior was unintentional, and because being explicit seems better in this case. Note that this only affects the JavaScript and Go APIs. The resolution directory for stdin passed using the command-line API still defaults to the current working directory. 1030 1031 In addition, it is now possible for esbuild to discover input source maps linked via `//# sourceMappingURL=` comments relative to the `resolveDir` for stdin. This previously only worked for files with a real path on the file system. 1032 1033 * Made names in the Go API consistent 1034 1035 Previously some of the names in the Go API were unnecessarily different than the corresponding names in the CLI and JavaScript APIs. This made it harder to write documentation and examples for these APIs that work consistently across all three API surfaces. These different names in the Go API have been fixed: 1036 1037 * `Defines` → `Define` 1038 * `Externals` → `External` 1039 * `Loaders` → `Loader` 1040 * `PureFunctions` → `Pure` 1041 1042 * The global name parameter now takes a JavaScript expression ([#293](https://github.com/evanw/esbuild/issues/293)) 1043 1044 The global name parameter determines the name of the global variable created for exports with the IIFE output format. For example, a global name of `abc` would generate the following IIFE: 1045 1046 ```js 1047 var abc = (() => { 1048 ... 1049 })(); 1050 ``` 1051 1052 Previously this name was injected into the source code verbatim without any validation. This meant a global name of `abc.def` would generate this code, which is a syntax error: 1053 1054 ```js 1055 var abc.def = (() => { 1056 ... 1057 })(); 1058 ``` 1059 1060 With this release, a global name of `abc.def` will now generate the following code instead: 1061 1062 ```js 1063 var abc = abc || {}; 1064 abc.def = (() => { 1065 ... 1066 })(); 1067 ``` 1068 1069 The full syntax is an identifier followed by one or more property accesses. If you need to include a `.` character in your property name, you can use an index expression instead. For example, the global name `versions['1.0']` will generate the following code: 1070 1071 ```js 1072 var versions = versions || {}; 1073 versions["1.0"] = (() => { 1074 ... 1075 })(); 1076 ``` 1077 1078 * Removed the workaround for `document.all` with nullish coalescing and optional chaining 1079 1080 The `--strict:nullish-coalescing` and `--strict:optional-chaining` options have been removed. They only existed to address a theoretical problem where modern code that uses the new `??` and `?.` operators interacted with the legacy [`document.all` object](https://developer.mozilla.org/en-US/docs/Web/API/Document/all) that has been deprecated for a long time. Realistically this case is extremely unlikely to come up in practice, so these obscure options were removed to simplify the API and reduce code complexity. For what it's worth this behavior also matches [Terser](https://github.com/terser/terser), a commonly-used JavaScript minifier. 1081 1082 ## 0.7.22 1083 1084 * Add `tsconfigRaw` to the transform API ([#483](https://github.com/evanw/esbuild/issues/483)) 1085 1086 The `build` API uses access to the file system and doesn't run in the browser, but the `transform` API doesn't access the file system and can run in the browser. Previously you could only use the build API for certain scenarios involving TypeScript code and `tsconfig.json` files, such as configuring the `importsNotUsedAsValues` setting. 1087 1088 You can now use `tsconfig.json` with the transform API by passing in the raw contents of that file: 1089 1090 ```js 1091 let result = esbuild.transformSync(ts, { 1092 loader: 'ts', 1093 tsconfigRaw: { 1094 compilerOptions: { 1095 importsNotUsedAsValues: 'preserve', 1096 }, 1097 }, 1098 }) 1099 ``` 1100 1101 Right now four values are supported with the transform API: `jsxFactory`, `jsxFragmentFactory`, `useDefineForClassFields`, and `importsNotUsedAsValues`. The values `extends`, `baseUrl`, and `paths` are not supported because they require access to the file system and the transform API deliberately does not access the file system. 1102 1103 You can also pass the `tsconfig.json` file as a string instead of a JSON object if you prefer. This can be useful because `tsconfig.json` files actually use a weird pseudo-JSON syntax that allows comments and trailing commas, which means it can't be parsed with `JSON.parse()`. 1104 1105 * Warn about `process.env.NODE_ENV` 1106 1107 Some popular browser-oriented libraries such as React use `process.env.NODE_ENV` even though this is not an API provided by the browser. While esbuild makes it easy to replace this at compile time using the `--define` feature, you must still do this manually and it's easy to forget. Now esbuild will warn you if you're bundling code containing `process.env.NODE_ENV` for the browser and you haven't configured it to be replaced by something. 1108 1109 * Work around a bug in Safari for the run-time code ([#489](https://github.com/evanw/esbuild/issues/489)) 1110 1111 The `Object.getOwnPropertyDescriptor` function in Safari is broken for numeric properties. It incorrectly returns `undefined`, which crashes the run-time code esbuild uses to bind modules together. This release contains code to avoid a crash in this case. 1112 1113 ## 0.7.21 1114 1115 * Use bracketed escape codes for non-BMP characters 1116 1117 The previous release introduced code that escapes non-ASCII characters using ASCII escape sequences. Since JavaScript uses UCS-2/UTF-16 internally, a non-[BMP](https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane) character such as `𐀀` ended up being encoded using a [surrogate pair](https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates): `\uD800\uDC00`. This is fine when the character is contained in a string, but it causes a syntax error when that character is used as an identifier. 1118 1119 This release fixes this issue by using the newer bracketed escape code instead: `\u{10000}`. One complication with doing this is that this escape code won't work in older environments without ES6 support. Because of this, using identifiers containing non-BMP characters is now an error if the configured target environment doesn't support bracketed escape codes. 1120 1121 * Escape non-ASCII characters in properties 1122 1123 The previous release overlooked the need to escape non-ASCII characters in properties in various places in the grammar (e.g. object literals, property accesses, import and export aliases). This resulted in output containing non-ASCII characters even with `--charset=ascii`. These characters should now always be escaped, even in properties. 1124 1125 ## 0.7.20 1126 1127 * Default to ASCII-only output ([#70](https://github.com/evanw/esbuild/issues/70), [#485](https://github.com/evanw/esbuild/issues/485)) 1128 1129 While esbuild's output is encoded using UTF-8 encoding, there are many other character encodings in the wild (e.g. [Windows-1250](https://en.wikipedia.org/wiki/Windows-1250)). You can explicitly mark the output files as UTF-8 by adding `<meta charset="utf-8">` to your HTML page or by including `charset=utf-8` in the `Content-Type` header sent by your server. This is probably a good idea regardless of the contents of esbuild's output since information being displayed to users is probably also encoded using UTF-8. 1130 1131 However, sometimes it's not possible to guarantee that your users will be running your code as UTF-8. For example, you may not control the server response or the contents of the HTML page that loads your script. Also, if your code needs to run in IE, there are [certain cases](https://docs.microsoft.com/en-us/troubleshoot/browsers/wrong-character-set-for-html-page) where IE may ignore the `<meta charset="utf-8">` tag and make up another encoding instead. 1132 1133 Also content encoded using UTF-8 may be parsed up to 1.7x slower by the browser than ASCII-only content, at least according to this blog post from the V8 team: https://v8.dev/blog/scanner. The official recommendation is to "avoid non-ASCII identifiers where possible" to improve parsing performance. 1134 1135 For these reasons, esbuild's default output has been changed to ASCII-only. All Unicode code points in identifiers and strings that are outside of the printable ASCII range (`\x20-\x7E` inclusive) are escaped using backslash escape sequences. If you would like to use raw UTF-8 encoding instead, you can pass the `--charset=utf8` flag to esbuild. 1136 1137 Further details: 1138 1139 * This does not yet escape non-ASCII characters embedded in regular expressions. This is because esbuild does not currently parse the contents of regular expressions at all. The flag was added despite this limitation because it's still useful for code that doesn't contain cases like this. 1140 1141 * This flag does not apply to comments. I believe preserving non-ASCII data in comments should be fine because even if the encoding is wrong, the run time environment should completely ignore the contents of all comments. For example, the [V8 blog post](https://v8.dev/blog/scanner) mentions an optimization that avoids decoding comment contents completely. And all comments other than license-related comments are stripped out by esbuild anyway. 1142 1143 * This new `--charset` flag simultaneously applies to all output file types (JavaScript, CSS, and JSON). So if you configure your server to send the correct `Content-Type` header and want to use `--charset=utf8`, make sure your server is configured to treat both `.js` and `.css` files as UTF-8. 1144 1145 * Interpret escape sequences in CSS tokens 1146 1147 Escape sequences in CSS tokens are now interpreted. This was already the case for string and URL tokens before, but this is now the case for all identifier-like tokens as well. For example, `c\6flor: #\66 00` is now correctly recognized as `color: #f00`. 1148 1149 * Support `.css` with the `--out-extension` option 1150 1151 The `--out-extension` option was added so you could generate `.mjs` and `.cjs` files for node like this: `--out-extension:.js=.mjs`. However, now that CSS is a first-class content type in esbuild, this should also be available for `.css` files. I'm not sure why you would want to do this, but you can now do `--out-extension:.css=.something` too. 1152 1153 ## 0.7.19 1154 1155 * Add the `--avoid-tdz` option for large bundles in Safari ([#478](https://github.com/evanw/esbuild/issues/478)) 1156 1157 This is a workaround for a performance issue with certain large JavaScript files in Safari. 1158 1159 First, some background. In JavaScript the `var` statement is "hoisted" meaning the variable is declared immediately in the closest surrounding function, module, or global scope. Accessing one of these variables before its declaration has been evaluated results in the value `undefined`. In ES6 the `const`, `let`, and `class` statements introduce what's called a "temporal dead zone" or TDZ. This means that, unlike `var` statements, accessing one of these variable before its declaration has been evaluated results in a `ReferenceError` being thrown. It's called a "temporal dead zone" because it's a zone of time in which the variable is inaccessible. 1160 1161 According to [this WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=199866), there's a severe performance issue with the tracking of TDZ checks in JavaScriptCore, the JavaScript JIT compiler used by WebKit. In a large private code base I have access to, the initialization phase of the bundle produced by esbuild runs 10x faster in Safari if top-level `const`, `let`, and `class` are replaced with `var`. It's a difference between a loading time of about 2sec vs. about 200ms. This transformation is not enabled by default because it changes the semantics of the code (it removes the TDZ and `const` assignment checks). However, this change in semantics may be acceptable for you given the performance trade-off. You can enable it with the `--avoid-tdz` flag. 1162 1163 * Warn about assignment to `const` symbols 1164 1165 Now that some `const` symbols may be converted to `var` due to `--avoid-tdz`, it seems like a good idea to at least warn when an assignment to a `const` symbol is detected during bundling. Otherwise accidental assignments to `const` symbols could go unnoticed if there isn't other tooling in place such as TypeScript or a linter. 1166 1167 ## 0.7.18 1168 1169 * Treat paths in CSS without a `./` or `../` prefix as relative ([#469](https://github.com/evanw/esbuild/issues/469)) 1170 1171 JavaScript paths starting with `./` or `../` are considered relative paths, while other JavaScript paths are considered package paths and are looked up in that package's `node_modules` directory. Currently `url()` paths in CSS files use that same logic, so `url(images/image.png)` checks for a file named `image.png` in the `image` package. 1172 1173 This release changes this behavior. Now `url(images/image.png)` first checks for `./images/image.png`, then checks for a file named `image.png` in the `image` package. This behavior should match the behavior of Webpack's standard `css-loader` package. 1174 1175 * Import non-enumerable properties from CommonJS modules ([#472](https://github.com/evanw/esbuild/issues/472)) 1176 1177 You can now import non-enumerable properties from CommonJS modules using an ES6 `import` statement. Here's an example of a situation where that might matter: 1178 1179 ```js 1180 // example.js 1181 module.exports = class { 1182 static method() {} 1183 } 1184 ``` 1185 1186 ```js 1187 import { method } from './example.js' 1188 method() 1189 ``` 1190 1191 Previously that didn't work because the `method` property is non-enumerable. This should now work correctly. 1192 1193 A minor consequence of this change is that re-exporting from a file using `export * from` will no longer re-export properties inherited from the prototype of the object assigned to `module.exports`. This is because run-time property copying has been changed from a for-in loop to `Object.getOwnPropertyNames`. This change should be inconsequential because as far as I can tell this isn't something any other bundler supports either. 1194 1195 * Remove arrow functions in runtime with `--target=es5` 1196 1197 The `--target=es5` flag is intended to prevent esbuild from introducing any ES6+ syntax into the generated output file. For example, esbuild usually shortens `{x: x}` into `{x}` since it's shorter, except that requires ES6 support. This release fixes a bug where `=>` arrow expressions in esbuild's runtime of helper functions were not converted to `function` expressions when `--target=es5` was present. 1198 1199 * Merge local variable declarations across files when minifying 1200 1201 Currently files are minified in parallel and then concatenated together for maximum performance. However, that means certain constructs are not optimally minified if they span multiple files. For example, a bundle containing two files `var a = 1` and `var b = 2` should ideally become `var a=1,b=2;` after minification but it currently becomes `var a=0;var b=2;` instead due to parallelism. 1202 1203 With this release, esbuild will generate `var a=1,b=2;` in this scenario. This is achieved by splicing the two files together to remove the trailing `;` and the leading `var `, which is more complicated than it sounds when you consider rewriting the source maps. 1204 1205 ## 0.7.17 1206 1207 * Add `--public-path=` for the `file` loader ([#459](https://github.com/evanw/esbuild/issues/459)) 1208 1209 The `file` loader causes importing a file to cause that file to be copied into the output directory. The name of the file is exported as the default export: 1210 1211 ```js 1212 // Assume ".png" is set to the "file" loader 1213 import name from 'images/image.png' 1214 1215 // This prints something like "image.L3XDQOAT.png" 1216 console.log(name) 1217 ``` 1218 1219 The new public path setting configures the path prefix. So for example setting it to `https://www.example.com/v1` would change the output text for this example to `https://www.example.com/v1/image.L3XDQOAT.png`. 1220 1221 * Add `--inject:` for polyfills ([#451](https://github.com/evanw/esbuild/issues/451)) 1222 1223 It's now possible to replace global variables with imports from a file with `--inject:file.js`. Note that `file.js` must export symbols using the `export` keyword for this to work. This can be used to polyfill a global variable in code you don't control. For example: 1224 1225 ```js 1226 // process.js 1227 export let process = {cwd() {}} 1228 ``` 1229 1230 ```js 1231 // entry.js 1232 console.log(process.cwd()) 1233 ``` 1234 1235 Building this with `esbuild entry.js --inject:process.js` gives this: 1236 1237 ```js 1238 let process = {cwd() { 1239 }}; 1240 console.log(process.cwd()); 1241 ``` 1242 1243 You can also combine this with the existing `--define` feature to be more selective about what you import. For example: 1244 1245 ```js 1246 // process.js 1247 export function dummy_process_cwd() {} 1248 ``` 1249 1250 ```js 1251 // entry.js 1252 console.log(process.cwd()) 1253 ``` 1254 1255 Building this with `esbuild entry.js --inject:process.js --define:process.cwd=dummy_process_cwd` gives this: 1256 1257 ```js 1258 function dummy_process_cwd() { 1259 } 1260 console.log(dummy_process_cwd()); 1261 ``` 1262 1263 Note that this means you can use `--inject` to provide the implementation for JSX expressions (e.g. auto-import the `react` package): 1264 1265 ```js 1266 // shim.js 1267 export * as React from 'react' 1268 ``` 1269 1270 ```jsx 1271 // entry.jsx 1272 console.log(<div/>) 1273 ``` 1274 1275 Building this with `esbuild entry.js --inject:shim.js --format=esm` gives this: 1276 1277 ```js 1278 import * as React from "react"; 1279 console.log(/* @__PURE__ */ React.createElement("div", null)); 1280 ``` 1281 1282 You can also use `--inject:file.js` with files that have no exports. In that case the injected file just comes first before the rest of the output as if every input file contained `import "./file.js"`. Because of the way ECMAScript modules work, this injection is still "hygienic" in that symbols with the same name in different files are renamed so they don't collide with each other. 1283 1284 If you want to _conditionally_ import a file only if the export is actually used, you should mark the injected file as not having side effects by putting it in a package and adding `"sideEffects": false` in that package's `package.json` file. This setting is a [convention from Webpack](https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free) that esbuild respects for any imported file, not just files used with `--inject`. 1285 1286 * Add an ECMAScript module build for the browser ([#342](https://github.com/evanw/esbuild/pull/342)) 1287 1288 The [current browser API](https://github.com/evanw/esbuild/blob/cfaedaeeb35ae6e8b42921ab98ad98f75375d39f/docs/js-api.md#browser-api) lets you use esbuild in the browser via the `esbuild-wasm` package and a script tag: 1289 1290 ```html 1291 <script src="node_modules/esbuild-wasm/lib/browser.js"></script> 1292 <script> 1293 esbuild.startService({ 1294 wasmURL: 'node_modules/esbuild-wasm/esbuild.wasm', 1295 }).then(service => { 1296 // Use service 1297 }) 1298 </script> 1299 ``` 1300 1301 In addition to this approach, you can now also use esbuild in the browser from a module-type script (note the use of `esm/browser.js` instead of `lib/browser.js`): 1302 1303 ```html 1304 <script type="module"> 1305 import * as esbuild from 'node_modules/esbuild-wasm/esm/browser.js' 1306 esbuild.startService({ 1307 wasmURL: 'node_modules/esbuild-wasm/esbuild.wasm', 1308 }).then(service => { 1309 // Use service 1310 }) 1311 </script> 1312 ``` 1313 1314 Part of this fix was contributed by [@calebeby](https://github.com/calebeby). 1315 1316 ## 0.7.16 1317 1318 * Fix backward slashes in source maps on Windows ([#463](https://github.com/evanw/esbuild/issues/463)) 1319 1320 The relative path fix in the previous release caused a regression where paths in source maps contained `\` instead of `/` on Windows. That is incorrect because source map paths are URLs, not file system paths. This release replaces `\` with `/` for consistency on Windows. 1321 1322 * `module.require()` is now an alias for `require()` ([#455](https://github.com/evanw/esbuild/issues/455)) 1323 1324 Some packages such as [apollo-server](https://github.com/apollographql/apollo-server) use `module.require()` instead of `require()` with the intent of bypassing the bundler's `require` and calling the underlying function from `node` instead. Unfortunately that doesn't actually work because CommonJS module semantics means `module` is a variable local to that file's CommonJS closure instead of the host's `module` object. 1325 1326 This wasn't an issue when using `apollo-server` with Webpack because the literal expression `module.require()` is automatically rewritten to `require()` by Webpack: [webpack/webpack#7750](https://github.com/webpack/webpack/pull/7750). To get this package to work, esbuild now matches Webpack's behavior here. Calls to `module.require()` will become external calls to `require()` as long as the required path has been marked as external. 1327 1328 ## 0.7.15 1329 1330 * Lower `export * as` syntax for ES2019 and below 1331 1332 The `export * from 'path'` syntax was added in ES2015 but the `export * as name from 'path'` syntax was added more recently in ES2020. This is a shorthand for an import followed by an export: 1333 1334 ```js 1335 // ES2020 1336 export * as name from 'path' 1337 1338 // ES2019 1339 import * as name from 'path' 1340 export {name} 1341 ``` 1342 1343 With this release, esbuild will now undo this shorthand syntax when using `--target=es2019` or below. 1344 1345 * Better code generation for TypeScript files with type-only exports ([#447](https://github.com/evanw/esbuild/issues/447)) 1346 1347 Previously TypeScript files could have an unnecessary CommonJS wrapper in certain situations. The specific situation is bundling a file that re-exports something from another file without any exports. This happens because esbuild automatically considers a module to be a CommonJS module if there is no ES6 `import`/`export` syntax. 1348 1349 This behavior is undesirable because the CommonJS wrapper is usually unnecessary. It's especially undesirable for cases where the re-export uses `export * from` because then the re-exporting module is also converted to a CommonJS wrapper (since re-exporting everything from a CommonJS module must be done at run-time). That can also impact the bundle's exports itself if the entry point does this and the format is `esm`. 1350 1351 It is generally equivalent to avoid the CommonJS wrapper and just rewrite the imports to an `undefined` literal instead: 1352 1353 ```js 1354 import {name} from './empty-file' 1355 console.log(name) 1356 ``` 1357 1358 This can be rewritten to this instead (with a warning generated about `name` being missing): 1359 1360 ```js 1361 console.log(void 0) 1362 ``` 1363 1364 With this release, this is now how cases like these are handled. The only case where this can't be done is when the import uses the `import * as` syntax. In that case a CommonJS wrapper is still necessary because the namespace cannot be rewritten to `undefined`. 1365 1366 * Add support for `importsNotUsedAsValues` in TypeScript ([#448](https://github.com/evanw/esbuild/issues/448)) 1367 1368 The `importsNotUsedAsValues` field in `tsconfig.json` is now respected. Setting it to `"preserve"` means esbuild will no longer remove unused imports in TypeScript files. This field was added in TypeScript 3.8. 1369 1370 * Fix relative paths in generated source maps ([#444](https://github.com/evanw/esbuild/issues/444)) 1371 1372 Currently paths in generated source map files don't necessarily correspond to real file system paths. They are really only meant to be human-readable when debugging in the browser. 1373 1374 However, the Visual Studio Code debugger expects these paths to point back to the original files on the file system. With this release, it should now always be possible to get back to the original source file by joining the directory containing the source map file with the relative path in the source map. 1375 1376 This fix was contributed by [@yoyo930021](https://github.com/yoyo930021). 1377 1378 ## 0.7.14 1379 1380 * Fix a bug with compound import statements ([#446](https://github.com/evanw/esbuild/issues/446)) 1381 1382 Import statements can simultaneously contain both a default import and a namespace import like this: 1383 1384 ```js 1385 import defVal, * as nsVal from 'path' 1386 ``` 1387 1388 These statements were previously miscompiled when bundling if the import path was marked as external, or when converting to a specific output format, and the namespace variable itself was used for something other than a property access. The generated code contained a syntax error because it generated a `{...}` import clause containing the default import. 1389 1390 This particular problem was caused by code that converts namespace imports into import clauses for more efficient bundling. This transformation should not be done if the namespace import cannot be completely removed: 1391 1392 ```js 1393 // Can convert namespace to clause 1394 import defVal, * as nsVal from 'path' 1395 console.log(defVal, nsVal.prop) 1396 ``` 1397 1398 ```js 1399 // Cannot convert namespace to clause 1400 import defVal, * as nsVal from 'path' 1401 console.log(defVal, nsVal) 1402 ``` 1403 1404 ## 0.7.13 1405 1406 * Fix `mainFields` in the JavaScript API ([#440](https://github.com/evanw/esbuild/issues/440) and [#441](https://github.com/evanw/esbuild/pull/441)) 1407 1408 It turns out the JavaScript bindings for the `mainFields` API option didn't work due to a copy/paste error. The fix for this was contributed by [@yoyo930021](https://github.com/yoyo930021). 1409 1410 * The benchmarks have been updated 1411 1412 The benchmarks now include Parcel 2 and Webpack 5 (in addition to Parcel 1 and Webpack 4, which were already included). It looks like Parcel 2 is slightly faster than Parcel 1 and Webpack 5 is significantly slower than Webpack 4. 1413 1414 ## 0.7.12 1415 1416 * Fix another subtle ordering issue with `import` statements 1417 1418 When importing a file while bundling, the import statement was ordered before the imported code. This could affect import execution order in complex scenarios involving nested hybrid ES6/CommonJS modules. The fix was to move the import statement to after the imported code instead. This issue affected the `@sentry/browser` package. 1419 1420 ## 0.7.11 1421 1422 * Fix regression in 0.7.9 when minifying with code splitting ([#437](https://github.com/evanw/esbuild/issues/437)) 1423 1424 In certain specific cases, bundling and minifying with code splitting active can cause a crash. This is a regression that was introduced in version 0.7.9 due to the fix for issue [#421](https://github.com/evanw/esbuild/issues/421). The crash has been fixed and this case now has test coverage. 1425 1426 ## 0.7.10 1427 1428 * Recover from bad `main` field in `package.json` ([#423](https://github.com/evanw/esbuild/issues/423)) 1429 1430 Some packages are published with invalid information in the `main` field of `package.json`. In that case, path resolution should fall back to searching for a file named `index.js` before giving up. This matters for the `simple-exiftool` package, for example. 1431 1432 * Ignore TypeScript types on `catch` clause bindings ([435](https://github.com/evanw/esbuild/issues/435)) 1433 1434 This fixes an issue where using a type annotation in a `catch` clause like this was a syntax error: 1435 1436 ```ts 1437 try { 1438 } catch (x: unknown) { 1439 } 1440 ``` 1441 1442 ## 0.7.9 1443 1444 * Fixed panic when using a `url()` import in CSS with the `--metafile` option 1445 1446 This release fixes a crash that happens when `metafile` output is enabled and the `url()` syntax is used in a CSS file to import a successfully-resolved file. 1447 1448 * Minify some CSS colors 1449 1450 The minifier can now reduce the size of some CSS colors. This is the initial work to start CSS minification in general beyond whitespace removal. There is currently support for minifying hex, `rgb()/rgba()`, and `hsl()/hsla()` into hex or shorthand hex. The minification process respects the configured target browser and doesn't use any syntax that wouldn't be supported. 1451 1452 * Lower newer CSS syntax for older browsers 1453 1454 Newer color syntax such as `rgba(255 0 0 / 50%)` will be converted to older syntax (in this case `rgba(255, 0, 0, 0.5)`) when the target browser doesn't support the newer syntax. For example, this happens when using `--target=chrome60`. 1455 1456 * Fix an ordering issue with `import` statements ([#421](https://github.com/evanw/esbuild/issues/421)) 1457 1458 Previously `import` statements that resolved to a CommonJS module turned into a call to `require()` inline. This was subtly incorrect when combined with tree shaking because it could sometimes cause imported modules to be reordered: 1459 1460 ```js 1461 import {foo} from './cjs-file' 1462 import {bar} from './esm-file' 1463 console.log(foo, bar) 1464 ``` 1465 1466 That code was previously compiled into something like this, which is incorrect because the evaluation of `bar` may depend on side effects from importing `cjs-file.js`: 1467 1468 ```js 1469 // ./cjs-file.js 1470 var require_cjs_file = __commonJS(() => { 1471 ... 1472 }) 1473 1474 // ./esm-file.js 1475 let bar = ...; 1476 1477 // ./example.js 1478 const cjs_file = __toModule(require_cjs_file()) 1479 console.log(cjs_file.foo, bar) 1480 ``` 1481 1482 That code is now compiled into something like this: 1483 1484 ```js 1485 // ./cjs-file.js 1486 var require_cjs_file = __commonJS(() => { 1487 ... 1488 }) 1489 1490 // ./example.js 1491 const cjs_file = __toModule(require_cjs_file()) 1492 1493 // ./esm-file.js 1494 let bar = ...; 1495 1496 // ./example.js 1497 console.log(cjs_file.foo, bar) 1498 ``` 1499 1500 This now means that a single input file can end up in multiple discontiguous regions in the output file as is the case with `example.js` here, which wasn't the case before this bug fix. 1501 1502 ## 0.7.8 1503 1504 * Move external `@import` rules to the top 1505 1506 Bundling could cause `@import` rules for paths that have been marked as external to be inserted in the middle of the CSS file. This would cause them to become invalid and be ignored by the browser since all `@import` rules must come first at the top of the file. These `@import` rules are now always moved to the top of the file so they stay valid. 1507 1508 * Better support for `@keyframes` rules 1509 1510 The parser now directly understands `@keyframes` rules, which means it can now format them more accurately and report more specific syntax errors. 1511 1512 * Minify whitespace around commas in CSS 1513 1514 Whitespace around commas in CSS will now be pretty-printed when not minifying and removed when minifying. So `a , b` becomes `a, b` when pretty-printed and `a,b` when minified. 1515 1516 * Warn about unknown at-rules in CSS 1517 1518 Using an `@rule` in a CSS file that isn't known by esbuild now generates a warning and these rules will be passed through unmodified. If they aren't known to esbuild, they are probably part of a CSS preprocessor syntax that should have been compiled away before giving the file to esbuild to parse. 1519 1520 * Recoverable CSS syntax errors are now warnings 1521 1522 The base CSS syntax can preserve nonsensical rules as long as they contain valid tokens and have matching opening and closing brackets. These rule with incorrect syntax now generate a warning instead of an error and esbuild preserves the syntax in the output file. This makes it possible to use esbuild to process CSS that was generated by another tool that contains bugs. 1523 1524 For example, the following code is invalid CSS, and was presumably generated by a bug in an automatic prefix generator: 1525 1526 ```css 1527 div { 1528 -webkit-undefined; 1529 -moz-undefined; 1530 -undefined; 1531 } 1532 ``` 1533 1534 This code will no longer prevent esbuild from processing the CSS file. 1535 1536 * Treat `url(...)` in CSS files as an import ([#415](https://github.com/evanw/esbuild/issues/415)) 1537 1538 When bundling, the `url(...)` syntax in CSS now tries to resolve the URL as a path using the bundler's built in path resolution logic. The following loaders can be used with this syntax: `text`, `base64`, `file`, `dataurl`, and `binary`. 1539 1540 * Automatically treat certain paths as external 1541 1542 The following path forms are now automatically considered external: 1543 1544 * `http://example.com/image.png` 1545 * `https://example.com/image.png` 1546 * `//example.com/image.png` 1547 * `data:image/png;base64,iVBORw0KGgo=` 1548 1549 In addition, paths starting with `#` are considered external in CSS files, which allows the following syntax to continue to work: 1550 1551 ```css 1552 path { 1553 /* This can be useful with SVG DOM content */ 1554 fill: url(#filter); 1555 } 1556 ``` 1557 1558 ## 0.7.7 1559 1560 * Fix TypeScript decorators on static members 1561 1562 This release fixes a bug with the TypeScript transform for the `experimentalDecorators` setting. Previously the target object for all decorators was the class prototype, which was incorrect for static members. Static members now correctly use the class object itself as a target object. 1563 1564 * Experimental support for CSS syntax ([#20](https://github.com/evanw/esbuild/issues/20)) 1565 1566 This release introduces the new `css` loader, enabled by default for `.css` files. It has the following features: 1567 1568 * You can now use esbuild to process CSS files by passing a CSS file as an entry point. This means CSS is a new first-class file type and you can use it without involving any JavaScript code at all. 1569 1570 * When bundling is enabled, esbuild will bundle multiple CSS files together if they are referenced using the `@import "./file.css";` syntax. CSS files can be excluded from the bundle by marking them as external similar to JavaScript files. 1571 1572 * There is basic support for pretty-printing CSS, and for whitespace removal when the `--minify` flag is present. There isn't any support for CSS syntax compression yet. Note that pretty-printing and whitespace removal both rely on the CSS syntax being recognized. Currently esbuild only recognizes certain CSS syntax and passes through unrecognized syntax unchanged. 1573 1574 Some things to keep in mind: 1575 1576 * CSS support is a significant undertaking and this is the very first release. There are almost certainly going to be issues. This is an experimental release to land the code and get feedback. 1577 1578 * There is no support for CSS modules yet. Right now all class names are in the global namespace. Importing a CSS file into a JavaScript file will not result in any import names. 1579 1580 * There is currently no support for code splitting of CSS. I haven't tested multiple entry-point scenarios yet and code splitting will require additional changes to the AST format. 1581 1582 ## 0.7.6 1583 1584 * Fix JSON files with multiple entry points ([#413](https://github.com/evanw/esbuild/issues/413)) 1585 1586 This release fixes an issue where a single build operation containing multiple entry points and a shared JSON file which is used by more than one of those entry points can generate incorrect code for the JSON file when code splitting is disabled. The problem was not cloning the AST representing the JSON file before mutating it. 1587 1588 * Silence warnings about `require.resolve()` for external paths ([#410](https://github.com/evanw/esbuild/issues/410)) 1589 1590 Bundling code containing a call to node's [`require.resolve()`](https://nodejs.org/api/modules.html#modules_require_resolve_request_options) function causes a warning because it's an unsupported use of `require` that does not end up being bundled. For example, the following code will likely have unexpected behavior if `foo` ends up being bundled because the `require()` call is evaluated at bundle time but the `require.resolve()` call is evaluated at run time: 1591 1592 ```js 1593 let foo = { 1594 path: require.resolve('foo'), 1595 module: require('foo'), 1596 }; 1597 ``` 1598 1599 These warnings can already be disabled by surrounding the code with a `try`/`catch` statement. With this release, these warnings can now also be disabled by marking the path as external. 1600 1601 * Ensure external relative paths start with `./` or `../` 1602 1603 Individual file paths can be marked as external in addition to package paths. In that case, the path to the file is rewritten to be relative to the output directory. However, previously the relative path for files in the output directory itself did not start with `./`, meaning they could potentially be interpreted as a package path instead of a relative path. These paths are now prefixed with `./` to avoid this edge case. 1604 1605 ## 0.7.5 1606 1607 * Fix an issue with automatic semicolon insertion after `let` ([#409](https://github.com/evanw/esbuild/issues/409)) 1608 1609 The character sequence `let` can be considered either a keyword or an identifier depending on the context. A fix was previously landed in version 0.6.31 to consider `let` as an identifier in code like this: 1610 1611 ```js 1612 if (0) let 1613 x = 0 1614 ``` 1615 1616 Handling this edge case is useless but the behavior is required by the specification. However, that fix also unintentionally caused `let` to be considered an identifier in code like this: 1617 1618 ```js 1619 let 1620 x = 0 1621 ``` 1622 1623 In this case, `let` should be considered a keyword instead. This has been fixed. 1624 1625 * Fix some additional conformance tests 1626 1627 Some additional syntax edge cases are now forbidden including `let let`, `import {eval} from 'path'`, and `if (1) x: function f() {}`. 1628 1629 ## 0.7.4 1630 1631 * Undo an earlier change to try to improve yarn compatibility ([#91](https://github.com/evanw/esbuild/pull/91) and [#407](https://github.com/evanw/esbuild/issues/407)) 1632 1633 The [yarn package manager](https://github.com/yarnpkg/yarn) behaves differently from npm and is not compatible in many ways. While npm is the only officially supported package manager for esbuild, people have contributed fixes for other package managers including yarn. One such fix is PR [#91](https://github.com/evanw/esbuild/pull/91) which makes sure the install script only runs once for a given installation directory. 1634 1635 I suspect this fix is actually incorrect, and is the cause of issue [#407](https://github.com/evanw/esbuild/issues/407). The problem seems to be that if you change the version of a package using `yarn add esbuild@version`, yarn doesn't clear out the installation directory before reinstalling the package so the package ends up with a mix of files from both package versions. This is not how npm behaves and seems like a pretty severe bug in yarn. I am reverting PR [#91](https://github.com/evanw/esbuild/pull/91) in an attempt to fix this issue. 1636 1637 * Disable some warnings for code inside `node_modules` directories ([#395](https://github.com/evanw/esbuild/issues/395) and [#402](https://github.com/evanw/esbuild/issues/402)) 1638 1639 Using esbuild to build code with certain suspicious-looking syntax may generate a warning. These warnings don't fail the build (the build still succeeds) but they point out code that is very likely to not behave as intended. This has caught real bugs in the past: 1640 1641 * [rollup/rollup#3729](https://github.com/rollup/rollup/issues/3729): Invalid dead code removal for return statement due to ASI 1642 * [aws/aws-sdk-js#3325](https://github.com/aws/aws-sdk-js/issues/3325): Array equality bug in the Node.js XML parser 1643 * [olifolkerd/tabulator#2962](https://github.com/olifolkerd/tabulator/issues/2962): Nonsensical comparisons with typeof and "null" 1644 * [mrdoob/three.js#11183](https://github.com/mrdoob/three.js/pull/11183): Comparison with -0 in Math.js 1645 * [mrdoob/three.js#11182](https://github.com/mrdoob/three.js/pull/11182): Operator precedence bug in WWOBJLoader2.js 1646 1647 However, it's not esbuild's job to find bugs in other libraries, and these warnings are problematic for people using these libraries with esbuild. The only fix is to either disable all esbuild warnings and not get warnings about your own code, or to try to get the warning fixed in the affected library. This is especially annoying if the warning is a false positive as was the case in https://github.com/firebase/firebase-js-sdk/issues/3814. So these warnings are now disabled for code inside `node_modules` directories. 1648 1649 ## 0.7.3 1650 1651 * Fix compile error due to missing `unix.SYS_IOCTL` in the latest `golang.org/x/sys` ([#396](https://github.com/evanw/esbuild/pull/396)) 1652 1653 The `unix.SYS_IOCTL` export was apparently removed from `golang.org/x/sys` recently, which affected code in esbuild that gets the width of the terminal. This code now uses another method of getting the terminal width. The fix was contributed by [@akayj](https://github.com/akayj). 1654 1655 * Validate that the versions of the host code and the binary executable match ([#407](https://github.com/evanw/esbuild/issues/407)) 1656 1657 After the install script runs, the version of the downloaded binary should always match the version of the package being installed. I have added some additional checks to verify this in case this invariant is ever broken. Breaking this invariant is very bad because it means the code being run is a mix of code from different package versions. 1658 1659 ## 0.7.2 1660 1661 * Transform arrow functions to function expressions with `--target=es5` ([#182](https://github.com/evanw/esbuild/issues/182) and [#297](https://github.com/evanw/esbuild/issues/297)) 1662 1663 Arrow functions are now transformed into function expressions when targeting `es5`. For example, this code: 1664 1665 ```js 1666 function foo() { 1667 var x = () => [this, arguments] 1668 return x() 1669 } 1670 ``` 1671 1672 is transformed into this code: 1673 1674 ```js 1675 function foo() { 1676 var _this = this, _arguments = arguments; 1677 var x = function() { 1678 return [_this, _arguments]; 1679 }; 1680 return x(); 1681 } 1682 ``` 1683 1684 * Parse template literal types from TypeScript 4.1 1685 1686 TypeScript 4.1 includes a new feature called template literal types. You can read [the announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types) for more details. The following syntax can now be parsed correctly by esbuild: 1687 1688 ```ts 1689 let foo: `${'a' | 'b'}-${'c' | 'd'}` = 'a-c' 1690 ``` 1691 1692 * Parse key remapping in mapped types from TypeScript 4.1 1693 1694 TypeScript 4.1 includes a new feature called key remapping in mapped types. You can read [the announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#key-remapping-mapped-types) for more details. The following syntax can now be parsed correctly by esbuild: 1695 1696 ```ts 1697 type RemoveField<T, F> = { [K in keyof T as Exclude<K, F>]: T[K] } 1698 ``` 1699 1700 * Allow automatic semicolon insertion before the TypeScript `as` operator 1701 1702 The following code now correctly parses as two separate statements instead of one statement with a newline in the middle: 1703 1704 ```ts 1705 let foo = bar 1706 as (null); 1707 ``` 1708 1709 * Fix a bug where `module` was incorrectly minified for non-JavaScript loaders 1710 1711 If you pass a non-JavaScript file such as a `.json` file to esbuild, it will by default generate `module.exports = {...}`. However, the `module` variable would incorrectly be minified when `--minify` is present. This issue has been fixed. This bug did not appear if `--format=cjs` was also present, only if no `--format` flag was specified. 1712 1713 * Fix bugs with `async` functions ([#388](https://github.com/evanw/esbuild/issues/388)) 1714 1715 This release contains correctness fixes for `async` arrow functions with regard to the `arguments` variable. This affected `async` arrow functions nested inside `function` expressions or statements. Part of this fix was contributed by [@rtsao](https://github.com/rtsao). 1716 1717 * Fix `export` clause when converting to CommonJS in transform API calls ([#393](https://github.com/evanw/esbuild/issues/393)) 1718 1719 This release fixes some bugs with the recently-released feature in version 0.6.32 where you can specify an output format even when bundling is disabled. This is the case when using the transform API call, for example. Previously esbuild could generate code that crashed at run time while trying to export something incorrectly. This only affected code with top-level `export` statements. This has been fixed and these cases now have test coverage. 1720 1721 ## 0.7.1 1722 1723 * Fix bug that forbids `undefined` values in the JavaScript API 1724 1725 The validation added in the previous release was accidentally overly restrictive and forbids `undefined` values for optional properties. This release allows `undefined` values again (which are simply ignored). 1726 1727 ## 0.7.0 1728 1729 * Mark output files with a hashbang as executable ([#364](https://github.com/evanw/esbuild/issues/364)) 1730 1731 Output files that start with a hashbang line such as `#!/usr/bin/env node` will now automatically be marked as executable. This lets you run them directly in a Unix-like shell without using the `node` command. 1732 1733 * Use `"main"` for `require()` and `"module"` for `import` ([#363](https://github.com/evanw/esbuild/issues/363)) 1734 1735 The [node module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together) uses the `"main"` field in `package.json` to determine which file to load when a package is loaded with `require()`. Independent of node, most bundlers have converged on a convention where the `"module"` field takes precedence over the `"main"` field when present. Package authors can then use the `"module"` field to publish the same code in a different format for bundlers than for node. 1736 1737 This is commonly used to publish "dual packages" that appear to use ECMAScript modules to bundlers but that appear to use CommonJS modules to node. This is useful because ECMAScript modules improve bundler output by taking advantage of "tree shaking" (basically dead-code elimination) and because ECMAScript modules cause lots of problems in node (for example, node doesn't support importing ECMAScript modules using `require()`). 1738 1739 The problem is that if code using `require()` resolves to the `"module"` field in esbuild, the resulting value is currently always an object. ECMAScript modules export a namespace containing all exported properties. There is no direct equivalent of `module.exports = value` in CommonJS. The closest is `export default value` but the CommonJS equivalent of that is `exports.default = value`. This is problematic for code containing `module.exports = function() {}` which is a frequently-used CommonJS library pattern. An example of such an issue is Webpack issue [#6584](https://github.com/webpack/webpack/issues/6584). 1740 1741 An often-proposed way to fix this is to map `require()` to `"main"` and map `import` to `"module"`. The problem with this is that it means the same package would be loaded into memory more than once if it is loaded both with `require()` and with `import` (perhaps from separate packages). An example of such an issue is GraphQL issue [#1479](https://github.com/graphql/graphql-js/issues/1479#issuecomment-416718578). 1742 1743 The workaround for these problems in this release is that esbuild will now exclusively use `"main"` for a package that is loaded using `require()` at least once. Otherwise, if a package is only loaded using `import`, esbuild will exclusively use the `"module"` field. This still takes advantage of tree shaking for ECMAScript modules but gracefully falls back to CommonJS for compatibility. 1744 1745 Keep in mind that the [`"browser"` field](https://github.com/defunctzombie/package-browser-field-spec) still takes precedence over both `"module"` and `"main"` when building for the browser platform. 1746 1747 * Add the `--main-fields=` flag ([#363](https://github.com/evanw/esbuild/issues/363)) 1748 1749 This adopts a configuration option from Webpack that lets you specify the order of "main fields" from `package.json` to use when determining the main module file for a package. Node only uses `main` but bundlers often respect other ones too such as `module` or `browser`. You can read more about this feature in the Webpack documentation [here](https://webpack.js.org/configuration/resolve/#resolvemainfields). 1750 1751 The default order when targeting the browser is essentially `browser,module,main` with the caveat that `main` may be chosen over `module` for CommonJS compatibility as described above. If choosing `module` over `main` at the expense of CommonJS compatibility is important to you, this behavior can be disabled by explicitly specifying `--main-fields=browser,module,main`. 1752 1753 The default order when targeting node is `main,module`. Note that this is different than Webpack, which defaults to `module,main`. This is also for compatibility because some packages incorrectly treat `module` as meaning "code for the browser" instead of what it actually means, which is "code for ES6 environments". Unfortunately this disables most tree shaking that would otherwise be possible because it means CommonJS modules will be chosen over ECMAScript modules. If choosing `module` over `main` is important to you (e.g. to potentially take advantage of improved tree shaking), this behavior can be disabled by explicitly specifying `--main-fields=module,main`. 1754 1755 * Additional validation of arguments to JavaScript API calls ([#381](https://github.com/evanw/esbuild/issues/381)) 1756 1757 JavaScript API calls each take an object with many optional properties as an argument. Previously there was only minimal validation of the contents of that object. If you aren't using TypeScript, this can lead to confusing situations when the data on the object is invalid. Now there is some additional validation done to the shape of the object and the types of the properties. 1758 1759 It is now an error to pass an object with a property that esbuild won't use. This should help to catch typos. It is also now an error if a property on the object has an unexpected type. 1760 1761 ## 0.6.34 1762 1763 * Fix parsing of `type;` statements followed by an identifier in TypeScript ([#377](https://github.com/evanw/esbuild/pull/377)) 1764 1765 The following TypeScript code is now correctly parsed as two separate expression statements instead of one type declaration statement: 1766 1767 ```ts 1768 type 1769 Foo = {} 1770 ``` 1771 1772 This was contributed by [@rtsao](https://github.com/rtsao). 1773 1774 * Fix `export {Type}` in TypeScript when bundling ([#379](https://github.com/evanw/esbuild/issues/379)) 1775 1776 In TypeScript, `export {Type}` is supposed to be silently removed by the compiler if `Type` does not refer to a value declared locally in the file. Previously this behavior was incompletely implemented. The statement itself was removed but the export record was not, so later stages of the pipeline could sometimes add the export statement back. This release removes the export record as well as the statement so it should stay removed in all cases. 1777 1778 * Forbid exporting non-local symbols in JavaScript 1779 1780 It is now an error to export an identifier using `export {foo}` if `foo` is not declared locally in the same file. This error matches the error that would happen at run-time if the code were to be evaluated in a JavaScript environment that supports ES6 module syntax. This is only an error in JavaScript. In TypeScript, the missing identifier is silently removed instead since it's assumed to be a type name. 1781 1782 * Handle source maps with out-of-order mappings ([#378](https://github.com/evanw/esbuild/issues/378)) 1783 1784 Almost all tools that generate source maps write out the mappings in increasing order by generated position since the mappings are generated along with the output. However, some tools can apparently generate source maps with out-of-order mappings. It's impossible for generated line numbers to be out of order due to the way the source map format works, but it's possible for generated column numbers to be out of order. This release fixes this issue by sorting the mappings by generated position after parsing if necessary. 1785 1786 ## 0.6.33 1787 1788 * Fix precedence of tagged template expressions ([#372](https://github.com/evanw/esbuild/issues/372)) 1789 1790 Previously `` await tag`text` `` and `` new tag`text` `` were incorrectly parsed as `` (await tag)`text` `` and `` (new tag)`text` ``. They are now correctly parsed as `` await (tag`text`) `` and `` new (tag`text`) `` instead. 1791 1792 * Fix invalid syntax when lowering `super` inside `async` to `es2016` or earlier ([#375](https://github.com/evanw/esbuild/issues/375)) 1793 1794 This release fixes a bug where using `super.prop` inside an `async` function with `--target=es2016` or earlier generated code that contained a syntax error. This was because `async` functions are converted to generator functions inside a wrapper function in this case, and `super` is not available inside the wrapper function. The fix is to move the reference to `super` outside of the wrapper function. 1795 1796 * Fix duplicate definition of `module` when targeting CommonJS ([#370](https://github.com/evanw/esbuild/issues/370)) 1797 1798 The bundler didn't properly reserve the identifier `module` when using `--format=cjs`. This meant automatically-generated variables named `module` could potentially not be renamed to avoid collisions with the CommonJS `module` variable. It was possible to get into this situation when importing a module named `module`, such as the [node built-in module by that name](https://nodejs.org/api/module.html). This name is now marked as reserved when bundling to CommonJS, so automatically-generated variables named `module` will now be renamed to `module2` to avoid collisions. 1799 1800 ## 0.6.32 1801 1802 * Allow `--format` when bundling is disabled ([#109](https://github.com/evanw/esbuild/issues/109)) 1803 1804 This change means esbuild can be used to convert ES6 import and export syntax to CommonJS syntax. The following code: 1805 1806 ```js 1807 import foo from 'foo' 1808 export const bar = foo 1809 ``` 1810 1811 will be transformed into the following code with `--format=cjs` (the code for `__export` and `__toModule` was omitted for brevity): 1812 1813 ```js 1814 __export(exports, { 1815 bar: () => bar 1816 }); 1817 const foo = __toModule(require("foo")); 1818 const bar = foo.default; 1819 ``` 1820 1821 This also applies to non-JavaScript loaders too. The following JSON: 1822 1823 ```json 1824 {"foo": true, "bar": false} 1825 ``` 1826 1827 is normally converted to the following code with `--loader=json`: 1828 1829 ```js 1830 module.exports = {foo: true, bar: false}; 1831 ``` 1832 1833 but will be transformed into the following code instead with `--loader=json --format=esm`: 1834 1835 ```js 1836 var foo = true; 1837 var bar = false; 1838 var stdin_default = {foo, bar}; 1839 export { 1840 bar, 1841 stdin_default as default, 1842 foo 1843 }; 1844 ``` 1845 1846 Note that converting CommonJS `require()` calls to ES6 imports is not currently supported. Code containing a reference to `require` in these situations will generate a warning. 1847 1848 * Change the flag for boolean and string minification ([#371](https://github.com/evanw/esbuild/issues/371)) 1849 1850 Previously setting the `--minify-whitespace` flag shortened `true` and `false` to `!0` and `!1` and shortened string literals containing many newlines by writing them as template literals instead. These shortening operations have been changed to the `--minify-syntax` flag instead. There is no change in behavior for the `--minify` flag because that flag already implies both `--minify-whitespace` and `--minify-syntax`. 1851 1852 * Remove trailing `()` from `new` when minifying 1853 1854 Now `new Foo()` will be printed as `new Foo` when minifying (as long as it's safe to do so), resulting in slightly shorter minified code. 1855 1856 * Forbid `async` functions when the target is `es5` 1857 1858 Previously using `async` functions did not cause a compile error when targeting `es5` since if they are unavailable, they are rewritten to use generator functions instead. However, generator functions may also be unsupported. It is now an error to use `async` functions if generator functions are unsupported. 1859 1860 * Fix subtle issue with transforming `async` functions when targeting `es2016` or below 1861 1862 The TypeScript compiler has a bug where, when the language target is set to `ES2016` or earlier, exceptions thrown during argument evaluation are incorrectly thrown immediately instead of later causing the returned promise to be rejected. Since esbuild replicates TypeScript's `async` function transformation pass, esbuild inherited this same bug. The behavior of esbuild has been changed to match the JavaScript specification. 1863 1864 Here's an example of code that was affected: 1865 1866 ```js 1867 async function test(value = getDefaultValue()) {} 1868 let promise = test() 1869 ``` 1870 1871 The call to `test()` here should never throw, even if `getDefaultValue()` throws an exception. 1872 1873 ## 0.6.31 1874 1875 * Invalid source maps are no longer an error ([#367](https://github.com/evanw/esbuild/issues/367)) 1876 1877 Previously esbuild would fail the build with an error if it encountered a source map that failed validation according to [the specification](https://sourcemaps.info/spec.html). Now invalid source maps will be validated with an error-tolerant validator that will either silently ignore errors or generate a warning, but will never fail the build. 1878 1879 * Fix various edge cases for conformance tests 1880 1881 * Hoisted function declarations in nested scopes can now shadow symbols in the enclosing scope without a syntax error: 1882 1883 ```js 1884 let foo 1885 { 1886 function foo() {} 1887 } 1888 ``` 1889 1890 * If statements directly containing function declarations now introduce a nested scope so this code is no longer a syntax error: 1891 1892 ```js 1893 let foo 1894 if (true) 1895 function foo() {} 1896 ``` 1897 1898 * Keywords can now be used as export aliases with `export * as` statements: 1899 1900 ```js 1901 export * as class from 'path' 1902 ``` 1903 1904 * It is now a syntax error to use `break` or `continue` in invalid locations: 1905 1906 ```js 1907 function foo() { break } 1908 ``` 1909 1910 * Using `yield` as an identifier outside of a generator function is now allowed: 1911 1912 ```js 1913 var yield = null 1914 ``` 1915 1916 * It is now a syntax error to use `yield` or `await` inside a generator or `async` function if it contains an escape sequence: 1917 1918 ```js 1919 async function foo() { 1920 return \u0061wait; 1921 } 1922 ``` 1923 1924 * It is now a syntax error to use an `import()` expression with the `new` operator without parentheses: 1925 1926 ```js 1927 new import('path') 1928 ``` 1929 1930 * Using `let` as an identifier is now allowed: 1931 1932 ```js 1933 let = null 1934 ``` 1935 1936 * It is no longer a compile-time error to assign to an import when not bundling: 1937 1938 ```js 1939 import {foo} from 'path' 1940 foo = null 1941 ``` 1942 1943 Instead the behavior will be left up to the host environment at run-time, which should cause a run-time error. However, this will still be treated as a compile-time error when bundling because the scope-hoisting optimization that happens during bundling means the host may no longer cause run-time errors. 1944 1945 * You can now declare a variable named `arguments` inside a function without an error: 1946 1947 ```js 1948 function foo() { 1949 let arguments = null 1950 } 1951 ``` 1952 1953 * Comma expressions in the iterable position of for-of loops are now a syntax error: 1954 1955 ```js 1956 for (var a of b, c) { 1957 } 1958 ``` 1959 1960 * It is now a syntax error to use `||` or `&&` with `??` without parentheses 1961 1962 ```js 1963 a ?? b || c // Syntax error 1964 a ?? (b || c) // Allowed 1965 (a ?? b) || c // Allowed 1966 ``` 1967 1968 * It is now a syntax error to use `arguments` inside a `class` field initializer 1969 1970 ```js 1971 class Foo { 1972 foo = arguments 1973 } 1974 ``` 1975 1976 * It is now a syntax error to a strict mode reserved word to name a `class` 1977 1978 ```js 1979 class static {} 1980 ``` 1981 1982 ## 0.6.30 1983 1984 * Fix optional call of `super` property ([#362](https://github.com/evanw/esbuild/issues/362)) 1985 1986 This fixes a bug where lowering the code `super.foo?.()` was incorrectly transformed to this: 1987 1988 ```js 1989 var _a, _b; 1990 (_b = (_a = super).foo) == null ? void 0 : _b.call(_a); 1991 ``` 1992 1993 This is invalid code because a bare `super` keyword is not allowed. Now that code is transformed to this instead: 1994 1995 ```js 1996 var _a; 1997 (_a = super.foo) == null ? void 0 : _a.call(this); 1998 ``` 1999 2000 * Add a `--strict:optional-chaining` option 2001 2002 This affects the transform for the `?.` optional chaining operator. In loose mode (the default), `a?.b` is transformed to `a == null ? void 0 : a.b`. This works fine in all cases except when `a` is the special object `document.all`. In strict mode, `a?.b` is transformed to `a === null || a === void 0 ? void 0 : a.b` which works correctly with `document.all`. Enable `--strict:optional-chaining` if you need to use `document.all` with the `?.` operator. 2003 2004 ## 0.6.29 2005 2006 * Add a warning for comparison with `NaN` 2007 2008 This warning triggers for code such as `x === NaN`. Code that does this is almost certainly a bug because `NaN === NaN` is false in JavaScript. 2009 2010 * Add a warning for duplicate switch case clauses 2011 2012 This warning detects situations when multiple `case` clauses in the same `switch` statement match on the same expression. This almost certainly indicates a problem with the code. This warning protects against situations like this: 2013 2014 ```js 2015 switch (typeof x) { 2016 case 'object': 2017 // ... 2018 case 'function': 2019 // ... 2020 case 'boolean': 2021 // ... 2022 case 'object': 2023 // ... 2024 } 2025 ``` 2026 2027 * Allow getters and setters in ES5 ([#356](https://github.com/evanw/esbuild/issues/356)) 2028 2029 This was an oversight. I incorrectly thought getters and setters were added in ES6, not in ES5. This release allows getter and setter method syntax even when `--target=es5`. 2030 2031 * Fix a Windows-only regression with missing directory errors ([#359](https://github.com/evanw/esbuild/issues/359)) 2032 2033 Various Go file system APIs return `ENOTDIR` for missing file system entries on Windows instead of `ENOENT` like they do on other platforms. This interfered with code added in the previous release that makes unexpected file system errors no longer silent. `ENOTDIR` is usually an unexpected error because it's supposed to happen when the file system entry is present but just unexpectedly a file instead of a directory. This release changes `ENOTDIR` to `ENOENT` in certain cases so that these Windows-only errors are no longer treated as unexpected errors. 2034 2035 * Enforce object accessor argument counts 2036 2037 According to the JavaScript specification, getter methods must have zero arguments and setter methods must have exactly one argument. This release enforces these rules. 2038 2039 * Validate assignment targets 2040 2041 Code containing invalid assignments such as `1 = 2` will now be correctly rejected as a syntax error. Previously such code was passed through unmodified and the output file would contain a syntax error (i.e. "garbage in, garbage out"). 2042 2043 ## 0.6.28 2044 2045 * Avoid running out of file handles when ulimit is low ([#348](https://github.com/evanw/esbuild/issues/348)) 2046 2047 When esbuild uses aggressive concurrency, it can sometimes simultaneously use more file handles than allowed by the system. This can be a problem when the limit is low (e.g. using `ulimit -n 32`). In this release, esbuild now limits itself to using a maximum of 32 file operations simultaneously (in practice this may use up to 64 file handles since some file operations need two handles). This limit was chosen to be low enough to not cause issues with normal ulimit values but high enough to not impact benchmark times. 2048 2049 * Unexpected file system errors are no longer silent ([#348](https://github.com/evanw/esbuild/issues/348)) 2050 2051 All file system errors were previously treated the same; any error meant the file or directory was considered to not exist. This was problematic when the process ran out of available file handles because it meant esbuild could ignore files that do actually exist if file handles are exhausted. Then esbuild could potentially generate a different output instead of failing with an error. Now if esbuild gets into this situation, it should report unexpected file system errors and fail to build instead of continuing to build and potentially producing incorrect output. 2052 2053 * Install script tries `npm install` before a direct download ([#347](https://github.com/evanw/esbuild/issues/347)) 2054 2055 The `esbuild` package has a post-install script that downloads the native binary for the current platform over HTTP. Some people have configured their environments such that HTTP requests to npmjs.org will hang, and configured npm to use a proxy for HTTP requests instead. In this case, esbuild's install script will still work as long as `npm install` works because the HTTP request will eventually time out, at which point the install script will run `npm install` as a fallback. The timeout is of course undesirable. 2056 2057 This release changes the order of attempted download methods in the install script. Now `npm install` is tried first and directly downloading the file over HTTP will be tried as a fallback. This means installations will be slightly slower since npm is slow, but it should avoid the situation where the install script takes a long time because it's waiting for a HTTP timeout. This should still support the scenarios where there is a HTTP proxy configured, where there is a custom registry configured, and where the `npm` command isn't available. 2058 2059 ## 0.6.27 2060 2061 * Add parentheses when calling `require()` inside `new` ([#339](https://github.com/evanw/esbuild/issues/339)) 2062 2063 This release fixes an issue where `new (require('path')).ctor()` became `new require_path().ctor()` after bundling, which caused `require_path()` to be invoked as the constructor instead of `ctor()`. With this fix the code `new (require_path()).ctor()` is generated instead, which correctly invokes `ctor()` as the constructor. This was contributed by [@rtsao](https://github.com/rtsao). 2064 2065 ## 0.6.26 2066 2067 * Fix syntax error when minifying and bundling CommonJS to ES5 ([#335](https://github.com/evanw/esbuild/issues/335)) 2068 2069 With the flags `--minify --bundle --target=es5`, esbuild had a bug where the arrow function for the closure used to wrap CommonJS modules was not correctly printed as an ES5 function expression, causing a syntax error. This bug has been fixed. 2070 2071 ## 0.6.25 2072 2073 * Avoid the `\v` escape sequence in JSON strings 2074 2075 Source maps are JSON files, and must obey the [JSON specification](https://www.json.org/). The escape sequence `\v` (for the ASCII control character 11) is valid in JavaScript but not in JSON. Previously esbuild contained a bug where source maps for files containing this ASCII control character were invalid JSON. This release fixes the bug by printing this character as `\u000B` instead. 2076 2077 * Speedup for `esbuild-wasm` when using the command line 2078 2079 The [esbuild-wasm](https://www.npmjs.com/package/esbuild-wasm) package includes a WebAssembly command-line tool called `esbuild` which functions the same as the native command-line tool called `esbuild` in the [esbuild](https://www.npmjs.com/package/esbuild) package. The difference is that the WebAssembly implementation is around an order of magnitude slower than the native version. 2080 2081 This release changes the API used to instantiate the WebAssembly module from [WebAssembly.instantiate](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) to [WebAssembly.Module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/Module), which reduces end-to-end build time by around 1 second on my development laptop. The WebAssembly version is still much slower than the native version, but now it's a little faster than before. 2082 2083 * Optimize for the [@material-ui/icons](https://www.npmjs.com/package/@material-ui/icons) package 2084 2085 This package has a directory containing over 11,000 files. Certain optimizations in esbuild that worked fine for common cases severely impacted performance for this edge case. This release changes some aspects of path resolution caching to fix these problems. Build time for a certain benchmark involving this package improved from 1.01s for the previous release to 0.22s for this release. Other benchmark times appear to be unaffected. 2086 2087 ## 0.6.24 2088 2089 * Switch from base64 encoding to base32 encoding for file hashes 2090 2091 Certain output files contain hashes in their name both to prevent collisions and to improve caching. For example, an SVG file named `example.svg` that is loaded using the `file` loader might be copied to a file named `example.T3K5TRK4.svg` in the build directory. The hashes are based on the file's contents so they only change when the file content itself changes. 2092 2093 The hashes previously used [base64 encoding](https://en.wikipedia.org/wiki/Base64) but I recently realized that since certain file systems (e.g. Windows) are case-insensitive, this could lead to confusing situations where esbuild could theoretically generate two files with different case-sensitive names but with the same case-insensitive name. Hashes now use [base32 encoding](https://en.wikipedia.org/wiki/Base32) which only includes uppercase letters, not lowercase letters, which should avoid this confusing situation. 2094 2095 * Optimize character frequency for better gzip compression 2096 2097 The character sequence used to generate minified names is now the characters in the input files sorted descending by frequency. Previously it was just the valid identifier characters in alphabetic order. This means minified names are more likely to contain characters found elsewhere in the output file (e.g. in keywords and strings). This is a pretty small win but it was added because it's a consistent win, it's simple to implement, and it's very fast to compute. 2098 2099 * Minor syntax minification improvements 2100 2101 This release contains these additional rules for syntax minification: 2102 2103 * `a ? b : b` is minified to `a, b` 2104 * `a ? a : b` is minified to `a || b` 2105 * `a ? b : a` is minified to `a && b` 2106 * `a == void 0` is minified to `a == null` 2107 * `a && (b && c)` is minified to `a && b && c` (same for `||`) 2108 * `a ? c : (b, c)` is minified to `(a || b), c` 2109 * `a ? (b, c) : c` is minified to `(a && b), c` 2110 * `a ? b || c : c` is minified to `(a && b) || c` 2111 * `a ? c : b && c` is minified to `(a || b) && c` 2112 * `a ? b(c) : b(d)` is minified to `b(a ? c : d)` 2113 * `a ? true : false` is minified to `!!a` 2114 * `a != null ? a : b` is minified to `a ?? b` if it's supported in the target environment 2115 * `a ? (b ? c : d) : d` is minified to `(a && b) ? c : d` 2116 * `a ? b : (c ? b : d)` is minified to `(a || c) ? b : d` 2117 * `(function foo() {})` is minified to `(function() {})` 2118 * `typeof a === "string"` is minified to `typeof a == "string"` 2119 * `if (a) if (b) return c` is minified to `if (a && b) return c` 2120 * `while (a) if (!b) break;` is minified to `for (; a && b; ) ;` 2121 * `a === null || a === undefined` is minified to `a == null` 2122 2123 These improvements cause minified code to be slightly smaller. 2124 2125 ## 0.6.23 2126 2127 * Add an error message for a missing `--tsconfig` file ([#330](https://github.com/evanw/esbuild/issues/330)) 2128 2129 The `--tsconfig` flag that was added in version 0.6.1 didn't report an error if the provided file doesn't actually exist. This release makes doing this an error that will fail the build. 2130 2131 * Avoid generating the minified label name `if` ([#332](https://github.com/evanw/esbuild/issues/332)) 2132 2133 The recent minification changes in 0.6.20 introduced a regression where input files containing 333 or more label statements resulted in a label being assigned the minified name `if`, which is a JavaScript keyword. This is the first JavaScript keyword in the minified name sequence that esbuild uses for label names: `a b c ... aa ba ca ...`. The regression has been fixed and there is now test coverage for this case. 2134 2135 ## 0.6.22 2136 2137 * The bell character is now escaped 2138 2139 In most terminals, printing the bell character (ASCII code 7) will trigger a sound. The macOS terminal will also flash the screen if sound is muted. This is annoying, and can happen when dumping the output of esbuild to the terminal if the input contains a bell character. Now esbuild will always escape bell characters in the output to avoid this problem. 2140 2141 * CommonJS modules now export properties of prototype ([#326](https://github.com/evanw/esbuild/issues/326)) 2142 2143 This change is for compatibility with Webpack. You can now assign an object with a custom prototype to `module.exports` and esbuild will consider all enumerable properties on the prototype as exports. This behavior is necessary to correctly bundle the [paper.js](https://github.com/paperjs/paper.js) library, for example. 2144 2145 ## 0.6.21 2146 2147 * Upgrade from Go 1.14 to Go 1.15 2148 2149 This change isn't represented by a commit in the repo, but from now on I will be using Go 1.15 to build the distributed binaries instead of Go 1.14. The [release notes for Go 1.15](https://golang.org/doc/go1.15) mention improvements to binary size: 2150 2151 > Go 1.15 reduces typical binary sizes by around 5% compared to Go 1.14 by eliminating certain types of GC metadata and more aggressively eliminating unused type metadata. 2152 2153 Initial testing shows that upgrading Go reduces the esbuild binary size on macOS from 7.4mb to 5.3mb, which is a 30% smaller binary! I assume the binary size savings are similar for other platforms. Run-time performance on the esbuild benchmarks seems consistent with previous releases. 2154 2155 * Lower non-tag template literals to ES5 ([#297](https://github.com/evanw/esbuild/issues/297)) 2156 2157 You can now use non-tag template literals such as `` `abc` `` and `` `a${b}c` `` with `--target=es5` and esbuild will convert them to string addition such as `"abc"` and `"a" + b + "c"` instead of reporting an error. 2158 2159 * Newline normalization in template literals 2160 2161 This fixes a bug with esbuild that caused carriage-return characters to incorrectly end up in multi-line template literals if the source file used Windows-style line endings (i.e. `\r\n`). The ES6 language specification says that both carriage-return characters and Windows carriage-return line-feed sequences must be converted to line-feed characters instead. With this change, esbuild's parsing of multi-line template literals should no longer be platform-dependent. 2162 2163 * Fix minification bug with variable hoisting 2164 2165 Hoisted variables that are declared with `var` in a nested scope but hoisted to the top-level scope were incorrectly minified as a nested scope symbol instead of a top-level symbol, which could potentially cause a name collision. This bug has been fixed. 2166 2167 ## 0.6.20 2168 2169 * Symbols are now renamed separately per chunk ([#16](https://github.com/evanw/esbuild/issues/16)) 2170 2171 Previously, bundling with code splitting assigned minified names using a single frequency distribution calculated across all chunks. This meant that typical code changes in one chunk would often cause the contents of all chunks to change, which negated some of the benefits of the browser cache. 2172 2173 Now symbol renaming (both minified and not minified) is done separately per chunk. It was challenging to implement this without making esbuild a lot slower and causing it to use a lot more memory. Symbol renaming has been mostly rewritten to accomplish this and appears to actually usually use a little less memory and run a bit faster than before, even for code splitting builds that generate a lot of chunks. In addition, minified chunks are now slightly smaller because a given minified name can now be reused by multiple chunks. 2174 2175 ## 0.6.19 2176 2177 * Reduce memory usage for large builds by 30-40% ([#304](https://github.com/evanw/esbuild/issues/304)) 2178 2179 This release reduces memory usage. These specific percentages are likely only accurate for builds with a large number of files. Memory is reduced by ~30% for all builds by avoiding unnecessary per-file symbol maps, and is reduced by an additional ~10% for builds with source maps by preallocating some large arrays relating to source map output. 2180 2181 * Replace `.js` and `.jsx` with `.ts` or `.tsx` when resolving ([#118](https://github.com/evanw/esbuild/issues/118)) 2182 2183 This adds an import path resolution behavior that's specific to the TypeScript compiler where you can use an import path that ends in `.js` or `.jsx` when the correct import path actually ends in `.ts` or `.tsx` instead. See the discussion here for more historical context: https://github.com/microsoft/TypeScript/issues/4595. 2184 2185 ## 0.6.18 2186 2187 * Install script falls back to `npm install` ([#319](https://github.com/evanw/esbuild/issues/319)) 2188 2189 The `esbuild` package has a post-install script that downloads the esbuild binary. However, this will fail if `registry.npmjs.org` (or the configured custom npm registry) is inaccessible. 2190 2191 This release adds an additional fallback for when the download fails. It tries to use the `npm install` command to download the esbuild binary instead. This handles situations where users have either configured npm with a proxy or have a custom command in their path called `npm`. 2192 2193 ## 0.6.17 2194 2195 * Add a download cache to the install script 2196 2197 This speeds up repeated esbuild installs for the same version by only downloading the binary from npm the first time and then reusing it for subsequent installs. The binary files are cached in these locations, which are the same locations as the Electron install script: 2198 2199 * Windows: `%USERPROFILE%\AppData\Local\Cache\esbuild\bin` 2200 * macOS: `~/Library/Caches/esbuild/bin` 2201 * Other: `~/.cache/esbuild/bin` 2202 2203 The cache holds a maximum of 5 entries and purges least-recently-used entries above that limit. 2204 2205 * Omit `export default` of local type names ([#316](https://github.com/evanw/esbuild/issues/316)) 2206 2207 Normally the `export default` syntax takes a value expression to export. However, TypeScript has a special case for `export default <identifier>` where the identifier is allowed to be a type expression instead of a value expression. In that case, the type expression should not be emitted in the resulting bundle. This release improves support for this case by omitting the export when the identifier matches a local type name. 2208 2209 ## 0.6.16 2210 2211 * Colors for Windows console output 2212 2213 Console output on Windows now uses color instead of being monochrome. This should make log messages easier to read. 2214 2215 * Parenthesize destructuring assignment in arrow function expressions ([#313](https://github.com/evanw/esbuild/issues/313)) 2216 2217 This fixes a bug where `() => ({} = {})` was incorrectly printed as `() => ({}) = {}`, which is a syntax error. This case is now printed correctly. 2218 2219 ## 0.6.15 2220 2221 * Support symlinks with absolute paths in `node_modules` ([#310](https://github.com/evanw/esbuild/issues/310)) 2222 2223 Previously esbuild only supported symlinks with relative paths, not absolute paths. Adding support for absolute paths in symlinks fixes issues with esbuild and [pnpm](https://github.com/pnpm/pnpm) on Windows. 2224 2225 * Preserve leading comments inside `import()` expressions ([#309](https://github.com/evanw/esbuild/issues/309)) 2226 2227 This makes it possible to use esbuild as a faster TypeScript-to-JavaScript frontend for Webpack, which has special [magic comments](https://webpack.js.org/api/module-methods/#magic-comments) inside `import()` expressions that affect Webpack's behavior. 2228 2229 * Fix crash for source files beginning with `\r\n` when using source maps ([#311](https://github.com/evanw/esbuild/issues/311)) 2230 2231 The source map changes in version 0.6.13 introduced a regression that caused source files beginning with `\r\n` to crash esbuild when source map generation was enabled. This was not caught during testing both because not many source files begin with a newline and not many source files have Windows-style line endings in them. This regression has been fixed and Windows-style line endings now have test coverage. 2232 2233 ## 0.6.14 2234 2235 * Add support for parsing top-level await ([#253](https://github.com/evanw/esbuild/issues/253)) 2236 2237 It seems appropriate for esbuild to support top-level await syntax now that [node is supporting top-level await syntax by default](https://github.com/nodejs/node/issues/34551) (it's the first widely-used platform to do so). This syntax can now be parsed by esbuild and is always passed through untransformed. It's only allowed when the target is `esnext` because the proposal is still in stage 3. It also cannot be used when bundling. Adding support for top-level await to the bundler is complicated since it causes imports to be asynchronous, which has far-reaching implications. This change is mainly for people using esbuild as a library to transform TypeScript into JavaScript one file at a time. 2238 2239 ## 0.6.13 2240 2241 * Exclude non-JavaScript files from source maps ([#304](https://github.com/evanw/esbuild/issues/304)) 2242 2243 Previously all input files were eligible for source map generation, even binary files included using loaders such as `dataurl`. This was not intentional. Doing this doesn't serve a purpose and can massively bloat the resulting source maps. Now all files are excluded except those loaded by the `js`, `jsx`, `ts`, and `tsx` loaders. 2244 2245 * Fix incorrect source maps with code splitting ([#303](https://github.com/evanw/esbuild/issues/303)) 2246 2247 Source maps were completely incorrect when code splitting was enabled for chunk files that imported other chunk files. The source map offsets were not being adjusted past the automatically-generated cross-chunk import statements. This has been fixed. 2248 2249 * Change source map column offsets from bytes to UTF-16 code units 2250 2251 The [source map specification](https://sourcemaps.info/spec.html) leaves many things unspecified including what column numbers mean. Until now esbuild has been generating byte offsets for column numbers, but Mozilla's popular [source-map](https://github.com/mozilla/source-map) library appears to use UTF-16 code unit counts for column numbers instead. With this release, esbuild now also uses UTF-16 code units for column numbers in source maps. This should help esbuild's compatibility with other tools in the ecosystem. 2252 2253 * Fix a bug with partial source mappings 2254 2255 The source map specification makes it valid to have mappings that don't actually map to anything. These mappings were never generated by esbuild but they are sometimes present in source maps generated by other tools. There was a bug where the source map line number would be thrown off if one of these mappings was present at the end of a line. This bug has been fixed. 2256 2257 ## 0.6.12 2258 2259 * Fix bugs with cross-chunk assignment handling ([#302](https://github.com/evanw/esbuild/issues/302)) 2260 2261 The code splitting process may end up moving the declaration of a file-local variable into a separate chunk from an assignment to that variable. However, it's not possible to assign to a variable in another chunk because assigning to an import is not allowed in ES6. To avoid generating invalid code, esbuild runs an additional pass after code splitting to force all code involved in cross-chunk assignments into the same chunk. 2262 2263 The logic to do this is quite tricky. For example, moving code between chunks may introduce more cross-chunk assignments that also need to be handled. In this case the bug was caused by not handling complex cases with three or more levels of cross-chunk assignment dependency recursion. These cases now have test coverage and should be handled correctly. 2264 2265 ## 0.6.11 2266 2267 * Code splitting chunks now use content hashes ([#16](https://github.com/evanw/esbuild/issues/16)) 2268 2269 Code that is shared between multiple entry points is separated out into "chunk" files when code splitting is enabled. These files are named `chunk.HASH.js` where `HASH` is a string of characters derived from a hash (e.g. `chunk.iJkFSV6U.js`). 2270 2271 Previously the hash was computed from the paths of all entry points which needed that chunk. This was done because it was a simple way to ensure that each chunk was unique, since each chunk represents shared code from a unique set of entry points. But it meant that changing the contents of the chunk did not cause the chunk name to change. 2272 2273 Now the hash is computed from the contents of the chunk file instead. This better aligns esbuild with the behavior of other bundlers. If changing the contents of the file always causes the name to change, you can serve these files with a very large `max-age` so the browser knows to never re-request them from your server if they are already cached. 2274 2275 Note that the names of entry points _do not_ currently contain a hash, so this optimization does not apply to entry points. Do not serve entry point files with a very large `max-age` or the browser may not re-request them even when they are updated. Including a hash in the names of entry point files has not been done in this release because that would be a breaking change. This release is an intermediate step to a state where all output file names contain content hashes. 2276 2277 The reason why this hasn't been done before now is because this change makes chunk generation more complex. Generating the contents of a chunk involves generating import statements for the other chunks which that chunk depends on. However, if chunk names now include a content hash, chunk generation must wait until the dependency chunks have finished. This more complex behavior has now been implemented. 2278 2279 Care was taken to still parallelize as much as possible despite parts of the code having to block. Each input file in a chunk is still printed to a string fully in parallel. Waiting was only introduced in the chunk assembly stage where input file strings are joined together. In practice, this change doesn't appear to have slowed down esbuild by a noticeable amount. 2280 2281 * Fix an off-by-one error with source map generation ([#289](https://github.com/evanw/esbuild/issues/289)) 2282 2283 The nested source map support added in version 0.6.5 contained a bug. Input files that were included in the bundle but that didn't themselves contain any generated code caused the source index to shift by one, throwing off the source names of all files after it. This could happen with files consisting only of re-export statements (e.g. `export {name} from 'path'`). This bug has been fixed and this specific scenario now has test coverage. 2284 2285 ## 0.6.10 2286 2287 * Revert the binary operator chain change 2288 2289 It turns out this caused some behavior bugs in the generated code. 2290 2291 ## 0.6.9 2292 2293 * Performance optimizations for large file transforms 2294 2295 There are two main JavaScript APIs: `build()` which operates on the file system and `transform()` which operates on in-memory data. Previously transforming large files using the JavaScript `transform()` API could be significantly slower than just writing the in-memory string to the file system, calling `build()`, and reading the result back from the file system. This is based on performance tests done on macOS 10.15. 2296 2297 Now esbuild will go through the file system when transforming large files (currently >1mb). This approach is only faster for large files, and can be significantly slower for small files, so small files still keep everything in memory. 2298 2299 * Avoid stack overflow for binary operator chains 2300 2301 Syntax trees with millions of sequential binary operators nested inside each other can cause the parser to stack overflow because it uses a recursive visitor pattern, so each binary operator added an entry to the call stack. Now code like this no longer triggers a stack overflow because the visitor uses the heap instead of the stack in this case. This is unlikely to matter in real-world code but can show up in certain artificial test cases, especially when `--minify-syntax` is enabled. 2302 2303 * Resolve implicitly-named `tsconfig.json` base files ([#279](https://github.com/evanw/esbuild/issues/279)) 2304 2305 The official TypeScript compiler lets you specify a package path as the `extends` property of a `tsconfig.json` file. The base file is then searched for in the relevant `node_modules` directory. Previously the package path had to end with the name of the base file. Now you can additionally omit the name of the base file if the file name is `tsconfig.json`. This more closely matches the behavior of the official TypeScript compiler. 2306 2307 * Support for 32-bit Windows systems ([#285](https://github.com/evanw/esbuild/issues/285)) 2308 2309 You can now install the esbuild npm package on 32-bit Windows systems. 2310 2311 ## 0.6.8 2312 2313 * Attempt to support the taobao.org registry ([#291](https://github.com/evanw/esbuild/issues/291)) 2314 2315 This release attempts to add support for the registry at https://registry.npm.taobao.org, which uses a different URL structure than the official npm registry. Also, the install script will now fall back to the official npm registry if installing with the configured custom registry fails. 2316 2317 ## 0.6.7 2318 2319 * Custom registry can now have a path ([#286](https://github.com/evanw/esbuild/issues/286)) 2320 2321 This adds support for custom registries hosted at a path other than `/`. Previously the registry had to be hosted at the domain level, like npm itself. 2322 2323 * Nested source maps use relative paths ([#289](https://github.com/evanw/esbuild/issues/289)) 2324 2325 The original paths in nested source maps are now modified to be relative to the directory containing the source map. This means source maps from packages inside `node_modules` will stay inside `node_modules` in browser developer tools instead of appearing at the root of the virtual file system where they might collide with the original paths of files in other packages. 2326 2327 * Support for 32-bit Linux systems ([#285](https://github.com/evanw/esbuild/issues/285)) 2328 2329 You can now install the esbuild npm package on 32-bit Linux systems. 2330 2331 ## 0.6.6 2332 2333 * Fix minification bug with `this` values for function calls ([#282](https://github.com/evanw/esbuild/issues/282)) 2334 2335 Previously `(0, this.fn)()` was incorrectly minified to `this.fn()`, which changes the value of `this` used for the function call. Now syntax like this is preserved during minification. 2336 2337 * Install script now respects the npm registry setting ([#286](https://github.com/evanw/esbuild/issues/286)) 2338 2339 If you have configured npm to use a custom registry using `npm config set registry <url>` or by installing esbuild using `npm install --registry=<url> ...`, this custom registry URL should now be respected by the esbuild install script. 2340 2341 Specifically, the install script now uses the URL from the `npm_config_registry` environment variable if present instead of the default registry URL `https://registry.npmjs.org/`. Note that the URL must have both a protocol and a host name. 2342 2343 * Fixed ordering between `node_modules` and a force-overridden `tsconfig.json` ([#278](https://github.com/evanw/esbuild/issues/278)) 2344 2345 When the `tsconfig.json` settings have been force-overridden using the new `--tsconfig` flag, the path resolution behavior behaved subtly differently than if esbuild naturally discovers the `tsconfig.json` file without the flag. The difference caused package paths present in a `node_modules` directory to incorrectly take precedence over custom path aliases configured in `tsconfig.json`. The ordering has been corrected such that custom path aliases always take place over `node_modules`. 2346 2347 * Add the `--out-extension` flag for custom output extensions ([#281](https://github.com/evanw/esbuild/issues/281)) 2348 2349 Previously esbuild could only output files ending in `.js`. Now you can override this to another extension by passing something like `--out-extension:.js=.mjs`. This allows generating output files with the node-specific `.cjs` and `.mjs` extensions without having to use a separate command to rename them afterwards. 2350 2351 ## 0.6.5 2352 2353 * Fix IIFE wrapper for ES5 2354 2355 The wrapper for immediately-invoked function expressions is hard-coded to an arrow function and was not updated when the ES5 target was added. This meant that bundling ES5 code would generate a bundle what wasn't ES5-compatible. Doing this now uses a function expression instead. 2356 2357 * Add support for nested source maps ([#211](https://github.com/evanw/esbuild/issues/211)) 2358 2359 Source map comments of the form `//# sourceMappingURL=...` inside input files are now respected. This means you can bundle files with source maps and esbuild will generate a source map that maps all the way back to the original files instead of to the intermediate file with the source map. 2360 2361 ## 0.6.4 2362 2363 * Allow extending `tsconfig.json` paths inside packages ([#269](https://github.com/evanw/esbuild/issues/269)) 2364 2365 Previously the `extends` field in `tsconfig.json` only worked with relative paths (paths starting with `./` or `../`). Now this field can also take a package path, which will be resolved by looking for the package in the `node_modules` directory. 2366 2367 * Install script now avoids the `npm` command ([#274](https://github.com/evanw/esbuild/issues/274)) 2368 2369 The install script now downloads the binary directly from npmjs.org instead of using the `npm` command to install the package. This should be more compatible with unusual node environments (e.g. having multiple old copies of npm installed). 2370 2371 * Fix a code splitting bug with re-exported symbols ([#273](https://github.com/evanw/esbuild/issues/273)) 2372 2373 Re-exporting a symbol in an entry point didn't correctly track the cross-chunk dependency, which caused the output file to be missing a required import. This bug has been fixed. 2374 2375 * Fix code splitting if a dynamic entry point is doubled as a normal entry point ([#272](https://github.com/evanw/esbuild/issues/272)) 2376 2377 Using a dynamic `import()` expression automatically adds the imported path as an entry point. However, manually adding the imported path to the bundler entry point list resulted in a build failure. This case is now handled. 2378 2379 * Fix dynamic imports from a parent directory ([#264](https://github.com/evanw/esbuild/issues/264)) 2380 2381 The nested output directory feature interacted badly with the code splitting feature when an entry point contained a dynamic `import()` to a file from a directory that was a parent directory to all entry points. This caused esbuild to generate output paths starting with `../` which stepped outside of the output directory. 2382 2383 The directory structure of the input files is mirrored in the output directory relative to the [lowest common ancestor](https://en.wikipedia.org/wiki/Lowest_common_ancestor) among all entry point paths. However, code splitting introduces a new entry point for each dynamic import. These additional entry points are not in the original entry point list so they were ignored by the lowest common ancestor algorithm. The fix is to make sure all entry points are included, user-specified and dynamic. 2384 2385 ## 0.6.3 2386 2387 * Fix `/* @__PURE__ */` IIFEs at start of statement ([#258](https://github.com/evanw/esbuild/issues/258)) 2388 2389 The introduction of support for `/* @__PURE__ */` comments in an earlier release introduced a bug where parentheses were no longer inserted if a statement started with a function expression that was immediately invoked. This bug has been fixed and parentheses are now inserted correctly. 2390 2391 * Add support for `@jsx` and `@jsxFrag` comments ([#138](https://github.com/evanw/esbuild/issues/138)) 2392 2393 You can now override the JSX factory and fragment values on a per-file basis using comments: 2394 2395 ```jsx 2396 // @jsx h 2397 // @jsxFrag Fragment 2398 import {h, Fragment} from 'preact' 2399 console.log(<><a/></>) 2400 ``` 2401 2402 This now generates the following code: 2403 2404 ```js 2405 import {h, Fragment} from "preact"; 2406 console.log(h(Fragment, null, h("a", null))); 2407 ``` 2408 2409 * Add the `Write` option to the Go API 2410 2411 This brings the Go API to parity with the JavaScript API, and makes certain uses of the `api.Build()` call simpler. You can now specify `Write: true` to have the output files written to the file system during the build instead of having to do that yourself. 2412 2413 ## 0.6.2 2414 2415 * Fix code splitting bug with re-export cycles ([#251](https://github.com/evanw/esbuild/issues/251)) 2416 2417 Two files that both re-export each other could cause invalid code to be generated when code splitting is enabled. The specific failure was an export statement without a matching import statement from the shared code chunk. This bug has been fixed. 2418 2419 Semantically a `export * from 'path'` statement should behave like a `export {name} from 'path'` statement with the export list determined automatically. And likewise `export {name} from 'path'` should behave like `import {name} from 'path'; export {name}`. 2420 2421 This issue was caused by the re-exported symbols not registering themselves as if they were imported with an import statement. That caused code splitting to fail to generate an import statement when the definition of the symbol ended up in a different chunk than the use of the symbol. 2422 2423 * Fix code splitting bug with missing generated imports 2424 2425 An ES6 module that doesn't import or export anything but that still uses ES6 module syntax (e.g. `import.meta`) interacted badly with some optimizations and caused invalid code to be generated. This generated an import statement without a matching export statement. The bug has been fixed. 2426 2427 To improve tree shaking, esbuild automatically converts `import * as ns from 'path'; use(ns.prop)` into `import {prop} from 'path'; use(prop)` at parse time. The parser doesn't yet know anything about `path` because parsing happens in parallel, so this transformation is always performed. 2428 2429 Later on `path` is determined to be an ES6 module with no exports. This means that there is no symbol to bind `prop` to. Since it was originally a property access on what is now known to be an empty exports object, its value is guaranteed to be undefined. It's no longer a property access so esbuild inlines the undefined value at all uses by replacing `prop` with `void 0`. 2430 2431 However, code splitting wasn't aware of this and still thought imports needed to be generated for uses of `prop`, even though it doesn't actually exist. That caused invalid and unnecessary import statements to be generated. Now code splitting is aware of this undefined substitution behavior and ignores these symbol uses. 2432 2433 ## 0.6.1 2434 2435 * Allow bundling with stdin as input ([#212](https://github.com/evanw/esbuild/issues/212)) 2436 2437 You can now use `--bundle` without providing any input files and the input will come from stdin instead. Use `--sourcefile=...` to set the name of the input file for error messages and source maps. Dependencies of the input file will be resolved relative to the current working directory. 2438 2439 ``` 2440 # These two commands are now basically equivalent 2441 esbuild --bundle example.js 2442 esbuild --bundle < example.js --sourcefile=example.js 2443 ``` 2444 2445 This option has also been added to the JavaScript and Go APIs. If needed, you can customize the resolve directory with the `resolveDir` option: 2446 2447 ```js 2448 const {outputFiles: [stdout]} = await build({ 2449 stdin: { 2450 contents: ` 2451 import {version} from './package.json' 2452 console.log(version as string) 2453 `, 2454 sourcefile: 'example.ts', 2455 resolveDir: __dirname, 2456 loader: 'ts', 2457 }, 2458 bundle: true, 2459 write: false, 2460 }) 2461 console.log(stdout) 2462 ``` 2463 2464 * Implement `extends` for `tsconfig.json` ([#233](https://github.com/evanw/esbuild/issues/233)) 2465 2466 A `tsconfig.json` file can inherit configurations from another file using the `extends` property. Before this release, esbuild didn't support this property and any inherited settings were missing. Now esbuild should include these inherited settings. 2467 2468 * Allow manually overriding `tsconfig.json` ([#226](https://github.com/evanw/esbuild/issues/226)) 2469 2470 Normally esbuild finds the appropriate `tsconfig.json` file by walking up the directory tree. This release adds the `--tsconfig=...` flag which lets you disable this feature and force esbuild to use the provided configuration file instead. This corresponds to the TypeScript compiler's `--project` flag. 2471 2472 * Remove gaps in source maps within a file ([#249](https://github.com/evanw/esbuild/issues/249)) 2473 2474 The widely-used [source-map](https://github.com/mozilla/source-map) library for parsing source maps [has a bug](https://github.com/mozilla/source-map/issues/261) where it doesn't return mappings from previous lines. This can cause queries within generated code to fail even though there are valid mappings on both sides of the query. 2475 2476 To work around this issue with the source-map library, esbuild now generates a mapping for every line of code that is generated from an input file. This means that queries with the source-map library should be more robust. For example, you should now be able to query within a multi-line template literal and not have the query fail. 2477 2478 Note that some lines of code generated during bundling will still not have source mappings. Examples include run-time library code and cross-chunk imports and exports. 2479 2480 ## 0.6.0 2481 2482 * Output directory may now contain nested directories ([#224](https://github.com/evanw/esbuild/issues/224)) 2483 2484 Note: This is a breaking change if you use multiple entry points from different directories. Output paths may change with this upgrade. 2485 2486 Previously esbuild would fail to bundle multiple entry points with the same name because all output files were written to the same directory. This can happen if your entry points are in different nested directories like this: 2487 2488 ``` 2489 src/ 2490 ├─ a/ 2491 │ └─ page.js 2492 └─ b/ 2493 └─ page.js 2494 ``` 2495 2496 With this release, esbuild will now generate nested directories in the output directory that mirror the directory structure of the original entry points. This avoids collisions because the output files will now be in separate directories. The directory structure is mirrored relative to the [lowest common ancestor](https://en.wikipedia.org/wiki/Lowest_common_ancestor) among all entry point paths. This is the same behavior as [Parcel](https://github.com/parcel-bundler/parcel) and the TypeScript compiler. 2497 2498 * Silence errors about missing dependencies inside try/catch blocks ([#247](https://github.com/evanw/esbuild/issues/247)) 2499 2500 This release makes it easier to use esbuild with libraries such as [debug](npmjs.com/package/debug) which contain a use of `require()` inside a `try`/`catch` statement for a module that isn't listed in its dependencies. Normally you need to mark the library as `--external` to silence this error. However, calling `require()` and catching errors is a common pattern for conditionally importing an unknown module, so now esbuild automatically treats the missing module as external in these cases. 2501 2502 * TypeScript type definitions for the browser API 2503 2504 The node-based JavaScript API already ships with TypeScript type checking for the `esbuild` and `esbuild-wasm` packages. However, up until now the browser-based JavaScript API located in `esbuild-wasm/lib/browser` did not have type definitions. This release adds type definitions so you can now import `esbuild-wasm/lib/browser` in TypeScript and get type checking. 2505 2506 * Add chunk imports to metadata file ([#225](https://github.com/evanw/esbuild/issues/225)) 2507 2508 With code splitting, it's sometimes useful to list out the chunks that will be needed by a given entry point. For example, you may want to use that list to insert one `<link rel="modulepreload">` tag for each chunk in your page header. This information is now present in the JSON metadata file that's generated with the `--metafile` flag. Each object in the `outputs` map now has an `imports` array, and each import has a `path`. 2509 2510 ## 0.5.26 2511 2512 * Allow disabling non-existent modules with the `browser` package.json field ([#238](https://github.com/evanw/esbuild/issues/238)) 2513 2514 The [browser field](https://github.com/defunctzombie/package-browser-field-spec) in package.json allows you to disable a module (i.e. force it to become empty) by adding an override that points to `false`. Previously esbuild still required it to have an existing absolute path on the file system so that the disabled module could have a consistent identity. Now this is no longer required, so you can disable modules that don't exist on the file system. For example, you can now use this feature to disable the `fs` module. 2515 2516 * Fix a bug with syntax transformation and `super()` calls ([#242](https://github.com/evanw/esbuild/issues/242)) 2517 2518 In certain situations, esbuild accidentally transformed a class constructor such that a call to `super()` that came first in the original code no longer came first in the generated code. This code generation bug has now been fixed. Calls to `super()` that come first are should now stay that way. 2519 2520 ## 0.5.25 2521 2522 * Performance improvment for repeated API calls 2523 2524 Previously every build or transform API call required parsing a new copy of the [esbuild JavaScript runtime code](internal/runtime/runtime.go). This added a constant overhead for every operation. Now the parsing of the runtime code is cached across API calls. The effect on performance depends on the size of the files you're transforming. Transform API calls appear to be >2x faster for small files, around ~10% faster for normal-sized files, and insignificant for large files. 2525 2526 * Add a binary loader 2527 2528 You can now assign the `binary` loader to a file extension to load all files of that type into a Uint8Array. The data is encoded as a base64 string and decoded into a Uint8Array at run time. The decoder defaults to a custom platform-independent implementation (faster than `atob`) but it switches to using the `Buffer` API with `--platform=node`. 2529 2530 * Add fine-grained `--target` environments ([#231](https://github.com/evanw/esbuild/issues/231)) 2531 2532 You can now configure individual JavaScript environments as targets. The `--target` flag now takes a comma-separated list of values like this: `--target=chrome58,firefox57,safari11,edge16`. Compatibility data was mainly sourced from [this widely-used compatibility table](https://kangax.github.io/compat-table/es2016plus/). 2533 2534 There is also now an additional `es5` target. Since no transforms to ES5 are implemented yet, its purpose is mainly to prevent ES6 syntax from accidentally being compiled. This target also prevents esbuild from doing some ES6-specific optimizations that would unintentionally change ES5 code into ES6 code. 2535 2536 ## 0.5.24 2537 2538 * Smaller code for loaders that generate expressions 2539 2540 Loaders that generate expressions (`json`, `text`, `base64`, `file`, and `dataurl`) export them using an assignment to `module.exports`. However, that forces the creation of a CommonJS module which adds unnecessary extra code. Now if the file for that loader is only imported using ES6 import statements instead of `require()`, the expression is exported using an `export default` statement instead. This generates smaller code. The bundler still falls back to the old `module.exports` behavior if the file is imported using `require()` instead of an ES6 import statement. 2541 2542 Example input file: 2543 2544 ```js 2545 import txt from './example.txt' 2546 console.log(txt) 2547 ``` 2548 2549 Old bundling behavior: 2550 2551 ```js 2552 // ...code for __commonJS() and __toModule() omitted... 2553 2554 // example.txt 2555 var require_example = __commonJS((exports, module) => { 2556 module.exports = "This is a text file."; 2557 }); 2558 2559 // example.ts 2560 const example = __toModule(require_example()); 2561 console.log(example.default); 2562 ``` 2563 2564 New bundling behavior: 2565 2566 ```js 2567 // example.txt 2568 var example_default = "This is a text file."; 2569 2570 // example.ts 2571 console.log(example_default); 2572 ``` 2573 2574 In addition, top-level properties of imported JSON files are now converted into individual ES6 exports for better tree shaking. For example, that means you can now import the `version` property from your `package.json` file and the entire JSON file will be removed from the bundle: 2575 2576 ```js 2577 import {version} from './package.json' 2578 console.log(version) 2579 ``` 2580 2581 The example above will now generate code that looks like this: 2582 2583 ```js 2584 // package.json 2585 var version = "1.0.0"; 2586 2587 // example.ts 2588 console.log(version); 2589 ``` 2590 2591 ## 0.5.23 2592 2593 * Fix `export declare` inside `namespace` in TypeScript ([#227](https://github.com/evanw/esbuild/issues/227)) 2594 2595 The TypeScript parser assumed that ambient declarations (the `declare` keyword) just declared types and did not affect the output. This was an incorrect assumption for exported declarations of local variables inside namespaces. The assignment to `foo` in the example below must be rewritten to an assignment to `ns.foo`: 2596 2597 ```ts 2598 namespace ns { 2599 export declare let foo: number 2600 foo = 123 2601 } 2602 ``` 2603 2604 This should now work correctly. 2605 2606 * Preserve certain statement-level comments ([#221](https://github.com/evanw/esbuild/issues/221)) 2607 2608 Statement-level comments starting with `//!` or `/*!` or containing `@preserve` or `@license` are now preserved in the output. This matches the behavior of other JavaScript tools such as [Terser](https://github.com/terser/terser). 2609 2610 * Higher memory limit for synchronous JavaScript APIs ([#228](https://github.com/evanw/esbuild/issues/228)) 2611 2612 Apparently the synchronous APIs in node's child process module that esbuild relies on will fail with `ENOBUFS` if the output is larger than a certain size. This caused issues with the `write: false` feature from the previous release. The memory limit has been raised to 16mb which should hopefully avoid these crashes. If that limit is still too low, it can be overridden with the `ESBUILD_MAX_BUFFER` environment variable. 2613 2614 ## 0.5.22 2615 2616 * JavaScript build API can now avoid writing to the file system ([#139](https://github.com/evanw/esbuild/issues/139) and [#220](https://github.com/evanw/esbuild/issues/220)) 2617 2618 You can now pass `write: false` to the JavaScript build API to avoid writing to the file system. Instead, the returned object will have the `outputFiles` property with an array of output files, each of which has a string `path` property and a Uint8Array `contents` property. This brings the JavaScript API to parity with the Go API, which already had this feature. 2619 2620 * Support `/* @__PURE__ */` annotations for tree shaking 2621 2622 You can now annotate call expressions and new expressions with a `/* @__PURE__ */` comment, which tells esbuild that the function call is allowed to be removed if the result is not used. This is a convention from other tools (e.g. UglifyJS and Rollup). 2623 2624 For example, the code below will now be completely removed during bundling if the `fib` variable is never used. The initializer is a function call and esbuild cannot determine that it has no side effects, but the annotation forces esbuild to consider it removable anyway: 2625 2626 ```js 2627 let fib = /* @__PURE__ */ (() => { 2628 let cache = {} 2629 return function f(n) { 2630 return cache[n] || (cache[n] = 2631 n <= 2 ? 1 : f(n - 1) + f(n - 2)); 2632 } 2633 })() 2634 ``` 2635 2636 * Add `--pure:name` to annotate calls to globals ([#28](https://github.com/evanw/esbuild/issues/28)) 2637 2638 This flag makes calls to the named function behave as if that call was prefixed by `/* @__PURE__ */`. For example, `--pure:console.log` means calls to `console.log()` will behave as if they were calls to `/* @__PURE__ */ console.log()` instead. This means when `--minify` is active, the calls will be removed as long as the return value is unused (any function arguments with side effects will be kept, however). 2639 2640 * Add basic tree shaking of JSX elements 2641 2642 Automatically-generated calls to the JSX factory function (usually `React.createElement`) are now marked as `/* @__PURE__ */`. This means the construction of a JSX element is now not considered to have side effects. For example, the code below will be completely removed during bundling if the `element` variable is never used: 2643 2644 ```jsx 2645 let element = <div>an unused element</div> 2646 ``` 2647 2648 * Fixed a concurrency issue with the JavaScript API 2649 2650 Before this release, multiple concurrent JavaScript API calls that used different values for the `define` option could end up using the value from another API call. This bug was due to inverted boolean logic in code that was intended to cache the define map only when there were no user-specified defines. The issue has been fixed. 2651 2652 ## 0.5.21 2653 2654 * Binaries for FreeBSD ([#217](https://github.com/evanw/esbuild/pull/217)) 2655 2656 There are now esbuild binaries for FreeBSD, both for AMD64 and ARM64. This was contributed by [@kikuchan](https://github.com/kikuchan). 2657 2658 * Remove nested `node_modules` directory 2659 2660 The install script for the `esbuild` npm package invokes `npm` recursively to install the binary for the current platform. However, the left over nested `node_modules` directory could potentially cause problems with tools that scan for nested `node_modules` directories. Now the install script no longer leaves a nested `node_modules` directory around after finishing. 2661 2662 ## 0.5.20 2663 2664 * Allow multiple `.` characters in loader extensions ([#215](https://github.com/evanw/esbuild/issues/215)) 2665 2666 You are now able to configure two loaders such that one is the suffix of the other. For example, you can now configure both `--loader:.txt=text` and `--loader:.base64.txt=base64`. The loader with the longer matching suffix will be used. 2667 2668 * Add support for scoped external packages ([#214](https://github.com/evanw/esbuild/issues/214)) 2669 2670 You can now mark scoped packages as external. For example, `--external:@babel/core` marks the package `@babel/core` as external. This was contributed by [@floydspace](https://github.com/floydspace). 2671 2672 * Add support for external paths ([#127](https://github.com/evanw/esbuild/issues/127) and [#191](https://github.com/evanw/esbuild/issues/191)) 2673 2674 Previously the `--external:M` flag only worked if `M` was a package name. For example, you can mark the `fs` package as external with `--external:fs`. 2675 2676 With this release, you can now also mark file paths as external using the same syntax. For example, `--external:./index.js` marks the file `index.js` in the current working directory as external. The path to the external module used in the output file will be relative to the output directory. 2677 2678 ## 0.5.19 2679 2680 * Fix bug with TypeScript `typeof` operator ([#213](https://github.com/evanw/esbuild/issues/213)) 2681 2682 The TypeScript parser in esbuild incorrectly treated `readonly` in `typeof readonly` as a type operator instead of an identifier, which meant that it expected a type expression to follow the `readonly` identifier. Type expressions containing `typeof readonly` are now parsed correctly. 2683 2684 ## 0.5.18 2685 2686 * Fix bug with code splitting and side effects 2687 2688 This release fixes a bug with experimental code splitting. Chunks with side effects but without any exports were not imported by the entry points that depended on them, which meant that their side effects accidentally did not occur. The fix ensures that all entry points import all relevant chunks regardless of whether or not the chunks have exports, so their side effects should never be omitted. 2689 2690 ## 0.5.17 2691 2692 * Pass through `import.meta` syntax ([#208](https://github.com/evanw/esbuild/issues/208)) 2693 2694 The `import.meta` syntax is a way for code in an ES6 module to access metadata about itself. For example, `import.meta.url` in the browser is the URL of the current module. 2695 2696 It's a new feature that doesn't work in older browsers, so esbuild converts it to a module-local variable to avoid generating code with a syntax error. However, this is only necessary when targeting older browsers or if the output format doesn't support `import.meta`. 2697 2698 The `import.meta` syntax is now passed through unmodified when the target is `es2020` or newer and the output format is `esm`. This lets you use features such as `import.meta.url` in those situations. 2699 2700 ## 0.5.16 2701 2702 * Experimental code splitting with `--splitting` ([#16](https://github.com/evanw/esbuild/issues/16)) 2703 2704 This release includes experimental support for code splitting. Enable it with the `--splitting` flag. This currently only works with the `esm` output format. Support for the `cjs` and `iife` formats will come later. It's being released early so people can try it out and provide feedback. 2705 2706 When enabled, code splitting does two things: 2707 2708 * An asynchronous `import('path')` expression will create another chunk that will only be loaded when that expression is evaluated. This is intended to be used for lazily loading additional code. All additional chunks will be written to the directory configured with `outdir`. 2709 2710 Note that when code splitting is disabled (i.e. the default behavior), an `import('path')` expression behaves similar to `Promise.resolve(require('path'))` and still bundles the imported file into the entry point bundle. No additional chunks are generated in this case. 2711 2712 * Multiple entry points will cause additional chunks to be created for code that is shared between entry points. Chunks are generated automatically based on simple principles: code should only ever be in one chunk (i.e. no duplication) and no unnecessary code should be loaded (i.e. chunk boundaries are minimal). 2713 2714 The way this works is by traversing through the module dependency graph and marking which top-level statements are reachable from which entry points. The set of entry points for a given top-level statement determines which chunk that statement is in. 2715 2716 This is an advanced form of code splitting where even a single file may end up being split into different chunks. This is not something most other bundlers can do at the moment. 2717 2718 Note that using code splitting with many entry points may generate many chunks for shared code reachable from different combinations of entry points. This should work fine and should still be efficient with HTTP/2. If you want to only let certain entry points share code, you can run esbuild multiple times for different groups of entry points. 2719 2720 Please try it out and report any issues on [#16](https://github.com/evanw/esbuild/issues/16). 2721 2722 ## 0.5.15 2723 2724 * Remove some unnecessary helper functions ([#206](https://github.com/evanw/esbuild/issues/206)) 2725 2726 Certain unnecessary helper functions were sometimes generated when the output format was `esm`. These helper functions should now only be generated when necessary. 2727 2728 * Optimize CommonJS-to-ES6 module conversion 2729 2730 CommonJS modules that exported raw strings were unnecessarily slow when imported using an ES6 import statement. This scenario should now be much faster. 2731 2732 The CommonJS-to-ES6 module conversion in esbuild copies properties off the object one-by-one onto a new object. This is the same approach that the TypeScript compiler uses. However, strings have numeric properties 0 to N-1 where N is the length of the string. Copying all of these numeric properties can take a significantly long time for long strings and is almost certainly unhelpful. Now esbuild's CommonJS-to-ES6 module conversion only copies properties if the export is an object. 2733 2734 * Support JSX fields in `tsconfig.json` 2735 2736 This release adds support for the `jsxFactory` and `jsxFragmentFactory` fields in `tsconfig.json`. Now you do not have to configure JSX again for esbuild if you have already configured it for TypeScript. The `jsxFragmentFactory` field is a [new feature in the upcoming TypeScript 4.0 release](https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/#custom-jsx-factories). 2737 2738 ## 0.5.14 2739 2740 * Prevent assignment to ES6 imports ([#202](https://github.com/evanw/esbuild/issues/202)) 2741 2742 ES6 imports are live bindings to other values, sort of like a getter-only property on an object. An assignment to an import identifier should cause a `TypeError` at run time according to the specification. However, when bundling esbuild performs the "scope hoisting" optimization and merges all modules into a single scope. Imports inside the bundle refer to the imported identifiers without any indirection and an assignment will not throw a `TypeError` at run time. 2743 2744 This release turns assignments to imports into compile-time errors to reject invalid code instead of allowing it to cause this non-conforming behavior. Handling this at compile-time is consistent with other tools such as TypeScript and Rollup. 2745 2746 * Exclude external child paths from the bundle ([#186](https://github.com/evanw/esbuild/pull/186)) 2747 2748 Marking a module as external via `--external:foo` means any imports for the module `foo` will be preserved in the output instead of being traversed by the bundler. This is helpful if the module contains problematic code such as a native node module that can't be bundled. 2749 2750 However, code often uses child paths to import a file within a module directly such as `import "foo/bar"`. These paths accidentally bypassed the external module check. The fix means all paths under an external module are now also considered external. This was contributed by [@floydspace](https://github.com/floydspace). 2751 2752 ## 0.5.13 2753 2754 * Add support for TypeScript labelled tuples 2755 2756 This is a new TypeScript feature to be released in TypeScript 4. Tuple types can now have labels: 2757 2758 ```ts 2759 let foo: [number, number] // Without labels 2760 let bar: [min: number, max: number] // With labels 2761 ``` 2762 2763 These labels are ignored by the TypeScript compiler and are only there to improve readability. You can read more here: https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/. 2764 2765 ## 0.5.12 2766 2767 * Fix a JSX whitespace bug ([#195](https://github.com/evanw/esbuild/issues/195)) 2768 2769 Whitespace behavior in JSX has unfortunately been [left out of the JSX specification](https://github.com/facebook/jsx/issues/6), so it's up to each implementation to determine how to handle whitespace characters. Most of the JSX parsers in the ecosystem have converged on similar behavior. When they differ, esbuild follows the behavior of the TypeScript JSX parser. 2770 2771 This release fixes a bug where esbuild's JSX parser behaved differently than TypeScript. Certain whitespace characters between JSX elements were incorrectly removed. For example, the space in `<a><b/> <c/></a>` must be preserved to match the TypeScript JSX parser. These cases now have test coverage. 2772 2773 ## 0.5.11 2774 2775 * Fix a JavaScript API crash on node 10.x 2776 2777 The current LTS version of node is 12.x, but some people are still running 10.x and want to use esbuild. Before this fix, attempting to use the esbuild JavaScript API with node 10.x would crash with `ReferenceError: TextEncoder is not defined`. The JavaScript API has been changed to not require `TextEncoder` and now works fine with node 10.x. 2778 2779 ## 0.5.10 2780 2781 * Transform object rest properties 2782 2783 This release transforms object rest property bindings such as `let {...x} = y` when the language target is set to `--target=es2017` or earlier. 2784 2785 If you're using Babel to transform your source code to ES6 for older browsers, this probably means esbuild's JavaScript API could now be a suitable replacement for Babel in your case. The only remaining features that esbuild can't yet transform to ES6 are a few very rarely used features that don't matter for the vast majority of real-world code (`for async` loops and `async` generators). 2786 2787 ## 0.5.9 2788 2789 * Add the `--strict:nullish-coalescing` option 2790 2791 This affects the transform for the `??` nullish coalescing operator. In loose mode (the default), `a ?? b` is transformed to `a != null ? a : b`. This works fine in all cases except when `a` is the special object `document.all`. In strict mode, `a ?? b` is transformed to `a !== null && a !== void 0 ? a : b` which works correctly with `document.all`. Enable `--strict:nullish-coalescing` if you need to use `document.all` with the `??` operator. 2792 2793 * Add the `--strict:class-fields` option 2794 2795 This affects the transform for instance and static class fields. In loose mode (the default), class field initialization is transformed to a normal assignment. This is what the TypeScript compiler does by default. However, it doesn't follow the JavaScript specification exactly (e.g. it may call setter methods). Either enable `--strict:class-fields` or add `useDefineForClassFields` to your `tsconfig.json` file if you need accurate class field initialization. 2796 2797 Note that you can also just use `--strict` to enable strictness for all transforms instead of using `--strict:...` for each transform. 2798 2799 ## 0.5.8 2800 2801 * Transform async functions ([#137](https://github.com/evanw/esbuild/issues/137)) 2802 2803 This release transforms async functions into generator functions for older browsers when the language target is set to `--target=es2016` or below. The transform esbuild uses is similar to the one used by the TypeScript compiler. 2804 2805 ## 0.5.7 2806 2807 * Transform private fields and private methods ([#47](https://github.com/evanw/esbuild/issues/47)) 2808 2809 Private names are an access control mechanism for classes. They begin with a `#` and are not accessible outside of the class they are declared in. Support for parsing this syntax was added in esbuild version 0.4.9 but the syntax was passed through unmodified, meaning it didn't work in older browsers. 2810 2811 This release adds support for transforming private fields and private methods for older browsers that don't support this syntax. This transform uses `WeakMap` and `WeakSet` to preserve the privacy properties of this feature, similar to the corresponding transforms in the Babel and TypeScript compilers. 2812 2813 This code: 2814 2815 ```js 2816 class Counter { 2817 #count = 1 2818 get value() { return this.#count } 2819 increment() { ++this.#count } 2820 } 2821 ``` 2822 2823 is transformed into this code when using `--target=es2020`: 2824 2825 ```js 2826 var _count; 2827 class Counter { 2828 constructor() { _count.set(this, 1); } 2829 get value() { return __privateGet(this, _count); } 2830 increment() { __privateSet(this, _count, +__privateGet(this, _count) + 1); } 2831 } 2832 _count = new WeakMap(); 2833 ``` 2834 2835 Note that most modern JavaScript engines (V8, JavaScriptCore, and SpiderMonkey but not ChakraCore) may not have good performance characteristics for large `WeakMap` and `WeakSet` objects. Creating many instances of classes with private fields or private methods with this syntax transform active may cause a lot of overhead for the garbage collector. This is because modern engines (other than ChakraCore) store weak values in an actual map object instead of as hidden properties on the keys themselves, and large map objects can cause performance issues with garbage collection. See [this reference](https://github.com/tc39/ecma262/issues/1657#issuecomment-518916579) for more information. 2836 2837 * Fix re-exports when bundling 2838 2839 This is similar to the fix for re-exports in version 0.5.6 except that it applies when bundling, instead of just when transforming. It needed to be fixed differently because of how cross-file linking works when bundling. 2840 2841 ## 0.5.6 2842 2843 * Fix re-export statements ([#190](https://github.com/evanw/esbuild/issues/190)) 2844 2845 The previous release caused a regression due to some behind-the-scenes work for the upcoming code splitting feature. The re-export alias in statements of the form `export { foo as bar } from 'path'` could sometimes incorrectly be renamed to something else, such as `foo` becoming `foo2`. This release fixes the bug. 2846 2847 ## 0.5.5 2848 2849 * Implement logical assignment operator transforms 2850 2851 There are three new logical assignment operators: `??=`, `&&=`, and `||=`. With this release, you can now use them in older browsers by setting `--target` to a language version other than `esnext`. See [the V8 blog post](https://v8.dev/features/logical-assignment) for more information about how they work. 2852 2853 * Fix re-exports of a CommonJS module in `esm` format 2854 2855 Previously re-exports of an individual identifier from a CommonJS module generated JavaScript that crashed at run-time when using the `esm` output format. This was because esbuild always tries to generate "live" exports for CommonJS modules that always return the current value of the export instead of "dead" bindings that only return the initial value of the export. The bug happened because the ES6 module format doesn't have a way to forward a live binding to a CommonJS module as an ES6 export. The fix is to generate "dead" exports instead, which is the only available option in this edge case. 2856 2857 These input files: 2858 2859 ```js 2860 // entry_point.js 2861 export {foo} from './cjs-format.js' 2862 ``` 2863 2864 ```js 2865 // cjs-format.js 2866 Object.defineProperty(exports, 'foo', { 2867 enumerable: true, 2868 get: () => Math.random(), 2869 }) 2870 ``` 2871 2872 Now become this output file: 2873 2874 ```js 2875 // cjs-format.js 2876 var require_cjs_format = __commonJS((exports) => { 2877 Object.defineProperty(exports, "foo", { 2878 enumerable: true, 2879 get: () => Math.random() 2880 }); 2881 }); 2882 2883 // entry_point.js 2884 const cjs_format = __toModule(require_cjs_format()); 2885 const export_foo = cjs_format.foo; // This is a "dead" re-export 2886 export { 2887 export_foo as foo 2888 }; 2889 ``` 2890 2891 ## 0.5.4 2892 2893 * Source maps use `/` on Windows ([#188](https://github.com/evanw/esbuild/issues/188)) 2894 2895 Before generated source maps used `\` on Windows, which meant that tools consuming these source maps (e.g. Chrome) didn't recognize these characters as path separators. Now all platforms consistently use `/` as a path separator. 2896 2897 * Prevent input files from being overwritten 2898 2899 There are now checks in place to avoid input files being accidentally overwritten. This could easily happen with `--bundle --outdir=.` when bundling JavaScript files since the output file name ends up being the same as the entry point name, and is written to the same directory. 2900 2901 ## 0.5.3 2902 2903 * Special-case `require` in browserify bundles ([#80](https://github.com/evanw/esbuild/issues/80) and [#90](https://github.com/evanw/esbuild/issues/90)) 2904 2905 [Browserify](https://browserify.org/) generates code containing the expression `typeof require == "function" && require` which then ends up in a lot of npm packages. This expression is problematic because bundling involves statically determining all source files and their dependencies. Using `require` dynamically like this defeats the static analysis. It's also problematic because esbuild replaces `typeof require == "function"` with `true` since `require` is a function at compile-time when bundling. Then `true && require` becomes `require` in the generated code, which crashes at run time. 2906 2907 Previously esbuild would generate an error for these expressions. Now esbuild replaces `typeof require == "function" && require` with `false` when targeting the browser and `require` when targeting node. This matches the intent of the browserify prelude snippet and allows esbuild to build libraries containing this code without errors or warnings. 2908 2909 * Allow dynamic dependencies ([#113](https://github.com/evanw/esbuild/issues/113)) 2910 2911 Bundling `require()` or `import()` when the argument isn't a string literal is a dynamic dependency. The dependency path relies on dynamic run-time behavior and cannot be statically determined by esbuild at bundle time. 2912 2913 Dynamic dependencies used to be an error but are now just a warning. Builds containing them now succeed and the generated code contains the `require()` or `import()` expression. This is useful either when the dynamic dependency is intentional or when you know the dynamic dependency won't ever be triggered. Doing this still generates a warning to alert you that some code was excluded from the bundle and because these expressions may still crash at run time if the imported path isn't valid. 2914 2915 ## 0.5.2 2916 2917 * Fix a regression with `--define` and identifiers 2918 2919 The API refactor introduced a regression where using a `--define` flag to replace something with an identifier followed by another `--define` flag unintentionally caused the first `--define` to use the value from the second `--define` for replacement. This regression was caused by a loop that was added around a Go closure, which caused all closures in that loop to close over the same variable. The bug has been fixed. 2920 2921 * Fix interpretation of legacy `-->` single-line HTML comments 2922 2923 The `-->` sequence starts a single-line comment similar to `//`. This is legacy behavior from [annex B](https://www.ecma-international.org/ecma-262/6.0/#sec-html-like-comments) under the name `SingleLineHTMLCloseComment`. However, `-->` was incorrectly treated as the start of a comment even when it didn't come at the beginning of the line. Now `-->` only starts a comment if there are no tokens before it on that line. 2924 2925 * Allow shadowing of CommonJS variables ([#165](https://github.com/evanw/esbuild/issues/165)) 2926 2927 It's now no longer an error to re-declare `exports`, `module`, or `require` in a module scope. The re-declared symbol will just silently shadow the CommonJS variable with that name. This allows to use a variable called `exports` in an ES6 module, for example. 2928 2929 ## 0.5.1 2930 2931 * Go documentation was moved to godoc ([#177](https://github.com/evanw/esbuild/pull/177)) 2932 2933 The Go documentation is now in the source files itself instead of in an external Markdown file. View it online at https://godoc.org/github.com/evanw/esbuild/pkg/api and https://godoc.org/github.com/evanw/esbuild/pkg/cli. 2934 2935 * The browser API now works in a script tag 2936 2937 The initial release of the browser API required a bundler to use correctly since it was in CommonJS format. This release adds the ability to use the browser API directly in HTML. 2938 2939 Here's an example using https://unpkg.com/ for simplicity, although you should consider hosting the files yourself: 2940 2941 ```html 2942 <script src="https://unpkg.com/esbuild-wasm@0.5.1/lib/browser.js"></script> 2943 <script> 2944 (async () => { 2945 const service = await esbuild.startService({ 2946 wasmURL: 'https://unpkg.com/esbuild-wasm@0.5.1/esbuild.wasm' 2947 }) 2948 try { 2949 const ts = 'enum Foo { A, B, C }' 2950 const { js } = await service.transform(ts, { loader: 'ts' }) 2951 console.log(js) 2952 } finally { 2953 service.stop() 2954 } 2955 })() 2956 </script> 2957 ``` 2958 2959 ## 0.5.0 2960 2961 * Overhaul public-facing API code 2962 2963 This is a rewrite of all externally facing API code. It fixes some bugs and inconsistencies, adds some new features, and makes it easier to support various use cases going forward. 2964 2965 At a high-level, esbuild's API supports two separate operations: "build" and "transform". Building means reading from the file system and writing back to the file system. Transforming takes an input string and generates an output string. You should use the build API if you want to take advantage of esbuild's bundling capability, and you should use the transform API if you want to integrate esbuild as a library inside another tool (e.g. a "minify" plugin). This rewrite ensures the APIs for these two operations are exposed consistently for all ways of interacting with esbuild (both through the CLI and as a library). 2966 2967 Here are some of the highlights: 2968 2969 * There is now a public Go API ([#152](https://github.com/evanw/esbuild/issues/152)) 2970 2971 The main API can be found in the [`github.com/evanw/esbuild/pkg/api`](pkg/api/api.go) module. It exposes the exact same features as the JavaScript API. This means you can use esbuild as a JavaScript transformation and bundling library from Go code without having to run esbuild as a child process. There is also the [`github.com/evanw/esbuild/pkg/cli`](pkg/cli/cli.go) module which can be used to wrap the esbuild CLI itself. 2972 2973 * There are now synchronous JavaScript APIs ([#136](https://github.com/evanw/esbuild/issues/136)) 2974 2975 Sometimes JavaScript source transformations must be synchronous. For example, using esbuild's API to shim `require()` for `.ts` files was previously not possible because esbuild only had an asynchronous transform API. 2976 2977 This release adds the new `transformSync()` and `buildSync()` synchronous functions to mirror the existing `transform()` and `build()` asynchronous functions. Note that these synchronous calls incur the cost of starting up a new child process each time, so you should only use these instead of `startService()` if you have to (or if you don't care about optimal performance). 2978 2979 * There is now an experimental browser-based API ([#172](https://github.com/evanw/esbuild/issues/172)) 2980 2981 The `esbuild-wasm` package now has a file called `browser.js` that exposes a `startService()` API which is similar to the esbuild API available in node. You can either import the `esbuild-wasm` package using a bundler that respects the `browser` field in `package.json` or import the `esbuild-wasm/lib/browser.js` file directly. 2982 2983 This is what esbuild's browser API looks like: 2984 2985 ```ts 2986 interface BrowserOptions { 2987 wasmURL: string 2988 worker?: boolean 2989 } 2990 2991 interface BrowserService { 2992 transform(input: string, options: TransformOptions): Promise<TransformResult> 2993 stop(): void 2994 } 2995 2996 declare function startService(options: BrowserOptions): Promise<BrowserService> 2997 ``` 2998 2999 You must provide the URL to the `esbuild-wasm/esbuild.wasm` file in `wasmURL`. The optional `worker` parameter can be set to `false` to load the WebAssembly module in the same thread instead of creating a worker thread. Using a worker thread is recommended because it means transforming will not block the main thread. 3000 3001 This API is experimental and may be changed in the future depending on the feedback it gets. 3002 3003 * Error messages now use `sourcefile` ([#131](https://github.com/evanw/esbuild/issues/131)) 3004 3005 Errors from transform API calls now use `sourcefile` as the original file name if present. Previously the file name in error messages was always `/input.js`. 3006 3007 ## 0.4.14 3008 3009 * Do not reorder `"use strict"` after support code ([#173](https://github.com/evanw/esbuild/issues/173)) 3010 3011 Even when not in bundling mode, esbuild sometimes adds automatically-generated support code at the start of the output file. For example, using the `**` operator with `--target=es2015` causes `let __pow = Math.pow` to be inserted at the start of the file. This interfered with `"use strict"` directives, which must come first. Now `"use strict"` directives are written out first before any automatically-generated support code. 3012 3013 * Fix bug with export star pointing to a re-export ([#176](https://github.com/evanw/esbuild/issues/176)) 3014 3015 This fixes a tree shaking bug that involves an `export * from ...` statement pointing to a file with a `export {name} from ...` statement. Now `name` will no longer be incorrectly removed from the bundle. 3016 3017 ## 0.4.13 3018 3019 * Fix possible name collision with CommonJS the target ([#174](https://github.com/evanw/esbuild/issues/174)) 3020 3021 A bug meant that the export objects for individual modules with the same filename could in some cases end up reusing the same name in the output file, which then caused a syntax error. This only happened with the `cjs` target. The bug has been fixed. 3022 3023 ## 0.4.12 3024 3025 * Support `export * from ...` for CommonJS modules ([#159](https://github.com/evanw/esbuild/issues/159)) 3026 3027 Wildcard re-exports are now supported when the exports come from a CommonJS or external module. Since CommonJS modules are not statically analyzable, this means in these cases the re-exports are evaluated at run time instead of at bundle time. Modules that re-export symbols this way will also be considered CommonJS modules during bundling because their exports are now also not statically analyzable. 3028 3029 * Add 3rd-party library test coverage 3030 3031 From the esbuild repo, you can now run `make test-extra` to build some 3rd-party libraries (Rollup, Sucrase, and Esprima) with esbuild and run their test suites. This ensures that these libraries will continue to work as esbuild releases new features. 3032 3033 ## 0.4.11 3034 3035 * Fix top-level name minification with runtime 3036 3037 When not bundling, esbuild only minifies top-level names if the file is an ES6 module (as determined by the presence of an ES6 import or export statement). This determination had a bug where a non-module file was considered a module if esbuild automatically generated an import to some internal support code called the "runtime". For example, using the `**` operator with `--target=es2015` generates an import for the `__pow` runtime function. Runtime imports are now ignored for module determination, so an automatically-generated runtime import no longer causes top-level names to be minified. 3038 3039 * Fix class name generation for default exports 3040 3041 Some changes to name generation for TypeScript decorators caused the generated class name for `export default class` statements to sometimes not match the name used for other references to that class in the same file. This bug has been fixed. 3042 3043 ## 0.4.10 3044 3045 * Initial implementation of TypeScript decorators ([#104](https://github.com/evanw/esbuild/issues/104)) 3046 3047 This release contains an initial implementation of the non-standard TypeScript-specific decorator syntax. This syntax transformation is enabled by default in esbuild, so no extra configuration is needed. The TypeScript compiler will need `"experimentalDecorators": true` configured in `tsconfig.json` for type checking to work with TypeScript decorators. 3048 3049 Here's an example of a method decorator: 3050 3051 ```ts 3052 function logged(target, key, descriptor) { 3053 let method = descriptor.value 3054 descriptor.value = function(...args) { 3055 let result = method.apply(this, args) 3056 let joined = args.map(x => JSON.stringify(x)).join(', ') 3057 console.log(`${key}(${joined}) => ${JSON.stringify(result)}`) 3058 return result 3059 } 3060 } 3061 3062 class Example { 3063 @logged 3064 method(text: string) { 3065 return text + '!' 3066 } 3067 } 3068 3069 const x = new Example 3070 x.method('text') 3071 ``` 3072 3073 There are four kinds of TypeScript decorators: class, method, parameter, and field decorators. See [the TypeScript decorator documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more information. Note that esbuild only implements TypeScript's `experimentalDecorators` setting. It does not implement the `emitDecoratorMetadata` setting because that requires type information. 3074 3075 * Fix order of side effects for computed fields 3076 3077 When transforming computed class fields, esbuild had a bug where the side effects of the field property names were not evaluated in source code order. The order of side effects now matches the order in the source code. 3078 3079 * Fix private fields in TypeScript 3080 3081 This fixes a bug with private instance fields in TypeScript where the private field declaration was incorrectly removed during the TypeScript class field transform, which inlines the initializers into the constructor. Now the initializers are still moved to the constructor but the private field declaration is preserved without the initializer. 3082 3083 Note that since static private fields are not currently supported by the official TypeScript compiler, they are also not supported by esbuild in TypeScript files. They are supported by esbuild in JavaScript files, however. 3084 3085 ## 0.4.9 3086 3087 * Initial support for private names ([#47](https://github.com/evanw/esbuild/issues/47)) 3088 3089 Private names are an access control mechanism for classes. They begin with a `#` and are not accessible outside of the class they are declared in. The private name syntax can now be parsed, printed, and minified correctly. Transforming this syntax for older browsers is not supported yet. This is what the syntax looks like: 3090 3091 ```js 3092 class Counter { 3093 #count = 1 3094 get value() { return this.#count } 3095 increment() { this.#count++ } 3096 } 3097 ``` 3098 3099 You can read more about these features here: 3100 3101 * https://github.com/tc39/proposal-private-methods 3102 * https://github.com/tc39/proposal-class-fields 3103 * https://github.com/tc39/proposal-static-class-features 3104 3105 * Initial support for logical assignment operators 3106 3107 This adds support for the three new logical assignment operators `||=`, `&&=`, and `??=`, which can now be parsed and passed through to the output. Transforming this syntax for older browsers is not supported yet. You can read more about these operators here: https://github.com/tc39/proposal-logical-assignment. 3108 3109 * Data loaders now set "no side effects" 3110 3111 Files loaded using the `json`, `text`, `base64`, `dataurl`, and `file` loaders are now removed from the bundle if the files that import them never use the imports. This is the same behavior as the `"sideEffects": false` setting in `package.json`. 3112 3113 ## 0.4.8 3114 3115 * Add the `--metafile` flag ([#140](https://github.com/evanw/esbuild/issues/140)) 3116 3117 Pass `--metafile=meta.json` to write metadata about the build to the file `meta.json`. This includes information such as which files are in the bundle, what other files a given file depends on, and how much of each file ended up in the bundle. This is similar to the [stats option in Webpack](https://webpack.js.org/api/stats/). 3118 3119 The format looks like this: 3120 3121 ```ts 3122 interface Metadata { 3123 inputs: { 3124 [path: string]: { 3125 bytes: number 3126 imports: { 3127 path: string 3128 }[] 3129 } 3130 } 3131 outputs: { 3132 [path: string]: { 3133 bytes: number 3134 inputs: { 3135 [path: string]: { 3136 bytesInOutput: number 3137 } 3138 } 3139 } 3140 } 3141 } 3142 ``` 3143 3144 * Shorten numeric literals ([#122](https://github.com/evanw/esbuild/issues/122)) 3145 3146 Certain numeric literals now use shorter representations in the generated JavaScript code. For example, `123400000` is now written out as `1234e5`. 3147 3148 ## 0.4.7 3149 3150 * Fixed `sideEffects` and nested directories 3151 3152 This fixes a bug where `package.json` files with `"sideEffects": false` were not respected for files in nested directories. When this bug occurred, bundles could be bigger than necessary. The `sideEffects` hint is now respected if any parent directory contains the hint instead of just the immediate enclosing directory. 3153 3154 * Fixed `sideEffects` and default exports with side effects 3155 3156 This fixes a bug with default exports with side effects inside a `"sideEffects": false` context that were imported and used. These exports were incorrectly discarded instead of being retained, which could cause the resulting bundle to crash. 3157 3158 ## 0.4.6 3159 3160 * Respect the `sideEffects` field when tree shaking ([#50](https://github.com/evanw/esbuild/issues/50)) 3161 3162 Tree shaking now respects `"sideEffects": false` in `package.json`, which means esbuild now generates smaller bundles with certain libraries such as [lodash-es](https://www.npmjs.com/package/lodash-es). This setting is a [convention from Webpack](https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free). Any files in a package with this setting will not be included in the bundle if they are imported using an ES6 import and then never used. 3163 3164 ## 0.4.5 3165 3166 * Fix a crash with more than 8 entry points ([#162](https://github.com/evanw/esbuild/pull/162)) 3167 3168 This bug was due to the wrong index being used for an internal bit set. That caused a crash due to an out-of-bounds array read when esbuild is run with more than 8 entry points. I now have test coverage for large numbers of entry points, so this should not happen again. 3169 3170 * Fix slash characters in file loader ([#164](https://github.com/evanw/esbuild/pull/164)) 3171 3172 This fixes a bug where the base64-encoded hash included in the file name could sometimes contain a `/` character. The fix is to use the base64 character set for URL-encoding, which replaces the `/` character with a `_` character. 3173 3174 ## 0.4.4 3175 3176 * Fix optional chaining with TypeScript operators ([#168](https://github.com/evanw/esbuild/issues/168)) 3177 3178 The work on optional chaining in the previous release introduced a regression where the TypeScript infix operators `!` and `<>` incorrectly stopped the propagation of optional chaining. That meant `a?.b!()` and `a?.b<T>()` incorrectly behaved like `(a?.b)()` instead of `a?.b()`. This now has test coverage. 3179 3180 * Add support for the `"paths"` field in `tsconfig.json` ([#60](https://github.com/evanw/esbuild/issues/60) and [#144](https://github.com/evanw/esbuild/issues/144)) 3181 3182 This provides a way of remapping module paths to local file paths. It's relatively powerful because it supports wildcard patterns and multiple fallback locations. See [the documentation in the TypeScript handbook](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) for more information about how this feature works. This was contributed by [@viankakrisna](https://github.com/viankakrisna). 3183 3184 * Add the `file` loader ([#14](https://github.com/evanw/esbuild/issues/14) and [#135](https://github.com/evanw/esbuild/pull/135)) 3185 3186 The `file` loader copies the input file to the output directory and exports the path of the file as a string to any modules that import the file. For example, `--loader:.png=file` enables this loader for all imported `.png` files. This was contributed by [@viankakrisna](https://github.com/viankakrisna). 3187 3188 * Add the `--resolve-extensions` flag ([#142](https://github.com/evanw/esbuild/pull/142)) 3189 3190 This lets you override the implicit extensions that are tested when importing a file. It must be a comma-separated list of extensions. For example, setting `--resolve-extensions=.jsx,.js` means `import "./foo"` will check for `./foo` then `./foo.jsx` then `./foo.js` in that order. The behavior corresponds to [the similarly-named feature in Webpack](https://webpack.js.org/configuration/resolve/#resolveextensions). This was contributed by [@viankakrisna](https://github.com/viankakrisna). 3191 3192 ## 0.4.3 3193 3194 * Fix bug with optional chaining parentheses ([#156](https://github.com/evanw/esbuild/issues/156)) 3195 3196 One edge case with JavaScript optional chaining syntax is that parentheses stop the chain. So `a?.b.c` will be `undefined` if `a` is nullish but `(a?.b).c` will crash if `a` is nullish. 3197 3198 This was handled correctly when lowering is enabled (i.e. when the language target is `es2019` or below) but was not handled correctly when lowering is disabled (i.e. when the language target is `es2020` or above). The output for `(a?.b).c` was incorrectly `a?.b.c` instead of `(a?.b).c`, which would no longer crash if `a` is nullish. The fix is to preserve the parentheses in the output. 3199 3200 * Support for the PowerPC 64-bit Little Endian architecture on Linux ([#146](https://github.com/evanw/esbuild/pull/146)) 3201 3202 This was contributed by [@runlevel5](https://github.com/runlevel5). 3203 3204 ## 0.4.2 3205 3206 * Bind imports to re-exports ([#149](https://github.com/evanw/esbuild/issues/149)) 3207 3208 This fixes a bug where imports of re-exported symbols were not correctly merged in some cases. This resulted in the generated code referencing symbols that were not declared, resulting in a crash. 3209 3210 ## 0.4.1 3211 3212 * Add a log level setting ([#117](https://github.com/evanw/esbuild/issues/117)) 3213 3214 You can now silence esbuild except for errors with `--log-level=error`, or except for errors and warnings with `--log-level=warning`. 3215 3216 * Now `jsconfig.json` is an alternative to `tsconfig.json` ([#132](https://github.com/evanw/esbuild/pull/132)) 3217 3218 The `"baseUrl"` setting in `tsconfig.json`, which lets you avoid `../../` relative import paths, is respected by esbuild. With this change, esbuild will also check for this setting in `jsconfig.json` if no `tsconfig.json` file is found. This is relevant to some projects that use the TypeScript compiler with JavaScript files instead of TypeScript files. You can read more about this feature [here](https://code.visualstudio.com/docs/languages/jsconfig). This was contributed by [@viankakrisna](https://github.com/viankakrisna). 3219 3220 * Chinese translation of documentation ([#129](https://github.com/evanw/esbuild/pull/129)) 3221 3222 Both the readme and the architecture documentation have been translated into Chinese, which is available here: http://docs.breword.com/evanw-esbuild. This was contributed by [@92hackers](https://github.com/92hackers). 3223 3224 * Async generator functions require `--target=es2018` 3225 3226 This fixes a bug where async generator functions were incorrectly allowed with `--target=es2017`, which is incorrect because the [asynchronous iteration spec](https://github.com/tc39/proposal-async-iteration) is part of ES2018. 3227 3228 ## 0.4.0 3229 3230 * Add the `esm` output format ([#48](https://github.com/evanw/esbuild/issues/48)) 3231 3232 It is now possible to generate a bundle in ES6 module format using `--format=esm`. The generated code uses ES6 import and export statements. This is useful for bundling code to be used as a library, for using in a `<script type="module>` tag in the browser, or for using with node's `--experimental-modules` flag. Note that CommonJS entry points bundled with this format will become a single default export, which is the same way node works. 3233 3234 * Preliminary tree shaking support ([#50](https://github.com/evanw/esbuild/issues/50)) 3235 3236 Bundling now performs tree shaking, which is also known as dead code elimination. Every top-level statement is considered to be a separate part of the file, and unused parts without any side effects are not included in the bundle. This only really affects code using ES6 modules, so make sure you use ES6 modules to take advantage of tree shaking. 3237 3238 This is the initial release of tree shaking which lands the fundamental mechanism behind it. This release does not include the [various annotations used by the community](https://webpack.js.org/guides/tree-shaking/) to indicate side-effect free code (e.g. `"sideEffects": false` and `/*#__PURE__*/`), so esbuild will likely generate somewhat bigger bundles than other bundlers. Support for these annotations will come in future releases. 3239 3240 * Benchmarks have been re-run 3241 3242 This updates all of the bundlers used in the benchmark to their latest versions. Due to recent performance work, esbuild is now at least 100x faster than all other bundlers. I have also included a single-threaded version of esbuild for comparison since some people were wondering how much of esbuild's performance was due to multithreading. 3243 3244 * Warnings about future syntax are now errors 3245 3246 This happens when an input file contains newer JavaScript syntax and `--target` is set to an earlier version of JavaScript than the syntax can be transformed to. These most of transforms will be implemented eventually, but for now some are still unimplemented. This was changed from a warning to an error because ignoring these warnings could result in broken code in older browsers, so these messages are more serious than warnings. 3247 3248 * Using bundle-related flags without `--bundle` is now an error 3249 3250 This leaves the possibility open of using these flags for non-bundle mode in the future. For example, in the future `--format` may also work when not bundling. 3251 3252 ## 0.3.9 3253 3254 * Add the `dataurl` loader ([#107](https://github.com/evanw/esbuild/pull/107)) 3255 3256 This loader turns the file into a base64-encoded data URL. The mime type is automatically derived from the file extension, with the file contents used as a fallback. This was contributed by [@viankakrisna](https://github.com/viankakrisna). 3257 3258 * Fix minification bug with external modules ([#134](https://github.com/evanw/esbuild/issues/134)) 3259 3260 When loading a module marked `--external` with `require()`, the resulting code was sometimes incorrectly minified when bundling. This now has test coverage. 3261 3262 ## 0.3.8 3263 3264 * Fix an issue that prevented non-inline source maps with the `build()` API ([#130](https://github.com/evanw/esbuild/issues/130)) 3265 3266 The issue happend when invoking `esbuild.build({ sourcemap: true })` and was a regression due to the addition of inline source map support. This now has test coverage. 3267 3268 ## 0.3.7 3269 3270 * Add an unsupported build for ARM64 ([#123](https://github.com/evanw/esbuild/issues/123)) 3271 3272 Now you can `npm install esbuild` on a Linux ARM64 machine and it should work. This lets you run esbuild on a Raspberry Pi. Note that this target isn't officially supported because it's not covered by any automated tests. This was contributed by [@violentmagician](https://github.com/violentmagician). 3273 3274 ## 0.3.6 3275 3276 * Fix a bug with JSX element contents that end in a multi-byte unicode character ([#124](https://github.com/evanw/esbuild/issues/124)) 3277 3278 Such characters are now preserved instead of being truncated. 3279 3280 ## 0.3.5 3281 3282 * Performance improvements 3283 3284 The parsing phase was failing to saturate all CPUs in many cases because input files were being read on a single goroutine in a blocking fashion. Each file is now read on its own goroutine and the parsing phase now saturates all CPUs. 3285 3286 With the performance improvements in this release and the previous release, the time to run the JavaScript benchmark has been reduced from 0.54s to 0.4s, which is approximately a 25% performance improvement. 3287 3288 ## 0.3.4 3289 3290 * Performance improvements 3291 3292 The GC is now disabled when running in build-and-exit mode, which is a noticeable speedup. This release also fixes some accidental O(n^2) behavior in the code that renames variables to avoid collisions in non-minify mode. This didn't affect any of esbuild's benchmarks but it did cause issues on certain other artificial test cases. 3293 3294 ## 0.3.3 3295 3296 * Support all unicode whitespace ([#116](https://github.com/evanw/esbuild/issues/116)) 3297 3298 The lexer now accepts all unicode characters in the `WS` category as valid whitespace to match the JavaScript standard. 3299 3300 ## 0.3.2 3301 3302 * Add some options related to source maps 3303 3304 There is now a `sourcefile` option to set the input file path for input files without a path. This happens in two cases: either using the `service.transform()` API or passing an input file using stdin. 3305 3306 This release also adds the `inline` value for the `sourcemap` option which inlines the source map as a base64-encoded data URL in the output file instead of writing the source map to a separate file. 3307 3308 ## 0.3.1 3309 3310 * Remove type-only exports from TypeScript ([#110](https://github.com/evanw/esbuild/issues/110)) 3311 3312 This fixes a bug where type-only exports in TypeScript files could in some cases generate an invalid export statement. 3313 3314 ## 0.3.0 3315 3316 * Support for stdin/stdout ([#76](https://github.com/evanw/esbuild/issues/76)) 3317 3318 You can now pass esbuild an input file over stdin instead of using a file path. Use the `--loader=jsx` syntax to set the loader instead of using the `--loader:.js=jsx` syntax. 3319 3320 Now if there is no output file, esbuild will write the output to stdout. Before this, esbuild would try to infer an output file based on the input file name. This is a breaking change so it was released with a minor version bump.