Skip to content

Commit 5477ff1

Browse files
committed
[Refactor] use generator-function
1 parent 2ac26fe commit 5477ff1

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

index.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@ var getProto = require('get-proto');
99
var toStr = callBound('Object.prototype.toString');
1010
var fnToStr = callBound('Function.prototype.toString');
1111

12-
var getGeneratorFunc = function () { // eslint-disable-line consistent-return
13-
if (!hasToStringTag) {
14-
return false;
15-
}
16-
try {
17-
return Function('return function*() {}')();
18-
} catch (e) {
19-
}
20-
};
21-
/** @type {undefined | false | null | GeneratorFunctionConstructor} */
22-
var GeneratorFunction;
12+
var getGeneratorFunction = require('generator-function');
2313

2414
/** @type {import('.')} */
2515
module.exports = function isGeneratorFunction(fn) {
@@ -36,12 +26,6 @@ module.exports = function isGeneratorFunction(fn) {
3626
if (!getProto) {
3727
return false;
3828
}
39-
if (typeof GeneratorFunction === 'undefined') {
40-
var generatorFunc = getGeneratorFunc();
41-
GeneratorFunction = generatorFunc
42-
// eslint-disable-next-line no-extra-parens
43-
? /** @type {GeneratorFunctionConstructor} */ (getProto(generatorFunc))
44-
: false;
45-
}
46-
return getProto(fn) === GeneratorFunction;
29+
var GeneratorFunction = getGeneratorFunction();
30+
return GeneratorFunction && getProto(fn) === GeneratorFunction;
4731
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"dependencies": {
4646
"call-bound": "^1.0.3",
47+
"generator-function": "^2.0.0",
4748
"get-proto": "^1.0.0",
4849
"has-tostringtag": "^1.0.2",
4950
"safe-regex-test": "^1.1.0"

0 commit comments

Comments
 (0)