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
Support circular dependencies with experimentalImportSupport (#1429)
Summary:
NOTE: This is an opt-in extension to `experimentalImportSupport`, this diff is a no-op by default.
Currently, `experimentalImportSupport` transforms named imports such that they're accessed immediately at the top level, eg:
```js
import {foo} from 'bar';
export function getFoo() {
return foo;
}
```
Becomes
```js
Object.defineProperty(exports, '__esModule', {
value: true
});
var foo = require('bar').foo;
function getFoo() {
return foo;
}
exports.getFoo = getFoo;
```
This immediate, top-level assignment of `require('bar').foo` to `foo` problematic for two reasons:
1. In the case of circular dependencies, the module at `'bar'` may not have been fully initialised, so that `foo` might be undefined at this point.
2. In the case where `bar` defines `export let foo = 'something mutable'`, a reassignment of `foo` within `'bar'` at runtime will not be reflected by the importing module.
This aims to fix 1 and get closer to a fix for 2. The new output would be:
```js
Object.defineProperty(exports, '__esModule', {
value: true
});
var _bar = require('bar');
function getFoo() {
return _bar.foo;
}
exports.getFoo = getFoo;
```
By lazily accessing values
Differential Revision: D68394514
0 commit comments