Skip to content

Commit

Permalink
Move collectGeneratorReturn into core
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Jul 30, 2019
1 parent bfc608e commit 8377927
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11791,14 +11791,6 @@ namespace ts {
return result!.value as Type;
}

function collectGeneratorReturn<TYield, TStep, TReturn>(gen: Generator<TYield, TReturn, TStep>, feedforward: (yielded: TYield) => TStep): TReturn {
let result;
for (result = gen.next(); !result.done;) {
result = gen.next(feedforward(result.value as TYield));
}
return (result as IteratorReturnResult<TReturn>).value;
}

function getPermissiveInstantiation(type: Type) {
return type.flags & (TypeFlags.Primitive | TypeFlags.AnyOrUnknown | TypeFlags.Never) ? type :
type.permissiveInstantiation || (type.permissiveInstantiation = instantiateType(type, permissiveMapper));
Expand Down
10 changes: 10 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ namespace ts {
return result;
}


export function collectGeneratorReturn<TYield, TStep, TReturn>(gen: Generator<TYield, TReturn, TStep>, feedforward: (yielded: TYield) => TStep): TReturn {
let result;
for (result = gen.next(); !result.done;) {
result = gen.next(feedforward(result.value as TYield));
}
return (result as IteratorReturnResult<TReturn>).value;
}


// Maps from T to T and avoids allocation if all elements map to themselves
export function sameMap<T>(array: T[], f: (x: T, i: number) => T): T[];
export function sameMap<T>(array: ReadonlyArray<T>, f: (x: T, i: number) => T): ReadonlyArray<T>;
Expand Down

0 comments on commit 8377927

Please sign in to comment.