-
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
Add ES2017 target #11407
Add ES2017 target #11407
Conversation
Hi @andrejbaran, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! 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, |
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.
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
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.
done
@@ -262,7 +262,9 @@ namespace ts { | |||
"es3": ScriptTarget.ES3, | |||
"es5": ScriptTarget.ES5, | |||
"es6": ScriptTarget.ES6, | |||
"es8": ScriptTarget.ES8, |
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.
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).
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.
done
@@ -262,7 +262,9 @@ namespace ts { | |||
"es3": ScriptTarget.ES3, | |||
"es5": ScriptTarget.ES5, | |||
"es6": ScriptTarget.ES6, | |||
"es8": ScriptTarget.ES8, |
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.
you also need to update getDefaultLibFileName
to inject the right library based on the target.
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.
done
@@ -2453,14 +2464,28 @@ namespace ts { | |||
* @param node The await expression node. | |||
*/ | |||
function visitAwaitExpression(node: AwaitExpression): Expression { |
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.
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.
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.
done
thanks @andrejbaran for the contribution. a few comments. also cc @rbuckton |
In theory trailing commas should also be preserved in the output for fidelity with |
yes, but the implementation today would make this a bit hard to achieve, not sure if there is much value though. |
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. |
Thanks for the review @mhegazy i'll get back to it tonight and will let you know |
Rename es7 to es2016. Update getDefaultLibFileName for new targets.
@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) |
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.
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; |
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.
is this comment still accurate? Or are async functions valid ES2017 too? If so, they probably shouldn't be marked as typescript.
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.
According to this async/await is finished and will be part of es2017, so I believe you have a valid point there.
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.
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; |
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.
same comment as for async function declarations
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.
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 |
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.
same comment as elsewhere. probably should just be AssertES2017
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.
done
/// <reference path="../visitor.ts" /> | ||
|
||
/*@internal*/ | ||
namespace ts { |
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.
@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 |
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 don't think you will even need this case
if you mark async/await as ES2017 only
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.
removed
if (isAsyncFunctionLike(node)) { | ||
return <FunctionBody>transformAsyncFunctionBody(node); | ||
} | ||
// if (isAsyncFunctionLike(node) && languageVersion < ScriptTarget.ES2017) { |
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.
delete this and the next comment section
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.
done
@@ -2555,6 +2555,11 @@ namespace ts { | |||
// extends clause of a class. | |||
let transformFlags = subtreeFlags | TransformFlags.AssertES6; | |||
|
|||
// propagate ES2017 |
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.
Any TransformFlags
of a subtree that should propagate should already be set in subtreeFlags
. There should be no need to explicitly propagate.
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.
done
@@ -2595,6 +2600,11 @@ namespace ts { | |||
transformFlags |= TransformFlags.AssertTypeScript; | |||
} | |||
|
|||
// Async MethodDeclaration is ES2017 | |||
if (modifierFlags & ModifierFlags.Async) { |
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.
Since async
is ES2017, the test at line 2598 is now incorrect.
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.
done
return undefined; | ||
|
||
case SyntaxKind.AwaitExpression: | ||
// Typescript 'await' expressions must be transformed for targets < ES2017. |
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.
Should be ES2017
and not Typescript
here
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.
done
return visitAwaitExpression(<AwaitExpression>node); | ||
|
||
case SyntaxKind.MethodDeclaration: | ||
// TypeScript method declarations may be 'async' |
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.
Should be ES2017
and not Typescript
here
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.
done
return visitMethodDeclaration(<MethodDeclaration>node); | ||
|
||
case SyntaxKind.FunctionDeclaration: | ||
// TypeScript function declarations may be 'async' |
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.
Should be ES2017
and not Typescript
here
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.
done
ContainsES2017 = 1 << 5, | ||
ES2016 = 1 << 6, | ||
ContainsES2016 = 1 << 7, | ||
ES6 = 1 << 8, |
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.
Please change to ES2015
for consistency.
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.
done
ES2016 = 1 << 6, | ||
ContainsES2016 = 1 << 7, | ||
ES6 = 1 << 8, | ||
ContainsES6 = 1 << 9, |
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.
Please change to ContainsES2015
for consistency.
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.
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, |
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.
Please change to AssertES2015
for consistency.
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.
done
return "lib.es2017.d.ts"; | ||
case ScriptTarget.ES2016: | ||
return "lib.es2016.d.ts"; | ||
case ScriptTarget.ES6: |
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.
Please use ES2015
here for consistency.
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.
done
return "lib.es2017.d.ts"; | ||
case ts.ScriptTarget.ES2016: | ||
return "lib.es2016.d.ts"; | ||
case ts.ScriptTarget.ES6: |
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.
Please use ES2015
here for consistency.
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.
done
@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) |
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.
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, |
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.
this is minor, but can you make ES2015=2
and ES6=ES2015
?
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.
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.
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.
The only place where ES6
is used (other than comments) is in command line/compiler options parsing.
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.
removed ES6 completely
@rbuckton any comments? |
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, 👍 |
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.
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> => { |
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.
"async"
@@ -0,0 +1,6 @@ | |||
// @target: es2017 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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.
@rbuckton done. Thanks! |
thanks @andrejbaran! waiting on the travis, it has been 🐌 sloooow 🐌 today |
Travis CI looks to be running behind. Once the build passes I'll merge the pull request. Thanks @andrejbaran for the contribution! |
@andrejbaran My appologies, can you take a look at the merge conflict? |
@rbuckton should be ok now |
Many thanks guys! |
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.