massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / is-constructor.js
1 var uncurryThis = require('../internals/function-uncurry-this');
2 var fails = require('../internals/fails');
3 var isCallable = require('../internals/is-callable');
4 var classof = require('../internals/classof');
5 var getBuiltIn = require('../internals/get-built-in');
6 var inspectSource = require('../internals/inspect-source');
7
8 var noop = function () { /* empty */ };
9 var empty = [];
10 var construct = getBuiltIn('Reflect', 'construct');
11 var constructorRegExp = /^\s*(?:class|function)\b/;
12 var exec = uncurryThis(constructorRegExp.exec);
13 var INCORRECT_TO_STRING = !constructorRegExp.exec(noop);
14
15 var isConstructorModern = function (argument) {
16   if (!isCallable(argument)) return false;
17   try {
18     construct(noop, empty, argument);
19     return true;
20   } catch (error) {
21     return false;
22   }
23 };
24
25 var isConstructorLegacy = function (argument) {
26   if (!isCallable(argument)) return false;
27   switch (classof(argument)) {
28     case 'AsyncFunction':
29     case 'GeneratorFunction':
30     case 'AsyncGeneratorFunction': return false;
31     // we can't check .prototype since constructors produced by .bind haven't it
32   } return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource(argument));
33 };
34
35 // `IsConstructor` abstract operation
36 // https://tc39.es/ecma262/#sec-isconstructor
37 module.exports = !construct || fails(function () {
38   var called;
39   return isConstructorModern(isConstructorModern.call)
40     || !isConstructorModern(Object)
41     || !isConstructorModern(function () { called = true; })
42     || called;
43 }) ? isConstructorLegacy : isConstructorModern;