Skip to content
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

Add ES2017 target #11407

Merged
merged 15 commits into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ var compilerSources = [
"transformers/module/system.ts",
"transformers/module/module.ts",
"transformers/jsx.ts",
"transformers/es7.ts",
"transformers/es2017.ts",
"transformers/es2016.ts",
"transformers/generators.ts",
"transformers/es6.ts",
"transformer.ts",
Expand Down Expand Up @@ -108,7 +109,8 @@ var servicesSources = [
"transformers/module/system.ts",
"transformers/module/module.ts",
"transformers/jsx.ts",
"transformers/es7.ts",
"transformers/es2017.ts",
"transformers/es2016.ts",
"transformers/generators.ts",
"transformers/es6.ts",
"transformer.ts",
Expand Down
28 changes: 21 additions & 7 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2411,8 +2411,8 @@ namespace ts {
}
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
|| operatorTokenKind === SyntaxKind.AsteriskAsteriskEqualsToken) {
// Exponentiation is ES7 syntax.
transformFlags |= TransformFlags.AssertES7;
// Exponentiation is ES2016 syntax.
transformFlags |= TransformFlags.AssertES2016;
}

node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
Expand Down Expand Up @@ -2555,6 +2555,11 @@ namespace ts {
// extends clause of a class.
let transformFlags = subtreeFlags | TransformFlags.AssertES6;

// propagate ES2017
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any TransformFlags of a subtree that should propagate should already be set in subtreeFlags. There should be no need to explicitly propagate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (node.expression.transformFlags & TransformFlags.ContainsES2017) {
transformFlags |= TransformFlags.ContainsES2017;
}

// If an ExpressionWithTypeArguments contains type arguments, then it
// is TypeScript syntax.
if (node.typeArguments) {
Expand Down Expand Up @@ -2595,6 +2600,11 @@ namespace ts {
transformFlags |= TransformFlags.AssertTypeScript;
}

// Async MethodDeclaration is ES2017
if (modifierFlags & ModifierFlags.Async) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since async is ES2017, the test at line 2598 is now incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

transformFlags |= TransformFlags.AssertES2017;
}

// Currently, we only support generators that were originally async function bodies.
if (asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) {
transformFlags |= TransformFlags.AssertGenerator;
Expand Down Expand Up @@ -2656,7 +2666,7 @@ namespace ts {

// If a FunctionDeclaration is async, then it is TypeScript syntax.
if (modifierFlags & ModifierFlags.Async) {
transformFlags |= TransformFlags.AssertTypeScript;
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment still accurate? Or are async functions valid ES2017 too? If so, they probably shouldn't be marked as typescript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this async/await is finished and will be part of es2017, so I believe you have a valid point there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

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

// An async function expression is TypeScript syntax.
if (modifierFlags & ModifierFlags.Async) {
transformFlags |= TransformFlags.AssertTypeScript;
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as for async function declarations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

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

// An async arrow function is TypeScript syntax.
if (modifierFlags & ModifierFlags.Async) {
transformFlags |= TransformFlags.AssertTypeScript;
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
}

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

switch (kind) {
case SyntaxKind.AsyncKeyword:
case SyntaxKind.AwaitExpression:
// Typescript async/await are ES2017 features
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as elsewhere. probably should just be AssertES2017

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2017;
break;

case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.AbstractKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.AsyncKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.AwaitExpression:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.TypeAssertionExpression:
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ namespace ts {
"es5": ScriptTarget.ES5,
"es6": ScriptTarget.ES6,
"es2015": ScriptTarget.ES2015,
"es2016": ScriptTarget.ES2016,
"es2017": ScriptTarget.ES2017,
}),
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
paramType: Diagnostics.VERSION,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ namespace ts {
export function getEmitModuleKind(compilerOptions: CompilerOptions) {
return typeof compilerOptions.module === "number" ?
compilerOptions.module :
getEmitScriptTarget(compilerOptions) === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
}

/* @internal */
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,10 @@ const _super = (function (geti, seti) {
helpersEmitted = true;
}

if (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions) {
// Only emit __awaiter function when target ES5/ES6.
// Only emit __generator function when target ES5.
// For target ES2017 and above, we can emit async/await as is.
if ((languageVersion < ScriptTarget.ES2017) && (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions)) {
writeLines(awaiterHelper);
if (languageVersion < ScriptTarget.ES6) {
writeLines(generatorHelper);
Expand Down
13 changes: 10 additions & 3 deletions src/compiler/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference path="visitor.ts" />
/// <reference path="transformers/ts.ts" />
/// <reference path="transformers/jsx.ts" />
/// <reference path="transformers/es7.ts" />
/// <reference path="transformers/es2017.ts" />
/// <reference path="transformers/es2016.ts" />
/// <reference path="transformers/es6.ts" />
/// <reference path="transformers/generators.ts" />
/// <reference path="transformers/module/module.ts" />
Expand Down Expand Up @@ -115,7 +116,13 @@ namespace ts {
transformers.push(transformJsx);
}

transformers.push(transformES7);
if (languageVersion < ScriptTarget.ES2017) {
transformers.push(transformES2017);
}

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

if (languageVersion < ScriptTarget.ES6) {
transformers.push(transformES6);
Expand Down Expand Up @@ -339,4 +346,4 @@ namespace ts {
return statements;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*@internal*/
namespace ts {
export function transformES7(context: TransformationContext) {
export function transformES2016(context: TransformationContext) {
const { hoistVariableDeclaration } = context;

return transformSourceFile;
Expand All @@ -17,10 +17,10 @@ namespace ts {
}

function visitor(node: Node): VisitResult<Node> {
if (node.transformFlags & TransformFlags.ES7) {
if (node.transformFlags & TransformFlags.ES2016) {
return visitorWorker(node);
}
else if (node.transformFlags & TransformFlags.ContainsES7) {
else if (node.transformFlags & TransformFlags.ContainsES2016) {
return visitEachChild(node, visitor, context);
}
else {
Expand All @@ -40,7 +40,7 @@ namespace ts {
}

function visitBinaryExpression(node: BinaryExpression): Expression {
// We are here because ES7 adds support for the exponentiation operator.
// We are here because ES2016 adds support for the exponentiation operator.
const left = visitNode(node.left, visitor, isExpression);
const right = visitNode(node.right, visitor, isExpression);
if (node.operatorToken.kind === SyntaxKind.AsteriskAsteriskEqualsToken) {
Expand Down Expand Up @@ -98,4 +98,4 @@ namespace ts {
}
}
}
}
}
Loading