Skip to content

Commit db36da5

Browse files
committed
[Refactor] move new Function helper into a separate file
1 parent dc929a5 commit db36da5

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

getAsyncFunc.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { AsyncFunction } from '.';
2+
3+
declare function getAsyncFunc(): AsyncFunction | false;
4+
5+
export = getAsyncFunc;

getAsyncFunc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
/** @type {import('./getAsyncFunc')} */
4+
module.exports = function () {
5+
try {
6+
return Function('return async function () {}')();
7+
} catch (e) {
8+
return false;
9+
}
10+
};

index.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
1010
var hasToStringTag = require('has-tostringtag/shams')();
1111
var getProto = require('get-proto');
1212

13-
var getAsyncFunc = function () { // eslint-disable-line consistent-return
14-
if (!hasToStringTag) {
15-
return false;
16-
}
17-
try {
18-
return Function('return async function () {}')();
19-
} catch (e) {
20-
}
21-
};
13+
var getAsyncFunc = require('./getAsyncFunc');
2214

2315
/** @type {import('.').AsyncFunction | false} */
2416
var AsyncFunction;

0 commit comments

Comments
 (0)