-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
browser.js
37 lines (32 loc) · 883 Bytes
/
browser.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
'use strict';
var callBound = require('call-bound');
var $then = callBound('Promise.prototype.then', true);
var pFalse = $then && Promise.resolve(false);
/** @type {() => false} */
var thunkFalse = function () {
return false;
};
/** @type {() => true} */
var thunkTrue = function () {
return true;
};
/** @type {() => PromiseLike<boolean>} */
module.exports = function hasDynamicImport() {
if (!$then) {
return {
__proto__: null,
// @ts-expect-error ts(2322) TODO: fixme
then: function (resolve) {
// @ts-expect-error ts(2723) TODO: fixme
resolve(false);
}
};
}
try {
var promise = Function('return import("data:text/javascript,")')(); // eslint-disable-line no-new-func
return $then(promise, thunkTrue, thunkFalse);
} catch (e) {
// eslint-disable-next-line no-extra-parens
return /** @type {NonNullable<typeof pFalse>} */ (pFalse);
}
};