-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
47 lines (42 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
var callBound = require('call-bound');
var callBind = require('call-bind');
var GetIntrinsic = require('get-intrinsic');
var $then = callBound('Promise.prototype.then', true);
var $Promise = GetIntrinsic('%Promise%', true);
var $PromiseResolve = GetIntrinsic('%Promise.resolve%', true);
var $resolve = $Promise && $PromiseResolve && $then && callBind($PromiseResolve, $Promise);
/** @type {() => false} */
var thunkFalse = function () {
return false;
};
/** @type {() => true} */
var thunkTrue = function () {
return true;
};
/** @type {() => PromiseLike<boolean>} */
module.exports = function hasDynamicImport() {
if (!$then) {
/** @type {PromiseLike<boolean>} */
return {
__proto__: null,
// @ts-expect-error ts(2322) TODO: fixme
then: function (resolve) { // eslint-disable-line consistent-return
if (typeof resolve === 'function') {
process.nextTick(function () {
resolve(false);
});
} else {
return hasDynamicImport();
}
}
};
}
try {
var importWrapper = require('./import'); // eslint-disable-line global-require
return $then(importWrapper(), thunkTrue, thunkFalse);
} catch (e) {
// eslint-disable-next-line no-extra-parens
return /** @type {Promise<false>} */ (/** @type {NonNullable<typeof $resolve>} */ ($resolve)(false));
}
};