Add namespace re-export support to import-export plugin#1768
Open
robhogan wants to merge 1 commit into
Open
Conversation
Summary: Add static import/export plugin (`experimentalImportSupport`) support for namespace re-exports, i.e. `export * as Name from "module"`. This was added to Expo's fork in expo/expo#38055, (h/t krystofwoldrich). Despite this being perfectly valid syntax it currently fails to transform under `experimantalImportSupport`, with: ``` Cannot read properties of undefined (reading 'name') at <..>/metro-transform-plugins/src/import-export-plugin.js:289:67 ``` (On access of `local.name`, because this type of export has no `local` binding) ## Spec ECMA-262 includes namespace re-export syntax in the ExportDeclaration grammar: https://tc39.es/ecma262/#prod-ExportDeclaration ## Implementation Metro's existing `experimentalImportSupport` transform already has namespace import helper plumbing via `importAll`. This change reuses that helper and then emits an explicit export assignment for the namespace object, keeping the change isolated to the static transform path. ``` - **[Experimental]** Support `export * as Name from "module"` under `experimentalImportSupport` ``` Reviewed By: huntie Differential Revision: D111013905
Contributor
|
@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111013905. |
This file contains hidden or 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
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.
Summary:
Add static import/export plugin (
experimentalImportSupport) support for namespace re-exports, i.e.export * as Name from "module".This was added to Expo's fork in expo/expo#38055, (h/t @krystofwoldrich).
Despite this being perfectly valid syntax it currently fails to transform under
experimantalImportSupport, with:(On access of
local.name, because this type of export has nolocalbinding)Spec
ECMA-262 includes namespace re-export syntax in the ExportDeclaration grammar: https://tc39.es/ecma262/#prod-ExportDeclaration
Implementation
Metro's existing
experimentalImportSupporttransform already has namespace import helper plumbing viaimportAll. This change reuses that helper and then emits an explicit export assignment for the namespace object, keeping the change isolated to the static transform path.Reviewed By: huntie
Differential Revision: D111013905