Skip to content

Commit

Permalink
[Refactor] move new Function helper into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 22, 2025
1 parent dc929a5 commit db36da5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions getAsyncFunc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { AsyncFunction } from '.';

declare function getAsyncFunc(): AsyncFunction | false;

export = getAsyncFunc;
10 changes: 10 additions & 0 deletions getAsyncFunc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

/** @type {import('./getAsyncFunc')} */
module.exports = function () {
try {
return Function('return async function () {}')();
} catch (e) {
return false;
}
};
10 changes: 1 addition & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
var hasToStringTag = require('has-tostringtag/shams')();
var getProto = require('get-proto');

var getAsyncFunc = function () { // eslint-disable-line consistent-return
if (!hasToStringTag) {
return false;
}
try {
return Function('return async function () {}')();
} catch (e) {
}
};
var getAsyncFunc = require('./getAsyncFunc');

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

0 comments on commit db36da5

Please sign in to comment.