-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[Transforms] Down-level transformations for Async Functions #9175
Changes from all commits
d506e92
88b38f8
aaf3ab7
c267691
83b4cbb
4ae83fa
e85d3e6
0948f73
8190666
3681e3c
4afb8c4
aa4662e
27931d5
ea61f2b
9073572
5e31b25
4eb2a82
278a350
c11b560
a858db6
4a16f65
393ee28
5b2e11c
48a9562
0c647c3
203dab4
644e4da
9e3d6f8
252cc25
c832444
c285767
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 |
---|---|---|
|
@@ -1638,7 +1638,7 @@ namespace ts { | |
} | ||
} | ||
|
||
function checkStrictModeNumericLiteral(node: LiteralExpression) { | ||
function checkStrictModeNumericLiteral(node: NumericLiteral) { | ||
if (inStrictMode && node.isOctalLiteral) { | ||
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode)); | ||
} | ||
|
@@ -1786,7 +1786,7 @@ namespace ts { | |
case SyntaxKind.DeleteExpression: | ||
return checkStrictModeDeleteExpression(<DeleteExpression>node); | ||
case SyntaxKind.NumericLiteral: | ||
return checkStrictModeNumericLiteral(<LiteralExpression>node); | ||
return checkStrictModeNumericLiteral(<NumericLiteral>node); | ||
case SyntaxKind.PostfixUnaryExpression: | ||
return checkStrictModePostfixUnaryExpression(<PostfixUnaryExpression>node); | ||
case SyntaxKind.PrefixUnaryExpression: | ||
|
@@ -2568,6 +2568,7 @@ namespace ts { | |
const modifierFlags = getModifierFlags(node); | ||
const body = node.body; | ||
const typeParameters = node.typeParameters; | ||
const asteriskToken = node.asteriskToken; | ||
|
||
// A MethodDeclaration is TypeScript syntax if it is either async, abstract, overloaded, | ||
// generic, or has a decorator. | ||
|
@@ -2578,6 +2579,11 @@ namespace ts { | |
transformFlags |= TransformFlags.AssertTypeScript; | ||
} | ||
|
||
// Currently, we only support generators that were originally async function bodies. | ||
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) { | ||
transformFlags |= TransformFlags.AssertGenerator; | ||
} | ||
|
||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; | ||
return transformFlags & ~TransformFlags.MethodOrAccessorExcludes; | ||
} | ||
|
@@ -2625,7 +2631,7 @@ namespace ts { | |
transformFlags = TransformFlags.AssertTypeScript; | ||
} | ||
else { | ||
transformFlags = subtreeFlags; | ||
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion; | ||
|
||
// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax. | ||
if (modifierFlags & ModifierFlags.Export) { | ||
|
@@ -2637,12 +2643,21 @@ namespace ts { | |
transformFlags |= TransformFlags.AssertTypeScript; | ||
} | ||
|
||
// If a FunctionDeclaration has an asterisk token, is exported, or its | ||
// subtree has marked the container as needing to capture the lexical `this`, | ||
// then this node is ES6 syntax. | ||
if (asteriskToken || (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask)) { | ||
// If a FunctionDeclaration's subtree has marked the container as needing to capture the | ||
// lexical this, or the function contains parameters with initializers, then this node is | ||
// ES6 syntax. | ||
if (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask) { | ||
transformFlags |= TransformFlags.AssertES6; | ||
} | ||
|
||
// If a FunctionDeclaration 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 (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) { | ||
transformFlags |= TransformFlags.AssertGenerator; | ||
} | ||
} | ||
|
||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; | ||
|
@@ -2659,12 +2674,22 @@ namespace ts { | |
transformFlags |= TransformFlags.AssertTypeScript; | ||
} | ||
|
||
// If a FunctionExpression contains an asterisk token, or its subtree has marked the container | ||
// as needing to capture the lexical this, then this node is ES6 syntax. | ||
if (asteriskToken || (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask)) { | ||
// If a FunctionExpression's subtree has marked the container as needing to capture the | ||
// lexical this, or the function contains parameters with initializers, then this node is | ||
// ES6 syntax. | ||
if (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask) { | ||
transformFlags |= TransformFlags.AssertES6; | ||
} | ||
|
||
// 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 (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) { | ||
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. how can this Also what happen to the case of 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.
In this case, we only add the flag if the generator was created as a result of an async function transformation. We do not down-level generators that are not the result of an async function transformation. |
||
transformFlags |= TransformFlags.AssertGenerator; | ||
} | ||
|
||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; | ||
return transformFlags & ~TransformFlags.FunctionExcludes; | ||
} | ||
|
@@ -2794,7 +2819,7 @@ namespace ts { | |
} | ||
|
||
function computeVariableDeclarationList(node: VariableDeclarationList, subtreeFlags: TransformFlags) { | ||
let transformFlags = subtreeFlags; | ||
let transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion; | ||
|
||
if (subtreeFlags & TransformFlags.ContainsBindingPattern) { | ||
transformFlags |= TransformFlags.AssertES6; | ||
|
@@ -2859,11 +2884,15 @@ namespace ts { | |
case SyntaxKind.TaggedTemplateExpression: | ||
case SyntaxKind.ShorthandPropertyAssignment: | ||
case SyntaxKind.ForOfStatement: | ||
case SyntaxKind.YieldExpression: | ||
// These nodes are ES6 syntax. | ||
transformFlags |= TransformFlags.AssertES6; | ||
break; | ||
|
||
case SyntaxKind.YieldExpression: | ||
// This node is ES6 syntax. | ||
transformFlags |= TransformFlags.AssertES6 | TransformFlags.ContainsYield; | ||
break; | ||
|
||
case SyntaxKind.AnyKeyword: | ||
case SyntaxKind.NumberKeyword: | ||
case SyntaxKind.NeverKeyword: | ||
|
@@ -2985,6 +3014,12 @@ namespace ts { | |
} | ||
|
||
break; | ||
|
||
case SyntaxKind.ReturnStatement: | ||
case SyntaxKind.ContinueStatement: | ||
case SyntaxKind.BreakStatement: | ||
transformFlags |= TransformFlags.ContainsHoistedDeclarationOrCompletion; | ||
break; | ||
} | ||
|
||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; | ||
|
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.
I think comment need to be updated?