You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pass globalPrefix through to serializer and expose to getRunModuleStatement (#1566)
Summary:
Pull Request resolved: #1566
To allow prefixing the global function `__r` (e.g., #1512), expose the prefix to the configured [`getRunModuleStatement`](https://metrobundler.dev/docs/configuration/#getrunmodulestatement), which returns the `__r()` call as a string.
```
- **[Feature]** Expose `globalPrefix` to `getRunModuleStatement`
```
## Alternative? Runtime prefixing
We could alternatively add prefix at runtime by emitting:
```
"globalThis[__METRO_GLOBAL_PREFIX__ + '__r'](/*...*/)"
```
There are a couple of downsides -
- These runModule statements are currently outside IIFEs that inject `global` based on (something like) `global = globalThis ?? global ?? window` - we don't rely on the existence of `globalThis` elsewhere (though it's probably safe to now - that's a separate breaking change).
- Concatenation/interpolation + object access is more verbose and slightly slower, and there's just no need for it in code emitted by Metro itself (as opposed to framework/userland code, which must use it).
Reviewed By: huntie
Differential Revision: D81476621
fbshipit-source-id: 90641cf21491711c56606131ec4c5797b7b00020
0 commit comments