-
Notifications
You must be signed in to change notification settings - Fork 675
[rfc] Support import.meta with experimentalImportSupport #1494
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
base: main
Are you sure you want to change the base?
Conversation
|
What do you think about adding It's supported in both browsers and node, and would be a replacement for |
The plan is for RN (or Expo) to define properties using the Metro could define some more defaults though.. |
| __getImportMetaProperties: module => { | ||
| return { | ||
| url: new URL(String(module.id), 'metro://'), | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this code will be added to react native itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, similar to how the framework defines async imports, eg:
Currently, Metro leaves `import.meta` accesses untransformed, but provides no `import` pseudoglobal, so (unless polyfilled) this throws at runtime. `import.meta` is [specified](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-meta-properties) as a writable null-proto object. Though the spec is silent on any properties, it provides a mechanism ([`HostGetImportMetaProperties`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-hostgetimportmetaproperties)) for hosts to set properties, given a module object. Eg: `url`, `resolve` are defined by Node.js and browsers (and notably `env` by Vite). We emulate that mechanism here with the `__getImportMetaProperties(module) => {[key: string]: mixed}` optional, framework-defined global function.
Currently, Metro leaves
import.metaaccesses untransformed, but provides noimportpseudoglobal, so (unless polyfilled) this throws at runtime.import.metais specified as a writable null-proto object. Though the spec is silent on any properties, it provides a mechanism (HostGetImportMetaProperties) for hosts to set properties, given a module object. Eg:url,resolveare defined by Node.js and browsers (and notablyenvby Vite).We emulate that mechanism here with the
__getImportMetaProperties(module) => {[key: string]: mixed}optional, framework-defined global function.