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 "defer" re-exports #31
Open
nicolo-ribaudo
wants to merge
10
commits into
tc39:main
Choose a base branch
from
nicolo-ribaudo:deferred-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.
Open
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
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 #30 for an alternative. Differences between the two PRs are marked with 🔎
This PR extends the 🔎
defer
keyword to named re-exports, with the following properties:export * from
cannot be deferreddefer
keyword withexport * as x from "x"
, it modifies both theexport
(by only loading"x"
if the consumer imports thex
binding) and the implicitimport
(by creating a deferred namespace object, and only evaluating"x"
when accessing properties on it)export defer source x from "..."
could be supported for the three-shaking semantics, but it might be confusing becausedefer
andsource
in all other places represent two alternative phases of the same load->link->execute pipeline.An optional re-export is considered to be used if the consumer of the module is:
import * as
import { ... }
and listing the optional bindingimport(...)
🔎 If the consumer module is importing with
import defer * as
orimport.defer(...)
, optional re-exports are preloaded but not evaluated until when the corresponding binding is accessed on the namespace object (async subgraphs are still pre-evaluated).A bundler/transpiler can re-write deferred 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/deferred-exports.html