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

Add ES2017 target #11407

merged 15 commits into from
Oct 15, 2016

Conversation

andrejbaran
Copy link
Contributor

@andrejbaran andrejbaran commented Oct 5, 2016

Hi there,
please consider this as a start for ES2017 target. Fixes #10768.

10/13/2016: This PR also includes a consolidation of naming of ES versions to reflect the official naming scheme (past es5) ES_YYYY_. This is a change through out the codebase.

@msftclas
Copy link

msftclas commented Oct 5, 2016

Hi @andrejbaran, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

@@ -262,7 +262,9 @@ namespace ts {
"es3": ScriptTarget.ES3,
"es5": ScriptTarget.ES5,
"es6": ScriptTarget.ES6,
"es8": ScriptTarget.ES8,
Copy link
Contributor

Choose a reason for hiding this comment

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

Officially there is no ES8, it is ES2017, so i would not add ES8 here or anywhere else. i would just leave it to ES2017

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

@@ -262,7 +262,9 @@ namespace ts {
"es3": ScriptTarget.ES3,
"es5": ScriptTarget.ES5,
"es6": ScriptTarget.ES6,
"es8": ScriptTarget.ES8,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add ES2016. it is a bit funny that we skip one ES 2016 (though not very useful but should be there for consistency).

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

@@ -262,7 +262,9 @@ namespace ts {
"es3": ScriptTarget.ES3,
"es5": ScriptTarget.ES5,
"es6": ScriptTarget.ES6,
"es8": ScriptTarget.ES8,
Copy link
Contributor

Choose a reason for hiding this comment

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

you also need to update getDefaultLibFileName to inject the right library based on the target.

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

@@ -2453,14 +2464,28 @@ namespace ts {
* @param node The await expression node.
*/
function visitAwaitExpression(node: AwaitExpression): Expression {
Copy link
Contributor

Choose a reason for hiding this comment

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

async/await should be split into its own transform, es2017.ts, then we do not need to run it in this case, just like ES7 transform.

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

@mhegazy
Copy link
Contributor

mhegazy commented Oct 6, 2016

thanks @andrejbaran for the contribution. a few comments. also cc @rbuckton

@yortus
Copy link
Contributor

yortus commented Oct 6, 2016

In theory trailing commas should also be preserved in the output for fidelity with target: es2017. Is that being too pedantic? I can't imagine any scenarios where it would matter.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 6, 2016

In theory trailing commas should also be preserved in the output for fidelity with target: es2017. Is that being too pedantic? I can't imagine any scenarios where it would matter.

yes, but the implementation today would make this a bit hard to achieve, not sure if there is much value though.

@yortus
Copy link
Contributor

yortus commented Oct 6, 2016

I can't imagine any scenarios where it would matter.

Thinking about it more, at least one scenario comes to mind: ES feature detection. Not sure how useful that is in practice (NB the linked repo has 0 stars). Probably safe to ignore until someone raises an actual issue.

@andrejbaran
Copy link
Contributor Author

Thanks for the review @mhegazy i'll get back to it tonight and will let you know

@andrejbaran
Copy link
Contributor Author

@mhegazy It turned out to be little more complicated than I anticipated, please review again. I have also renamed es7 to es2016 for consistency? (maybe es6 should be renamed too, dunno but I believe es2015 is preferred)

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Looks good except for the binder marking async/await as Typescript even though I think they should just be ES2017 now. @rbuckton can you take a look at that?

@@ -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

@@ -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

@@ -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

/// <reference path="../visitor.ts" />

/*@internal*/
namespace ts {
Copy link
Member

Choose a reason for hiding this comment

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

@rbuckton do you mind taking a look at least at this file and ts.ts?

@@ -386,7 +379,7 @@ namespace ts {
return visitEnumDeclaration(<EnumDeclaration>node);

case SyntaxKind.AwaitExpression:
// TypeScript 'await' expressions must be transformed.
// Typescript ES2017 async/await are handled by ES2017 transformer
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you will even need this case if you mark async/await as ES2017 only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

if (isAsyncFunctionLike(node)) {
return <FunctionBody>transformAsyncFunctionBody(node);
}
// if (isAsyncFunctionLike(node) && languageVersion < ScriptTarget.ES2017) {
Copy link
Member

Choose a reason for hiding this comment

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

delete this and the next comment section

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

@andrejbaran andrejbaran changed the title Add ES8/ES2017 target Add ES2017 target Oct 12, 2016
@@ -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

@@ -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

return undefined;

case SyntaxKind.AwaitExpression:
// Typescript 'await' expressions must be transformed for targets < ES2017.
Copy link
Member

Choose a reason for hiding this comment

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

Should be ES2017 and not Typescript here

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

return visitAwaitExpression(<AwaitExpression>node);

case SyntaxKind.MethodDeclaration:
// TypeScript method declarations may be 'async'
Copy link
Member

Choose a reason for hiding this comment

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

Should be ES2017 and not Typescript here

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

return visitMethodDeclaration(<MethodDeclaration>node);

case SyntaxKind.FunctionDeclaration:
// TypeScript function declarations may be 'async'
Copy link
Member

Choose a reason for hiding this comment

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

Should be ES2017 and not Typescript here

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

ContainsES2017 = 1 << 5,
ES2016 = 1 << 6,
ContainsES2016 = 1 << 7,
ES6 = 1 << 8,
Copy link
Member

Choose a reason for hiding this comment

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

Please change to ES2015 for consistency.

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

ES2016 = 1 << 6,
ContainsES2016 = 1 << 7,
ES6 = 1 << 8,
ContainsES6 = 1 << 9,
Copy link
Member

Choose a reason for hiding this comment

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

Please change to ContainsES2015 for consistency.

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


HasComputedFlags = 1 << 29, // Transform flags have been computed.

// Assertions
// - Bitmasks that are used to assert facts about the syntax of a node and its subtree.
AssertTypeScript = TypeScript | ContainsTypeScript,
AssertJsx = Jsx | ContainsJsx,
AssertES7 = ES7 | ContainsES7,
AssertES2017 = ES2017 | ContainsES2017,
AssertES2016 = ES2016 | ContainsES2016,
AssertES6 = ES6 | ContainsES6,
Copy link
Member

Choose a reason for hiding this comment

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

Please change to AssertES2015 for consistency.

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

return "lib.es2017.d.ts";
case ScriptTarget.ES2016:
return "lib.es2016.d.ts";
case ScriptTarget.ES6:
Copy link
Member

Choose a reason for hiding this comment

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

Please use ES2015 here for consistency.

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

return "lib.es2017.d.ts";
case ts.ScriptTarget.ES2016:
return "lib.es2016.d.ts";
case ts.ScriptTarget.ES6:
Copy link
Member

Choose a reason for hiding this comment

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

Please use ES2015 here for consistency.

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

@andrejbaran
Copy link
Contributor Author

andrejbaran commented Oct 13, 2016

@mhegazy @rbuckton @sandersn Review the changes pls. I also made the change from ES6 -> ES2015 through out the code so the naming scheme for ES versions is as consistent as possible. Let me know if that's not desired as I realise it's not the purpose of this PR, but since this PR kind of kicked off the consolidation I went for it. Again let me know if you're not ok with it (since it's quite a big change)

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

One minor comment, otherwise looks good. I'm not sure whether we need to duplicate all the async tests to have 2017 versions, but I'll let @rbuckton take a look and decide on that.

@@ -3055,7 +3055,9 @@ namespace ts {
ES5 = 1,
ES6 = 2,
Copy link
Member

Choose a reason for hiding this comment

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

this is minor, but can you make ES2015=2 and ES6=ES2015 ?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe even delete ES6 if it's not used any more. I can't remember if this has anything to do with command line parsing, so it might be hard to tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only place where ES6 is used (other than comments) is in command line/compiler options parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed ES6 completely

@mhegazy
Copy link
Contributor

mhegazy commented Oct 14, 2016

@rbuckton any comments?

@rbuckton
Copy link
Member

I concur with @sandersn that there are a number of unnecessarily duplicated tests. I need to go through them to see which ones are unneeded. Other than that, 👍

@andrejbaran
Copy link
Contributor Author

@sandersn @rbuckton sorry about that, I thought it would be good to have them for es2017, but didn't find time to dig deeper.

Copy link
Member

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

Most of the tests are fine as they also are vetting the emit for --target ES2017. I have marked some tests that are specific to either the checker or our down-level emit for ES6 that do not need to be duplicated.

I can approve this once those changes are made.

await 0;
}

const asycnArrowFunc = async (): Promise<void> => {
Copy link
Member

Choose a reason for hiding this comment

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

"async"

@@ -0,0 +1,6 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify return type check for async functions, which is already handled by the existing tests. The reason we differ between es5/es6 is that the rules governing whether this is allowed are different when targeting es5/3, but will be the same for es6+

@@ -0,0 +1,4 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@@ -0,0 +1,6 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@@ -0,0 +1,3 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@@ -0,0 +1,5 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test isn't really needed as it was added only to ensure the __awaiter helper was added to the correct file.

@@ -0,0 +1,9 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@@ -0,0 +1,6 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@@ -0,0 +1,14 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@@ -0,0 +1,25 @@
// @target: es2017
Copy link
Member

Choose a reason for hiding this comment

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

This test is unnecessary as its only purpose is to verify the checker with respect to async functions, which is already handled by existing tests.

@andrejbaran
Copy link
Contributor Author

andrejbaran commented Oct 14, 2016

@rbuckton done. Thanks!

@mhegazy
Copy link
Contributor

mhegazy commented Oct 14, 2016

thanks @andrejbaran! waiting on the travis, it has been 🐌 sloooow 🐌 today

@rbuckton
Copy link
Member

Travis CI looks to be running behind. Once the build passes I'll merge the pull request. Thanks @andrejbaran for the contribution!

@rbuckton
Copy link
Member

@andrejbaran My appologies, can you take a look at the merge conflict?

@andrejbaran
Copy link
Contributor Author

@rbuckton should be ok now

@rbuckton rbuckton merged commit 63160de into microsoft:master Oct 15, 2016
@mhegazy mhegazy mentioned this pull request Oct 15, 2016
@andrejbaran
Copy link
Contributor Author

Many thanks guys!

@andrejbaran andrejbaran deleted the es2017-target branch October 17, 2016 06:48
@mhegazy mhegazy mentioned this pull request May 29, 2018
3 tasks
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants