{"id":13451753,"url":"https://github.com/tc39/proposal-export-default-from","last_synced_at":"2025-04-09T15:09:51.841Z","repository":{"id":46410948,"uuid":"55003623","full_name":"tc39/proposal-export-default-from","owner":"tc39","description":"Proposal to add `export v from \"mod\";` to ECMAScript.","archived":false,"fork":false,"pushed_at":"2021-10-15T18:42:55.000Z","size":34,"stargazers_count":312,"open_issues_count":4,"forks_count":12,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-09T15:09:41.418Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tc39.github.io/proposal-export-default-from/","language":"HTML","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/tc39.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}},"created_at":"2016-03-29T19:13:42.000Z","updated_at":"2025-03-26T16:15:23.000Z","dependencies_parsed_at":"2022-09-03T10:00:18.656Z","dependency_job_id":null,"html_url":"https://github.com/tc39/proposal-export-default-from","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/tc39%2Fproposal-export-default-from","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-export-default-from/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-export-default-from/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-export-default-from/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tc39","download_url":"https://codeload.github.com/tc39/proposal-export-default-from/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040157,"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":[],"created_at":"2024-07-31T07:01:01.362Z","updated_at":"2025-04-09T15:09:51.826Z","avatar_url":"https://github.com/tc39.png","language":"HTML","readme":"# ECMAScript Proposal: export default from\n\n**Stage:** 1\n\n**Author:** Lee Byron\n\n**Reviewers:** Caridy Patiño\n\n**Specification:** https://tc39.github.io/proposal-export-default-from/\n\n**AST:** [ESTree.md](./ESTree.md)\n\n**Transpiler:** See Babel's [export-default-from](https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from) plugin.\n\n\u003e NOTE: Closely related to the [export-ns-from](https://github.com/tc39/proposal-export-ns-from) proposal.\n\n## Problem statement and rationale\n\nThe `export ___ from \"module\"` statements are a very useful mechanism for\nbuilding up \"package\" modules in a declarative way. In the ECMAScript 2015 spec,\nwe can:\n\n* export through a single export with `export {x} from \"mod\"`\n* ...optionally renaming it with `export {x as v} from \"mod\"`.\n* We can also spread all exports with `export * from \"mod\"`.\n\nThese three export-from statements are easy to understand if you understand the\nsemantics of the similar looking import statements.\n\nHowever there is an import statement which does not have corresponding\nexport-from statement, exporting the ModuleNameSpace object as a named export.\n\nExample:\n\n```js\nexport someIdentifier from \"someModule\";\nexport someIdentifier, { namedIdentifier } from \"someModule\";\n```\n\n\n### Current ECMAScript 2015 Modules:\n\nImport Statement Form         | [[ModuleRequest]] | [[ImportName]] | [[LocalName]]\n---------------------         | ----------------- | -------------- | -------------\n`import v from \"mod\";`        | `\"mod\"`           | `\"default\"`    | `\"v\"`\n`import * as ns from \"mod\";`  | `\"mod\"`           | `\"*\"`          | `\"ns\"`\n`import {x} from \"mod\";`      | `\"mod\"`           | `\"x\"`          | `\"x\"`\n`import {x as v} from \"mod\";` | `\"mod\"`           | `\"x\"`          | `\"v\"`\n`import \"mod\";`               |                   |                |\n\n\nExport Statement Form           | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] | [[ExportName]]\n---------------------           | ----------------- | -------------- | ------------- | --------------\n`export var v;`                 | **null**          | **null**       | `\"v\"`         | `\"v\"`\n`export default function f(){};`| **null**          | **null**       | `\"f\"`         | `\"default\"`\n`export default function(){};`  | **null**          | **null**       | `\"*default*\"` | `\"default\"`\n`export default 42;`            | **null**          | **null**       | `\"*default*\"` | `\"default\"`\n`export {x}`;                   | **null**          | **null**       | `\"x\"`         | `\"x\"`\n`export {x as v}`;              | **null**          | **null**       | `\"x\"`         | `\"v\"`\n`export * as ns from \"mod\";`    | `\"mod\"`           | `\"*\"`          | **null**      | `\"ns\"`\n`export {x} from \"mod\"`;        | `\"mod\"`           | `\"x\"`          | **null**      | `\"x\"`\n`export {x as v} from \"mod\"`;   | `\"mod\"`           | `\"x\"`          | **null**      | `\"v\"`\n`export * from \"mod\"`;          | `\"mod\"`           | `\"*\"`          | **null**      | **null**\n\n\n### Proposed addition:\n\nExport Statement Form   | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] | [[ExportName]]\n---------------------   | ----------------- | -------------- | ------------- | --------------\n`export v from \"mod\";`  | `\"mod\"`           | `\"default\"`    | **null**      | `\"v\"`\n\n\n## Symmetry between import and export\n\nThere's a syntactic symmetry between the export-from statements and the import\nstatements they resemble. There is also a semantic symmetry; where import\ncreates a locally named binding, export-from creates an export entry.\n\nAs an existing example:\n\n```js\nimport {v} from \"mod\";\n```\n\nIf then `v` should be exported, this can be followed by an `export`. However, if\n`v` is unused in the local scope, then it has introduced a name to the local\nscope unnecessarily.\n\n```js\nimport {v} from \"mod\";\nexport {v};\n```\n\nA single \"export from\" line directly creates an export entry, and does not alter\nthe local scope. It is *symmetric* to the similar \"import from\" statement.\n\n```js\nexport {v} from \"mod\";\n```\n\nThis presents a developer experience where it is expected that replacing the\nword `import` with `export` will always provide this symmetric behavior.\n\nHowever, when there is a gap in this symmetry, it can lead to confusing behavior:\n\n\u003e \"I would like to chime in with use-case evidence. When I began using ES6 (via\n\u003e babel) and discovered imports could be re-exported I assumed the feature set\n\u003e would be symmetrical only to find out quite surprisingly that it was not. I\n\u003e would love to see this spec round out what I believe is a slightly incomplete\n\u003e feature set in ES6.\"\n\u003e\n\u003e - @jasonkuhrt\n\u003e\n\u003e \"I also bumped into this and even thought this was a bug in Babel.\"\n\u003e\n\u003e - @gaearon\n\n### Proposed addition:\n\nThe proposed addition follows this same symmetric pattern:\n\nImporting the \"default\" name (existing):\n\n```js\nimport v from \"mod\";\n```\n\nExporting that name (existing):\n\n```js\nimport v from \"mod\";\nexport {v};\n```\n\nSymmetric \"export from\" (proposed):\n\n```js\nexport v from \"mod\";\n```\n\n### Compound \"export from\" statements:\n\nThis proposal also includes the symmetric export-from for the compound imports:\n\nImporting the \"default\" name as well as named export (existing):\n\n```js\nimport v, { x, y as w } from \"mod\";\n```\n\nExporting those names (existing):\n\n```js\nimport v, { x, y as w } from \"mod\";\nexport { v, x, w };\n```\n\nSymmetric \"export from\" (proposed):\n\n```js\nexport v, {x, y as w} from \"mod\";\n```\n\n\u003e Note: The compound form must also support [export-ns-from](https://github.com/leebyron/ecmascript-export-ns-from) should both proposals be accepted:\n\u003e\n\u003e ```js\n\u003e export v, * as ns from \"mod\";\n\u003e ```\n\n### Exporting a default as default:\n\nOne use case is to take the default export of an inner module and export it as\nthe default export of the outer module. This can be written as:\n\n```js\nexport default from \"mod\";\n```\n\nThis is symmmetric to the (existing) import form:\n\n```js\nimport default from \"mod\";\nexport { default };\n```\n\nThis is *not additional syntax* above what's already proposed. In fact, this is\njust the `export v from \"mod\"` syntax where the export name happens to be\n`default`. This nicely mirrors the other `export default ____` forms in both\nsyntax and semantics without requiring additional specification. An alteration\nto an existing lookahead restriction is necessary for supporting this case.\n\n\n### Common concerns:\n\n\u003e Do we need this even through you can already do this with `export { default } from \"mod\"`?\n\nYes! It is true that you can already \"export from\" a module's default export\nwithout altering the local scope:\n\n```js\nexport { default } from \"mod\";\n```\n\nYou can even rename the default:\n\n```js\nexport { default as someIdentifier } from \"mod\"\n```\n\nThere is a benefit to this, it's explicit and it is symmetric with the\n\"import\" form:\n\n```js\nimport { default as someIdentifier } from \"mod\"\n```\n\nHowever the purpose of this proposal is not to enable a new use case, the\npurpose is to provide an expected syntactic form which currently does not exist,\nand which favors the \"default\" export.\n\nThat \"import\" example is not often typed, as there is a preferred shorter syntax:\n\n```js\nimport someIdentifier from \"mod\"\n```\n\nThis proposal argues that a similar shorter syntax should also exist for a\nsymmetric \"export from\" form:\n\n```js\nexport someIdentifier from \"mod\"\n```\n\n\n### Table showing symmetry\n\nUsing the terminology of [Table 40][] and [Table 42][] in ECMAScript 2015, the\nexport-from form can be created from the symmetric import form by setting\nexport-from's **[[ExportName]]** to import's **[[LocalName]]** and export-from's\n**[[LocalName]]** to **null**.\n\n[Table 40]: http://www.ecma-international.org/ecma-262/6.0/#table-40\n[Table 42]: http://www.ecma-international.org/ecma-262/6.0/#table-42\n\nStatement Form                          | [[ModuleRequest]] | [[ImportName]] | [[LocalName]]  | [[ExportName]]\n--------------                          | ----------------- | -------------- | -------------- | --------------\n`import v from \"mod\";`                  | `\"mod\"`           | `\"default\"`    | `\"v\"`          |\n\u003cins\u003e`export v from \"mod\";`\u003c/ins\u003e       | `\"mod\"`           | `\"default\"`    | **null**       | `\"v\"`\n`import {x} from \"mod\";`                | `\"mod\"`           | `\"x\"`          | `\"x\"`          |\n`export {x} from \"mod\";`                | `\"mod\"`           | `\"x\"`          | **null**       | `\"x\"`\n`import {x as v} from \"mod\";`           | `\"mod\"`           | `\"x\"`          | `\"v\"`          |\n`export {x as v} from \"mod\";`           | `\"mod\"`           | `\"x\"`          | **null**       | `\"v\"`\n`import * as ns from \"mod\";`            | `\"mod\"`           | `\"*\"`          | `\"ns\"`         |\n`export * as ns from \"mod\";`            | `\"mod\"`           | `\"*\"`          | **null**       | `\"ns\"`\n`export * from \"mod\";`                  | `\"mod\"`           | `\"*\"`          | **null**       | **null** (many)\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-export-default-from","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftc39%2Fproposal-export-default-from","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-export-default-from/lists"}