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.
so this code will be added to react native itself?
There was a problem hiding this comment.
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.