-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async Iteration and down-level Generators #12346
Changes from 46 commits
6453fde
86091d7
a2e0b19
fea6827
cb85356
c6ee25d
74ec093
bd86778
549ac8f
b5cc96c
4b5686a
4f3fb80
a4036c7
ab1dc52
d6a5e39
28d23ce
df303c9
e53263e
42085a6
c758359
281c890
1af8ac8
1c0917a
2f6ac58
c72509b
32bcc97
38b7757
1980334
8af87dc
87eeb57
b0faa92
0d7c9dc
6a737c8
30aff2f
5e0160b
2e62d5e
35ef1f7
f9999e9
74498bb
21bf485
5d415ca
64be1f2
56a360c
94b37b1
5ca6665
e1f8be5
3e427f4
dedf4a7
344a9d2
cf72ceb
11f58ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,13 +311,21 @@ var es2016LibrarySourceMap = es2016LibrarySource.map(function (source) { | |
var es2017LibrarySource = [ | ||
"es2017.object.d.ts", | ||
"es2017.sharedmemory.d.ts", | ||
"es2017.string.d.ts", | ||
"es2017.string.d.ts" | ||
]; | ||
|
||
var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) { | ||
return { target: "lib." + source, sources: ["header.d.ts", source] }; | ||
}); | ||
|
||
var esnextLibrarySource = [ | ||
"esnext.asynciterable.d.ts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to update VS setup to include this file as well. |
||
]; | ||
|
||
var esnextLibrarySourceMap = esnextLibrarySource.map(function (source) { | ||
return { target: "lib." + source, sources: ["header.d.ts", source] }; | ||
}); | ||
|
||
var hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"]; | ||
|
||
var librarySourceMap = [ | ||
|
@@ -332,11 +340,12 @@ var librarySourceMap = [ | |
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] }, | ||
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] }, | ||
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] }, | ||
{ target: "lib.esnext.d.ts", sources: ["header.d.ts", "esnext.d.ts"] }, | ||
|
||
// JavaScript + all host library | ||
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) }, | ||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") } | ||
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap); | ||
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap); | ||
|
||
var libraryTargets = librarySourceMap.map(function (f) { | ||
return path.join(builtLocalDirectory, f.target); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -956,6 +956,9 @@ namespace ts { | |
const postLoopLabel = createBranchLabel(); | ||
addAntecedent(preLoopLabel, currentFlow); | ||
currentFlow = preLoopLabel; | ||
if (node.kind === SyntaxKind.ForOfStatement) { | ||
bind(node.awaitModifier); | ||
} | ||
bind(node.expression); | ||
addAntecedent(postLoopLabel, currentFlow); | ||
bind(node.initializer); | ||
|
@@ -2331,7 +2334,7 @@ namespace ts { | |
|
||
function bindFunctionDeclaration(node: FunctionDeclaration) { | ||
if (!isDeclarationFile(file) && !isInAmbientContext(node)) { | ||
if (isAsyncFunctionLike(node)) { | ||
if (isAsyncFunction(node)) { | ||
emitFlags |= NodeFlags.HasAsyncFunctions; | ||
} | ||
} | ||
|
@@ -2348,7 +2351,7 @@ namespace ts { | |
|
||
function bindFunctionExpression(node: FunctionExpression) { | ||
if (!isDeclarationFile(file) && !isInAmbientContext(node)) { | ||
if (isAsyncFunctionLike(node)) { | ||
if (isAsyncFunction(node)) { | ||
emitFlags |= NodeFlags.HasAsyncFunctions; | ||
} | ||
} | ||
|
@@ -2362,7 +2365,7 @@ namespace ts { | |
|
||
function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { | ||
if (!isDeclarationFile(file) && !isInAmbientContext(node)) { | ||
if (isAsyncFunctionLike(node)) { | ||
if (isAsyncFunction(node)) { | ||
emitFlags |= NodeFlags.HasAsyncFunctions; | ||
} | ||
} | ||
|
@@ -2796,11 +2799,10 @@ namespace ts { | |
|
||
// An async method declaration is ES2017 syntax. | ||
if (hasModifier(node, ModifierFlags.Async)) { | ||
transformFlags |= TransformFlags.AssertES2017; | ||
transformFlags |= node.asteriskToken ? TransformFlags.AssertESNext : TransformFlags.AssertES2017; | ||
} | ||
|
||
// Currently, we only support generators that were originally async function bodies. | ||
if (node.asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) { | ||
if (node.asteriskToken) { | ||
transformFlags |= TransformFlags.AssertGenerator; | ||
} | ||
|
||
|
@@ -2866,7 +2868,7 @@ namespace ts { | |
|
||
// An async function declaration is ES2017 syntax. | ||
if (modifierFlags & ModifierFlags.Async) { | ||
transformFlags |= TransformFlags.AssertES2017; | ||
transformFlags |= node.asteriskToken ? TransformFlags.AssertESNext : TransformFlags.AssertES2017; | ||
} | ||
|
||
// function declarations with object rest destructuring are ES Next syntax | ||
|
@@ -2886,7 +2888,7 @@ namespace ts { | |
// down-level generator. | ||
// Currently we do not support transforming any other generator fucntions | ||
// down level. | ||
if (node.asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) { | ||
if (node.asteriskToken) { | ||
transformFlags |= TransformFlags.AssertGenerator; | ||
} | ||
} | ||
|
@@ -2908,7 +2910,7 @@ namespace ts { | |
|
||
// An async function expression is ES2017 syntax. | ||
if (hasModifier(node, ModifierFlags.Async)) { | ||
transformFlags |= TransformFlags.AssertES2017; | ||
transformFlags |= node.asteriskToken ? TransformFlags.AssertESNext : TransformFlags.AssertES2017; | ||
} | ||
|
||
// function expressions with object rest destructuring are ES Next syntax | ||
|
@@ -2927,9 +2929,7 @@ namespace ts { | |
// If a FunctionExpression is generator function and is the body of a | ||
// transformed async function, then this node can be transformed to a | ||
// down-level generator. | ||
// Currently we do not support transforming any other generator fucntions | ||
// down level. | ||
if (node.asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) { | ||
if (node.asteriskToken) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment on line 2922-2926 #Closed |
||
transformFlags |= TransformFlags.AssertGenerator; | ||
} | ||
|
||
|
@@ -3097,8 +3097,8 @@ namespace ts { | |
switch (kind) { | ||
case SyntaxKind.AsyncKeyword: | ||
case SyntaxKind.AwaitExpression: | ||
// async/await is ES2017 syntax | ||
transformFlags |= TransformFlags.AssertES2017; | ||
// async/await is ES2017 syntax, but may be ESNext syntax (for async generators) | ||
transformFlags |= TransformFlags.AssertESNext | TransformFlags.AssertES2017; | ||
break; | ||
|
||
case SyntaxKind.PublicKeyword: | ||
|
@@ -3129,10 +3129,6 @@ namespace ts { | |
transformFlags |= TransformFlags.AssertJsx; | ||
break; | ||
|
||
case SyntaxKind.ForOfStatement: | ||
// for-of might be ESNext if it has a rest destructuring | ||
transformFlags |= TransformFlags.AssertESNext; | ||
// FALLTHROUGH | ||
case SyntaxKind.NoSubstitutionTemplateLiteral: | ||
case SyntaxKind.TemplateHead: | ||
case SyntaxKind.TemplateMiddle: | ||
|
@@ -3146,9 +3142,18 @@ namespace ts { | |
transformFlags |= TransformFlags.AssertES2015; | ||
break; | ||
|
||
case SyntaxKind.ForOfStatement: | ||
// This node is either ES2015 syntax or ES2017 syntax (if it is a for-await-of). | ||
if ((<ForOfStatement>node).awaitModifier) { | ||
transformFlags |= TransformFlags.AssertESNext; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about rest destructuring? Is that no longer handled by the ESNext transformer? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way that the esnext transformer works now is to always descend through the tree if some node is marked |
||
} | ||
transformFlags |= TransformFlags.AssertES2015; | ||
break; | ||
|
||
case SyntaxKind.YieldExpression: | ||
// This node is ES6 syntax. | ||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsYield; | ||
// This node is either ES2015 syntax (in a generator) or ES2017 syntax (in an async | ||
// generator). | ||
transformFlags |= TransformFlags.AssertESNext | TransformFlags.AssertES2015 | TransformFlags.ContainsYield; | ||
break; | ||
|
||
case SyntaxKind.AnyKeyword: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use an arrow function here? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency with the surrounding code.