save code
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"globals": {
|
||||
"StopIteration": false,
|
||||
},
|
||||
|
||||
"rules": {
|
||||
"func-name-matching": [2, "always"],
|
||||
"id-length": 0,
|
||||
},
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 85.93,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Jordan Harband
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
|
||||
var $StopIteration = typeof StopIteration === 'object' ? StopIteration : null;
|
||||
|
||||
/** @type {import('.')} */
|
||||
module.exports = function getStopIterationIterator(origIterator) {
|
||||
if (!$StopIteration) {
|
||||
throw new $SyntaxError('this environment lacks StopIteration');
|
||||
}
|
||||
|
||||
SLOT.set(origIterator, '[[Done]]', false);
|
||||
|
||||
/** @template T @typedef {T extends Iterator<infer U> ? U : never} IteratorType */
|
||||
/** @typedef {IteratorType<ReturnType<typeof getStopIterationIterator>>} T */
|
||||
var siIterator = {
|
||||
next: /** @type {() => IteratorResult<T>} */ function next() {
|
||||
// eslint-disable-next-line no-extra-parens
|
||||
var iterator = /** @type {typeof origIterator} */ (SLOT.get(this, '[[Iterator]]'));
|
||||
var done = !!SLOT.get(iterator, '[[Done]]');
|
||||
try {
|
||||
return {
|
||||
done: done,
|
||||
// eslint-disable-next-line no-extra-parens
|
||||
value: done ? void undefined : /** @type {T} */ (iterator.next())
|
||||
};
|
||||
} catch (e) {
|
||||
SLOT.set(iterator, '[[Done]]', true);
|
||||
if (e !== $StopIteration) {
|
||||
throw e;
|
||||
}
|
||||
return {
|
||||
done: true,
|
||||
value: void undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SLOT.set(siIterator, '[[Iterator]]', origIterator);
|
||||
|
||||
// @ts-expect-error TODO FIXME
|
||||
return siIterator;
|
||||
};
|
||||
Reference in New Issue
Block a user