Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAsync Iteration and down-level Generators #12346
Merged
Conversation
Closed
TonyPythoneer
commented
Feb 10, 2017
•
|
This PR is planed on |
|
@mhegazy, Is there anyone else you want to review this or should I merge? |
| ]; | ||
|
|
||
| var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) { | ||
| return { target: "lib." + source, sources: ["header.d.ts", source] }; | ||
| }); | ||
|
|
||
| var esnextLibrarySource = [ | ||
| "esnext.asynciterable.d.ts" |
This comment has been minimized.
This comment has been minimized.
src/compiler/comments.ts
Outdated
| @@ -272,7 +272,7 @@ namespace ts { | |||
|
|
|||
| function forEachLeadingCommentToEmit(pos: number, cb: (commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) => void) { | |||
| // Emit the leading comments only if the container's pos doesn't match because the container should take care of emitting these comments | |||
| if (containerPos === -1 || pos !== containerPos) { | |||
| if ((containerPos === -1 || pos !== containerPos)) { | |||
This comment has been minimized.
This comment has been minimized.
src/compiler/comments.ts
Outdated
| @@ -284,7 +284,7 @@ namespace ts { | |||
|
|
|||
| function forEachTrailingCommentToEmit(end: number, cb: (commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean) => void) { | |||
| // Emit the trailing comments only if the container's end doesn't match because the container should take care of emitting these comments | |||
| if (containerEnd === -1 || (end !== containerEnd && end !== declarationListContainerEnd)) { | |||
| if ((containerEnd === -1 || (end !== containerEnd && end !== declarationListContainerEnd))) { | |||
This comment has been minimized.
This comment has been minimized.
src/compiler/checker.ts
Outdated
| @@ -21132,7 +21287,7 @@ namespace ts { | |||
| function checkExternalEmitHelpers(location: Node, helpers: ExternalEmitHelpers) { | |||
| if ((requestedExternalEmitHelpers & helpers) !== helpers && compilerOptions.importHelpers) { | |||
| const sourceFile = getSourceFileOfNode(location); | |||
| if (isEffectiveExternalModule(sourceFile, compilerOptions)) { | |||
| if (!isDeclarationFile(sourceFile) && isEffectiveExternalModule(sourceFile, compilerOptions)) { | |||
This comment has been minimized.
This comment has been minimized.
mhegazy
Feb 17, 2017
why do you need this here, should not the new helpers only be visible in expressions?
This comment has been minimized.
This comment has been minimized.
This was referenced Apr 20, 2017
Closed
jocull
commented
May 30, 2017
|
Just curious, why is the |
mhegazy
commented
May 30, 2017
it is, just use |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
rbuckton commentedNov 18, 2016
•
edited
This PR adds full support for Async Generators and Async Iteration (
for..await..of) as per the current TC39 Proposal for all script targets. It also contains full support for Generators in ES5/3, includingfor..of, spread, and iterator destructuring.Iterators
ES6 introduced
Iterator, which is an object that exposes three methods,next,return, andthrow, as per the following interface:This kind of iterator is useful for iterating over synchronously available values, such as the elements of an Array or the keys of a Map. An object that supports iteration is said to be "iterable" if it has a
Symbol.iteratormethod that returns anIteratorobject.Async Iterators
The Async Iteration proposal introduces an
AsyncIterator, which is similar toIterator. The difference lies in the fact that thenext,return, andthrowmethods of anAsyncIteratorreturn aPromisefor the iteration result, rather than the result itself. This allows the caller to enlist in an asynchronous notification for the time at which theAsyncIteratorhas advanced to the point of yielding a value. AnAsyncIteratorhas the following shape:An object that supports async iteration is said to be "iterable" if it has a
Symbol.asyncIteratormethod that returns anAsyncIteratorobject.Generators
ES6 also introduced "Generators", which are functions that can be used to yield partial computation results via the
Iteratorinterface and theyieldkeyword. Generators can also internally delegate calls to another iterable throughyield *. For example:Async Generators
The Async Iteration proposal introduces "Async Generators", which are async functions that also can be used to yield partial computation results. Async Generators can also delegate calls via
yield*to either an iterable or async iterable:As with Generators, Async Generators can only be function declarations, function expressions, or methods of classes or object literals. Arrow functions cannot be Async Generators. Async Generators require a valid, global
Promiseimplementation (either native or an ES6-compatible polyfill), in addition to a validSymbol.asyncIteratorreference (either a native symbol or a shim).The
for-await-ofStatementFinally, ES6 introduced the
for..ofstatement as a means of iterating over an iterable. Similarly, the Async Iteration proposal introduces thefor..await..ofstatement to iterate over an async iterable:The
for..await..ofstatement is only legal within an Async Function or Async Generator.Generators and Iteration for ES5/3
In addition, the following changes are included to bring full support for Generators to ES5/ES3:
-downlevelIterationcompiler option, used when targeting ES5 or ES3.[Symbol.iterator]()method on the iterated object if it is found, and creates a synthetic array iterator over the object if it is not. This requires a nativeSymbol.iteratororSymbol.iteratorshim at runtime for any non-array values.for..ofare only supported for arrays as is the current behavior in TypeScript 2.1 and earlier.Symbol.iteratorin ES5/3 if available when using-downlevelIteration, but can be used on an Array even if it does not defineSymbol.iteratorat run time or design time.Symbol.iteratorin ES5/3 if available when using-downlevelIteration, but can be used on Array even if it does not defineSymbol.iteratorat run time or design time.for..ofstatements supportSymbol.iteratorin ES5/3 if available when using-downlevelIteration, but can be used on an Array even if it does not defineSymbol.iteratorat run time or design time.Symbol.iteratorpolyfill at run time to operate.Related issues