save code

This commit is contained in:
xsl
2026-01-26 08:04:53 +08:00
parent 0895398138
commit e4b59c5ee4
1238 changed files with 95107 additions and 1068 deletions
+16
View File
@@ -0,0 +1,16 @@
{
"root": true,
"extends": "@ljharb",
"overrides": [
{
"files": "./index.js",
"extends": "@ljharb/eslint-config/node/8"
},
{
"files": "./require.mjs",
"extends": "@ljharb/eslint-config/node/16",
},
],
}
+9
View File
@@ -0,0 +1,9 @@
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
+8
View File
@@ -0,0 +1,8 @@
'use strict';
// eslint-disable-next-line no-extra-parens, no-empty-function
const cached = /** @type {GeneratorFunctionConstructor} */ (function* () {}.constructor);
/** @type {import('.')} */
module.exports = () => cached;
+18
View File
@@ -0,0 +1,18 @@
'use strict';
/** @type {GeneratorFunctionConstructor | false} */
var cached;
/** @type {import('./index.js')} */
module.exports = function getGeneratorFunction() {
if (typeof cached === 'undefined') {
try {
// eslint-disable-next-line no-new-func
cached = Function('return function* () {}')().constructor;
} catch (e) {
cached = false;
}
}
return cached;
};
View File
+42
View File
@@ -0,0 +1,42 @@
'use strict';
var test = require('tape');
var getProto = require('get-proto');
var semver = require('semver');
var getGeneratorFunction = require('generator-function');
test('getGeneratorFunction', function (t) {
var result = getGeneratorFunction();
/* eslint-env browser */
if (typeof window === 'undefined' && typeof process !== 'undefined') {
t.equal(
!!result,
semver.satisfies(process.version, '>= 1'),
'result is present or absent as expected for node ' + process.version
);
}
t.test('exists', { skip: !result }, function (st) {
if (result && getProto) { // TS can't infer `skip`, or that getProto definitely exists if GeneratorFunction exists
st.equal(typeof result, 'function', 'is a function');
st.equal(getProto(result), Function, 'extends Function');
var iterator = result('a', 'return a')(42);
st.deepEqual(iterator.next(), { value: 42, done: true }, 'returns a generator function which returns an iterator');
} else {
st.fail('should never get here');
}
st.end();
});
t.test('does not exist', { skip: !!result }, function (st) {
st.equal(result, false, 'is false');
st.end();
});
t.end();
});