[deferred-reexports] Add `import { x, y } as ns` support by nicolo-ribaudo · Pull Request #340 · estree/estree · GitHub
Skip to content

[deferred-reexports] Add import { x, y } as ns support - #340

Open
nicolo-ribaudo wants to merge 2 commits into
estree:masterfrom
nicolo-ribaudo:deferred-reexports-filtered-namespaces
Open

nicolo-ribaudo wants to merge 2 commits into
estree:masterfrom
nicolo-ribaudo:deferred-reexports-filtered-namespaces

Conversation

@nicolo-ribaudo

Copy link
Copy Markdown
Contributor

This is adding AST for this syntax:

import { x, y } as ns from "foo";

introduced by https://tc39.es/proposal-deferred-reexports/#sec-imports. More info is in the TC39 presentation that introduced the syntax: https://docs.google.com/presentation/d/1uYgMUqz5bZT3wwPARnyq7GrJlWFesIrmoCJA1iDH3W8/edit?slide=id.g3965d76ffd6_0_22#slide=id.g3965d76ffd6_0_22

I also need to add support for export { x, y } as ns from "foo", however depending on the outcome of #339 I see two possible options. If we reuse ImportNamespaceSpecifier for export * as ns from "x" then there is nothing to do, otherwise if the ExportAllDeclaration gets a .specifier: Identifier | Literal field, I'd also add it to ExportNamedDeclaration for this proposal.

@nicolo-ribaudo nicolo-ribaudo Aug 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the name here I'd align with whatever the outcome of tc39/proposal-deferred-reexports#39 is (and you are welcome to share opinions :) )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exportsFilter, or simply filter, both look good to me.

Will import { foo as bar } as ns from "./lib" ever be a thing? If so I suggest we use ImportSpecifier for exportsFilter.

The current proposed structure serves the current proposal well, but if there is ever a proposal extending the current syntax, there is not much room to nicely extend.

@nicolo-ribaudo nicolo-ribaudo Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into this again, and there are no plans for foo as bar as it has significant implementation complexity without benefits (aliasing exists to avoid conflict when importing the same name from multiple modules, which doesn't apply here). It's however good to allow extensibility just in case, and so that I can produce a nice AST in Babel's error recovery mode :)

If we want to use a node, ImportSpecifier doesn't really work: because the "local" part can be a string here (import { "str" } as ns from "x"). I could use ExportSpecifier maybe? Even though the exported property name doesn't really work. Or we introduce a new node type (NamespaceFilterSpecifier) like ImportSpecifier but that has only .imported and no .local.

Regarding the name, the proposal ended up with exports for dynamic import (import("foo", { exports: ["a", "b"] }). I think I still prefer to call the AST property exportsFilter, for clarity.

@JLHwung JLHwung Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. If future extensibility is not the plan, then I am good with the current design. As for Babel's error recovery, we could still try to parse an Importspecifier if we see as after the exportsFilter, without the specifier wrapper.

@nicolo-ribaudo nicolo-ribaudo changed the title [deferred-reexports] Add import namespace filter [deferred-reexports] Add import { x, y } as ns support Aug 7, 2026
Comment thread experimental/deferred-reexports.md Outdated
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants