Skip to content

Commit 5d52c9f

Browse files
committed
Move async/await into separate es2017 transformer
1 parent f42c791 commit 5d52c9f

File tree

15 files changed

+614
-243
lines changed

15 files changed

+614
-243
lines changed

Jakefile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var compilerSources = [
7474
"transformers/module/system.ts",
7575
"transformers/module/module.ts",
7676
"transformers/jsx.ts",
77+
"transformers/es2017.ts",
7778
"transformers/es2016.ts",
7879
"transformers/generators.ts",
7980
"transformers/es6.ts",
@@ -108,6 +109,7 @@ var servicesSources = [
108109
"transformers/module/system.ts",
109110
"transformers/module/module.ts",
110111
"transformers/jsx.ts",
112+
"transformers/es2017.ts",
111113
"transformers/es2016.ts",
112114
"transformers/generators.ts",
113115
"transformers/es6.ts",

src/compiler/binder.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,11 @@ namespace ts {
25552555
// extends clause of a class.
25562556
let transformFlags = subtreeFlags | TransformFlags.AssertES6;
25572557

2558+
// propagate ES2017
2559+
if (node.expression.transformFlags & TransformFlags.ContainsES2017) {
2560+
transformFlags |= TransformFlags.ContainsES2017;
2561+
}
2562+
25582563
// If an ExpressionWithTypeArguments contains type arguments, then it
25592564
// is TypeScript syntax.
25602565
if (node.typeArguments) {
@@ -2595,6 +2600,11 @@ namespace ts {
25952600
transformFlags |= TransformFlags.AssertTypeScript;
25962601
}
25972602

2603+
// Async MethodDeclaration is ES2017
2604+
if (modifierFlags & ModifierFlags.Async) {
2605+
transformFlags |= TransformFlags.AssertES2017;
2606+
}
2607+
25982608
// Currently, we only support generators that were originally async function bodies.
25992609
if (asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) {
26002610
transformFlags |= TransformFlags.AssertGenerator;
@@ -2656,7 +2666,7 @@ namespace ts {
26562666

26572667
// If a FunctionDeclaration is async, then it is TypeScript syntax.
26582668
if (modifierFlags & ModifierFlags.Async) {
2659-
transformFlags |= TransformFlags.AssertTypeScript;
2669+
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
26602670
}
26612671

26622672
// If a FunctionDeclaration's subtree has marked the container as needing to capture the
@@ -2687,7 +2697,7 @@ namespace ts {
26872697

26882698
// An async function expression is TypeScript syntax.
26892699
if (modifierFlags & ModifierFlags.Async) {
2690-
transformFlags |= TransformFlags.AssertTypeScript;
2700+
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
26912701
}
26922702

26932703
// If a FunctionExpression's subtree has marked the container as needing to capture the
@@ -2717,7 +2727,7 @@ namespace ts {
27172727

27182728
// An async arrow function is TypeScript syntax.
27192729
if (modifierFlags & ModifierFlags.Async) {
2720-
transformFlags |= TransformFlags.AssertTypeScript;
2730+
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
27212731
}
27222732

27232733
// If an ArrowFunction contains a lexical this, its container must capture the lexical this.
@@ -2856,14 +2866,18 @@ namespace ts {
28562866
let excludeFlags = TransformFlags.NodeExcludes;
28572867

28582868
switch (kind) {
2869+
case SyntaxKind.AsyncKeyword:
2870+
case SyntaxKind.AwaitExpression:
2871+
// Typescript async/await are ES2017 features
2872+
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
2873+
break;
2874+
28592875
case SyntaxKind.PublicKeyword:
28602876
case SyntaxKind.PrivateKeyword:
28612877
case SyntaxKind.ProtectedKeyword:
28622878
case SyntaxKind.AbstractKeyword:
28632879
case SyntaxKind.DeclareKeyword:
2864-
case SyntaxKind.AsyncKeyword:
28652880
case SyntaxKind.ConstKeyword:
2866-
case SyntaxKind.AwaitExpression:
28672881
case SyntaxKind.EnumDeclaration:
28682882
case SyntaxKind.EnumMember:
28692883
case SyntaxKind.TypeAssertionExpression:

src/compiler/transformer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="visitor.ts" />
22
/// <reference path="transformers/ts.ts" />
33
/// <reference path="transformers/jsx.ts" />
4+
/// <reference path="transformers/es2017.ts" />
45
/// <reference path="transformers/es2016.ts" />
56
/// <reference path="transformers/es6.ts" />
67
/// <reference path="transformers/generators.ts" />
@@ -115,6 +116,9 @@ namespace ts {
115116
transformers.push(transformJsx);
116117
}
117118

119+
if (languageVersion < ScriptTarget.ES2017) {
120+
transformers.push(transformES2017);
121+
}
118122

119123
if (languageVersion < ScriptTarget.ES2016) {
120124
transformers.push(transformES2016);

0 commit comments

Comments
 (0)