-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add ES2017 target #11407
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
Changes from 2 commits
2c46f9b
d16e846
f42c791
5d52c9f
1b4c0e3
e60e97f
f0fd77a
4284a74
7df3fda
c5ddf27
b871b53
a500fd9
86784a5
7352e97
17d60d5
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 |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done 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. you also need to update 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. done |
||
"es2015": ScriptTarget.ES2015, | ||
"es2017": ScriptTarget.ES2017, | ||
}), | ||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015, | ||
paramType: Diagnostics.VERSION, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,11 +240,14 @@ namespace ts { | |
// ES6 export and default modifiers are elided when inside a namespace. | ||
return currentNamespace ? undefined : node; | ||
|
||
case SyntaxKind.AsyncKeyword: | ||
// Async keyword is not elided for target ES8 | ||
return languageVersion < ScriptTarget.ES8 ? undefined : node; | ||
|
||
case SyntaxKind.PublicKeyword: | ||
case SyntaxKind.PrivateKeyword: | ||
case SyntaxKind.ProtectedKeyword: | ||
case SyntaxKind.AbstractKeyword: | ||
case SyntaxKind.AsyncKeyword: | ||
case SyntaxKind.ConstKeyword: | ||
case SyntaxKind.DeclareKeyword: | ||
case SyntaxKind.ReadonlyKeyword: | ||
|
@@ -2223,6 +2226,14 @@ namespace ts { | |
/*location*/ node | ||
); | ||
|
||
// Add ES8 async function expression modifier | ||
// Not sure this is the right place? Might be better to move this | ||
// into createFunctionExpression itself. | ||
if ((languageVersion >= ScriptTarget.ES8) && isAsyncFunctionLike(node)) { | ||
const funcModifiers = visitNodes(node.modifiers, visitor, isModifier); | ||
func.modifiers = createNodeArray(funcModifiers); | ||
} | ||
|
||
setOriginalNode(func, node); | ||
|
||
return func; | ||
|
@@ -2235,7 +2246,7 @@ namespace ts { | |
*/ | ||
function visitArrowFunction(node: ArrowFunction) { | ||
const func = createArrowFunction( | ||
/*modifiers*/ undefined, | ||
visitNodes(node.modifiers, visitor, isModifier), | ||
/*typeParameters*/ undefined, | ||
visitNodes(node.parameters, visitor, isParameter), | ||
/*type*/ undefined, | ||
|
@@ -2250,7 +2261,7 @@ namespace ts { | |
} | ||
|
||
function transformFunctionBody(node: MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression): FunctionBody { | ||
if (isAsyncFunctionLike(node)) { | ||
if (isAsyncFunctionLike(node) && languageVersion < ScriptTarget.ES8) { | ||
return <FunctionBody>transformAsyncFunctionBody(node); | ||
} | ||
|
||
|
@@ -2270,7 +2281,7 @@ namespace ts { | |
} | ||
|
||
function transformConciseBody(node: ArrowFunction): ConciseBody { | ||
if (isAsyncFunctionLike(node)) { | ||
if (isAsyncFunctionLike(node) && languageVersion < ScriptTarget.ES8) { | ||
return transformAsyncFunctionBody(node); | ||
} | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. async/await should be split into its own transform, 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. done 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. Just remove this function altogether. 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. done |
||
const targetAtLeastES8 = languageVersion >= ScriptTarget.ES8; | ||
return setOriginalNode( | ||
createYield( | ||
targetAtLeastES8 ? createAwaitExpression() : createYieldExpression(), | ||
node | ||
); | ||
|
||
function createAwaitExpression() { | ||
const awaitExpression = createAwait( | ||
visitNode(node.expression, visitor, isExpression), | ||
/*location*/ node | ||
); | ||
return awaitExpression; | ||
} | ||
|
||
function createYieldExpression() { | ||
const yieldExpression = createYield( | ||
/*asteriskToken*/ undefined, | ||
visitNode(node.expression, visitor, isExpression), | ||
/*location*/ node | ||
), | ||
node | ||
); | ||
); | ||
return yieldExpression; | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2831,8 +2831,10 @@ namespace ts { | |
ES3 = 0, | ||
ES5 = 1, | ||
ES6 = 2, | ||
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. this is minor, but can you make 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. The only place where 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. removed ES6 completely |
||
ES8 = 3, | ||
ES2015 = ES6, | ||
Latest = ES6, | ||
ES2017 = ES8, | ||
Latest = ES8, | ||
} | ||
|
||
export const enum LanguageVariant { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//// [es8-async.ts] | ||
|
||
async (): Promise<void> => { | ||
await 0; | ||
} | ||
|
||
async function asyncFunc() { | ||
await 0; | ||
} | ||
|
||
const asycnArrowFunc = async (): Promise<void> => { | ||
await 0; | ||
} | ||
|
||
async function asyncIIFE() { | ||
await 0; | ||
|
||
await (async function(): Promise<void> { | ||
await 1; | ||
})(); | ||
|
||
await (async function asyncNamedFunc(): Promise<void> { | ||
await 1; | ||
})(); | ||
|
||
await (async (): Promise<void> => { | ||
await 1; | ||
})(); | ||
} | ||
|
||
class AsyncClass { | ||
asyncPropFunc = async function(): Promise<void> { | ||
await 2; | ||
} | ||
|
||
asyncPropNamedFunc = async function namedFunc(): Promise<void> { | ||
await 2; | ||
} | ||
|
||
asyncPropArrowFunc = async (): Promise<void> => { | ||
await 2; | ||
} | ||
|
||
async asyncMethod(): Promise<void> { | ||
await 2; | ||
} | ||
} | ||
|
||
|
||
//// [es8-async.js] | ||
async () => { | ||
await 0; | ||
}; | ||
async function asyncFunc() { | ||
await 0; | ||
} | ||
const asycnArrowFunc = async () => { | ||
await 0; | ||
}; | ||
async function asyncIIFE() { | ||
await 0; | ||
await (async function () { | ||
await 1; | ||
})(); | ||
await (async function asyncNamedFunc() { | ||
await 1; | ||
})(); | ||
await (async () => { | ||
await 1; | ||
})(); | ||
} | ||
class AsyncClass { | ||
constructor() { | ||
this.asyncPropFunc = async function () { | ||
await 2; | ||
}; | ||
this.asyncPropNamedFunc = async function namedFunc() { | ||
await 2; | ||
}; | ||
this.asyncPropArrowFunc = async () => { | ||
await 2; | ||
}; | ||
} | ||
async asyncMethod() { | ||
await 2; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
=== tests/cases/compiler/es8-async.ts === | ||
|
||
async (): Promise<void> => { | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 0; | ||
} | ||
|
||
async function asyncFunc() { | ||
>asyncFunc : Symbol(asyncFunc, Decl(es8-async.ts, 3, 1)) | ||
|
||
await 0; | ||
} | ||
|
||
const asycnArrowFunc = async (): Promise<void> => { | ||
>asycnArrowFunc : Symbol(asycnArrowFunc, Decl(es8-async.ts, 9, 5)) | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 0; | ||
} | ||
|
||
async function asyncIIFE() { | ||
>asyncIIFE : Symbol(asyncIIFE, Decl(es8-async.ts, 11, 1)) | ||
|
||
await 0; | ||
|
||
await (async function(): Promise<void> { | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 1; | ||
})(); | ||
|
||
await (async function asyncNamedFunc(): Promise<void> { | ||
>asyncNamedFunc : Symbol(asyncNamedFunc, Decl(es8-async.ts, 20, 11)) | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 1; | ||
})(); | ||
|
||
await (async (): Promise<void> => { | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 1; | ||
})(); | ||
} | ||
|
||
class AsyncClass { | ||
>AsyncClass : Symbol(AsyncClass, Decl(es8-async.ts, 27, 1)) | ||
|
||
asyncPropFunc = async function(): Promise<void> { | ||
>asyncPropFunc : Symbol(AsyncClass.asyncPropFunc, Decl(es8-async.ts, 29, 18)) | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 2; | ||
} | ||
|
||
asyncPropNamedFunc = async function namedFunc(): Promise<void> { | ||
>asyncPropNamedFunc : Symbol(AsyncClass.asyncPropNamedFunc, Decl(es8-async.ts, 32, 5)) | ||
>namedFunc : Symbol(namedFunc, Decl(es8-async.ts, 34, 24)) | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 2; | ||
} | ||
|
||
asyncPropArrowFunc = async (): Promise<void> => { | ||
>asyncPropArrowFunc : Symbol(AsyncClass.asyncPropArrowFunc, Decl(es8-async.ts, 36, 5)) | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 2; | ||
} | ||
|
||
async asyncMethod(): Promise<void> { | ||
>asyncMethod : Symbol(AsyncClass.asyncMethod, Decl(es8-async.ts, 40, 5)) | ||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
await 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.
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