{"id":15390182,"url":"https://github.com/gajus/babel-plugin-transform-export-default-name","last_synced_at":"2025-09-08T22:45:09.284Z","repository":{"id":3817351,"uuid":"50997195","full_name":"gajus/babel-plugin-transform-export-default-name","owner":"gajus","description":"Babel plugin that transforms default exports to named exports.","archived":false,"fork":false,"pushed_at":"2022-04-14T20:37:04.000Z","size":139,"stargazers_count":21,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T01:23:42.512Z","etag":null,"topics":["babel-plugin","es-modules"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-03T12:08:54.000Z","updated_at":"2024-07-24T12:20:35.000Z","dependencies_parsed_at":"2022-09-08T01:11:37.218Z","dependency_job_id":null,"html_url":"https://github.com/gajus/babel-plugin-transform-export-default-name","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fbabel-plugin-transform-export-default-name","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fbabel-plugin-transform-export-default-name/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fbabel-plugin-transform-export-default-name/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fbabel-plugin-transform-export-default-name/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/babel-plugin-transform-export-default-name/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248510002,"owners_count":21116131,"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":["babel-plugin","es-modules"],"created_at":"2024-10-01T15:04:45.791Z","updated_at":"2025-04-15T21:19:46.100Z","avatar_url":"https://github.com/gajus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-transform-export-default-name\n\n[![NPM version](http://img.shields.io/npm/v/babel-plugin-transform-export-default-name.svg?style=flat-square)](https://www.npmjs.org/package/babel-plugin-transform-export-default-name)\n[![Travis build status](http://img.shields.io/travis/gajus/babel-plugin-transform-export-default-name/master.svg?style=flat-square)](https://travis-ci.org/gajus/babel-plugin-transform-export-default-name)\n[![js-canonical-style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n\nBabel plugin that transforms `export default` of anonymous functions to named function export.\n\nPlugin uses the name of the target file to create a temporary variable. Target resource (arrow function or an anonymous function) is assigned to the latter temporary variable. Temporary value is used in place of function in the export declaration.\n\n## Implementation\n\nValues that are affected:\n\n* anonymous function\n* arrow function\n* anonymous class\n\nNamed function, named class and other object as well as literal values are not transformed.\n\n### Export Name\n\nThe name used for a temporary variable is derived from the name of the file (excluding `.js` extension). [`_.camelCase`](https://lodash.com/docs#camelCase) is used to sanitize file name (i.e. `foo-bar.js` becomes `fooBar`).\n\n## Problem\n\nExecuting a function without a name (arrow function or an anonymous function) appears as an `(anonymous function)` in the stack trace, e.g.\n\n```js\n(() =\u003e {\n    throw new Error('Hello, World!');\n})();\n```\n\n![Stack trace without function name](./.README/stack-trace-without-name.png)\n\nHowever, if an arrow function is defined on the right-hand-side of an assignment expression, the engine will take the name on the left-hand-side and use it to set the arrow function's `.name`, e.g.\n\n```js\nlet test;\n\ntest = () =\u003e {\n    throw new Error('Hello, World!');\n};\n\ntest();\n```\n\n![Stack trace without function name](./.README/stack-trace-with-name.png)\n\nWhen you export an anonymous function using `export default`, this function will appear as an `(anonymous function)` the stack trace. `babel-plugin-transform-export-default-name` plugin transforms the code to assign function a name before it is exported.\n\n`./index.js`\n\n```js\nimport foo from './foo';\n\nfoo();\n```\n\n`./foo.js`\n\n```js\nimport bar from './bar';\n\nexport default () =\u003e {\n    bar();\n};\n```\n\n`./bar.js`\n\n```js\nimport baz from './baz';\n\nexport default () =\u003e {\n    baz();\n};\n```\n\n`./baz.js`\n\n```js\nexport default () =\u003e {\n    throw new Error('test');\n};\n```\n\n![Stack trace before and after export is given a name](./.README/stack-trace-before-and-after.png)\n\n## Example\n\nInput file is `./foo.js`.\n\nInput code:\n\n```js\nexport default () =\u003e {};\n```\n\nOutput code:\n\n```js\nlet foo = () =\u003e {};\n\nexport default foo;\n```\n\n## Usage\n\nAdd to `.babelrc`:\n\n```js\n{\n    \"plugins\": [\n        \"transform-export-default-name\"\n    ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fbabel-plugin-transform-export-default-name","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fbabel-plugin-transform-export-default-name","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fbabel-plugin-transform-export-default-name/lists"}