{"id":20277360,"url":"https://github.com/bitjson/shake-default-params","last_synced_at":"2025-03-04T01:41:53.443Z","repository":{"id":69519815,"uuid":"482064037","full_name":"bitjson/shake-default-params","owner":"bitjson","description":"Testing dead-code elimination of unused default parameters in all known JS bundlers","archived":false,"fork":false,"pushed_at":"2022-05-17T16:13:02.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-14T06:47:09.652Z","etag":null,"topics":["dead-code-elimination","esbuild","parcel","rollup","tree-shaking","webpack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitjson.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-15T19:28:46.000Z","updated_at":"2022-04-15T20:27:08.000Z","dependencies_parsed_at":"2023-02-22T09:45:27.691Z","dependency_job_id":null,"html_url":"https://github.com/bitjson/shake-default-params","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitjson%2Fshake-default-params","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitjson%2Fshake-default-params/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitjson%2Fshake-default-params/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitjson%2Fshake-default-params/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitjson","download_url":"https://codeload.github.com/bitjson/shake-default-params/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241768282,"owners_count":20017117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dead-code-elimination","esbuild","parcel","rollup","tree-shaking","webpack"],"created_at":"2024-11-14T13:18:06.375Z","updated_at":"2025-03-04T01:41:53.416Z","avatar_url":"https://github.com/bitjson.png","language":"JavaScript","readme":"# Tree-Shaking Default Parameters\n\nThis demo tests how various bundlers handle [Libauth](https://github.com/bitauth/libauth/)'s WebAssembly crypto implementations (`ripemd160`, `sha1`, `sha256`, `sha512`, and `secp256k1`).\n\nAs a [pure ESM library](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), Libauth v2 can asynchronously instantiate each WASM implementation internally, exporting simple interfaces that behave like collections of JS-only functions (with better performance).\n\nMany of Libauth's exported functions also use one of these built-in WASM instances as a default parameter. For example, `decodeBase58Address` has the definition:\n\n```ts\nexport const decodeBase58Address = (\n  address: string,\n  sha256: { hash: (input: Uint8Array) =\u003e Uint8Array } = internalSha256\n) =\u003e {\n  // ...\n};\n```\n\nMost applications can call `decodeBase58Address(address)` to automatically use the default, WASM-based `sha256` implementation (`internalSha256`). See [`src/app-default.js`](./src/app-default.js).\n\nApplications that already have another `sha256` implementation can provide that implementation as the second parameter: `decodeBase58Address(address, mySha256Implementation)`. In this case, the default parameter (`internalSha256`) is dead code and should be possible to eliminate from the application's bundle (commonly called [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) in the JavaScript ecosystem). See [`src/app-shakable.js`](./src/app-shakable.js).\n\n## Bundler Support\n\nThis repo tests dead-code elimination of unused default parameters as used in Libauth (with asynchronously instantiated WASM implementations): [`src/app-shakable.js`](./src/app-shakable.js).\n\nCurrently, **dead-code elimination of unused default parameters** is only supported by [Rollup](https://rollupjs.org/).\n\n| Bundler                                 |                      Support                       | Issue                                                                                | PR                                                                 |\n| --------------------------------------- | :------------------------------------------------: | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------ |\n| [`esbuild`](https://esbuild.github.io/) | ❌ ([example](./bundlers/esbuild/app-shakable.js)) | [`evanw/esbuild#2185`](https://github.com/evanw/esbuild/issues/2185)                 | -                                                                  |\n| [`parcel`](https://parceljs.org/)       | ❌ ([example](./bundlers/parcel/app-shakable.js))  | [`parcel-bundler/parcel#7961`](https://github.com/parcel-bundler/parcel/issues/7961) | -                                                                  |\n| [`rollup`](https://rollupjs.org/)       | ⏳ ([example](./bundlers/rollup/app-shakable.js))  | [`rollup/rollup#4466`](https://github.com/rollup/rollup/issues/4466)                 | [`rollup/rollup#4498`](https://github.com/rollup/rollup/pull/4498) |\n| [`terser`](https://terser.org/)         | ❌ ([example](./bundlers/terser/app-shakable.js))  | [`terser/terser#1199`](https://github.com/terser/terser/issues/1199)                 | -                                                                  |\n| [`webpack`](https://webpack.js.org/)    |    ❌ ([example](./bundlers/webpack/main.mjs))     | [`webpack/webpack#15671`](https://github.com/webpack/webpack/issues/15671)           | -                                                                  |\n\nThis simpler example may also be useful for quickly testing support in bundlers:\n\n`package.json`:\n\n```json\n{\n  \"type\": \"module\"\n}\n```\n\n`module.js`:\n\n```js\n// should not appear in bundle:\nconst internalAdd = (a, b) =\u003e (a === '0' ? b : a + b);\n\nexport const addAndLog = (a, b, impl = internalAdd) =\u003e console.log(impl(a, b));\n```\n\n`app.js`:\n\n```js\nimport { addAndLog } from './module.js';\n\nconst myAdd = (a, b) =\u003e a + b;\n\naddAndLog(1, 2, myAdd); // =\u003e 3\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitjson%2Fshake-default-params","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitjson%2Fshake-default-params","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitjson%2Fshake-default-params/lists"}