generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for "optional" re-exports #30
Open
nicolo-ribaudo
wants to merge
9
commits into
tc39:main
Choose a base branch
from
nicolo-ribaudo:optional-exports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Mar 22, 2024
Closed
nicolo-ribaudo
added a commit
to nicolo-ribaudo/proposal-defer-import-eval
that referenced
this pull request
Mar 22, 2024
tc39#30 and tc39#31, that implement more general "optional/deferred re-exports" with tree-shaking capabilities, give two different meaning to `export defer * as x from "x"`: - in tc39#30, `export defer * as x from "x"` unconditionally loads `"x"`, and defers it's execution until when the namespace is used - in tc39#31, it only loads `x` if some module is actually importing `{ x }` from this one, and then defers its execution Due to this difference, for now it's better to remove `export defer *` until its semantics are settlet, together with the other `export defer`/ `export optional` cases. I will include a revert for this commit in those two PRs.
nicolo-ribaudo
added a commit
to nicolo-ribaudo/proposal-defer-import-eval
that referenced
this pull request
Mar 22, 2024
\tc39#30 and tc39#31, that implement more general "optional/deferred re-exports" with tree-shaking capabilities, give two different meaning to `export defer * as x from "x"`: - in tc39#30, `export defer * as x from "x"` unconditionally loads `"x"`, and defers it's execution until when the namespace is used - in tc39#31, it only loads `x` if some module is actually importing `{ x }` from this one, and then defers its execution Due to this difference, for now it's better to remove `export defer *` until its semantics are settlet, together with the other `export defer`/ `export optional` cases. I will include a revert for this commit in those two PRs.
This was referenced Mar 22, 2024
I really like this framing of a new keyword for The idea of a partial deferred namespace is very interesting and I remember Yulia wanting to see something like this in the past. Would be interesting to explore that design space further as well! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
See #31 for an alternative. Differences between the two PRs are marked with 🔎
This PR adds a new keyword for exports, 🔎
optional
, to markexport ... from
statements as three-shakeable. It has the following properties:export * from
cannot be optionaloptional
modifier is indipendent from modifier that affect how the imported module is represented, so all the following variations are valid:export optional * as x from "x"
- only loadx
if the consumer is importing it. Eagerly link/execute it and build the namespace object.export defer * as x from "x"
- always loadx
and its dependencies, eagerly execute it's asynchronous subgraphs, and only execute the rest on property access on the namespace objectexport optional defer * as x from "x"
- only loadx
if the consumer is importing it. If it gets loaded, eagerly execute it's asynchronous subgraphs, and only execute the rest on property access on the namespace object.export optional source x from "x"
- only loadx
if the consumer is importing it, and do so as defined in https://github.com/tc39/proposal-source-phase-importsAn optional re-export is considered to be used if the consumer of the module is:
import * as
(🔎 orimport defer * as
)import { ... }
and listing the optional bindingimport(...)
(🔎 orimport.defer(...)
)A follow-up proposal might introduce some syntax to mark which bindings will be used in namespace imports, such as
import { foo, bar } as partialNamespace from "x"
andimport("x", { bindings: ["foo", "bar"] })
.A bundler/transpiler can re-write optional re-exports to these exact semantics by moving them to the consumer module:
🔎
Rendered preview: https://nicolo-ribaudo.github.io/proposal-defer-import-eval/branch/optional-exports.html