Proposal: use ref(() => Map) instead of ref('Map')
- Dominant language
- JavaScript
- Stars
- 797
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
This is a:
- [ ] Bug Report
- [ ] Feature Request
- [x] Question
- [ ] Other
Which concerns:
- [x] flow-runtime
- [x] babel-plugin-flow-runtime
- [ ] flow-runtime-validators
- [ ] flow-runtime-mobx
- [ ] flow-config-parser
- [ ] The documentation website
---
### Using`ref` with the name of a type as a string is fundamentally problematic
Because the babel module transform mangles the names of imports. It has to because it can't know at compile time if the value of an export will change, because of circular imports, etc.
So any code that `babel-plugin-flow-runtime` converts to `ref('Map')` will break if `Map` comes from `import Map from '...'` because that import will get transpiled to
```
var _map = require('...')
var _map2 = _iteropRequireDefault(_map)
```
(see #177)
I think the best way to get around this would be to use a function instead of a string: `ref(() => Map)`. That way it can still be evaluated at runtime, but babel's module transform will convert that to `ref(() => _map2.default)`, so it won't break.
@phpnode thoughts?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.