MCPcopy Index your code
hub / github.com/nodejs/node / getIterationTypesOfIteratorFast

Function getIterationTypesOfIteratorFast

test/fixtures/snapshot/typescript.js:83405–83427  ·  view source on GitHub ↗

* Gets the iteration types of an `Iterator`-like or `AsyncIterator`-like type from the * cache or from common heuristics. * * If we previously analyzed this type and found no iteration types, `noIterationTypes` is * returned. If we found iteration types, an `Itera

(type, resolver)

Source from the content-addressed store, hash-verified

83403 * `getIterationTypesOfIterator` instead.
83404 */
83405 function getIterationTypesOfIteratorFast(type, resolver) {
83406 // As an optimization, if the type is an instantiation of one of the following global types,
83407 // then just grab its related type argument:
83408 // - `IterableIterator<T>` or `AsyncIterableIterator<T>`
83409 // - `Iterator<T, TReturn, TNext>` or `AsyncIterator<T, TReturn, TNext>`
83410 // - `Generator<T, TReturn, TNext>` or `AsyncGenerator<T, TReturn, TNext>`
83411 var globalType = resolver.getGlobalIterableIteratorType(/*reportErrors*/ false);
83412 if (isReferenceToType(type, globalType)) {
83413 var yieldType = getTypeArguments(type)[0];
83414 // The "return" and "next" types of `IterableIterator` and `AsyncIterableIterator` are defined by the
83415 // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
83416 // and `undefined` in our libs by default, a custom lib *could* use different definitions.
83417 var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
83418 getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
83419 var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
83420 return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
83421 }
83422 if (isReferenceToType(type, resolver.getGlobalIteratorType(/*reportErrors*/ false)) ||
83423 isReferenceToType(type, resolver.getGlobalGeneratorType(/*reportErrors*/ false))) {
83424 var _b = getTypeArguments(type), yieldType = _b[0], returnType = _b[1], nextType = _b[2];
83425 return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
83426 }
83427 }
83428 function isIteratorResult(type, kind) {
83429 // From https://tc39.github.io/ecma262/#sec-iteratorresult-interface:
83430 // > [done] is the result status of an iterator `next` method call. If the end of the iterator was reached `done` is `true`.

Callers 1

Calls 6

isReferenceToTypeFunction · 0.85
getTypeArgumentsFunction · 0.85
setCachedIterationTypesFunction · 0.85
createIterationTypesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…