mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 19:45:07 -06:00
Add ES8/ES2017 target (#10768)
This commit is contained in:
parent
ebb17e8019
commit
2c46f9b687
@ -262,7 +262,9 @@ namespace ts {
|
||||
"es3": ScriptTarget.ES3,
|
||||
"es5": ScriptTarget.ES5,
|
||||
"es6": ScriptTarget.ES6,
|
||||
"es8": ScriptTarget.ES8,
|
||||
"es2015": ScriptTarget.ES2015,
|
||||
"es2017": ScriptTarget.ES2017,
|
||||
}),
|
||||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
|
||||
paramType: Diagnostics.VERSION,
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 ES8 and above, we can emit async/await as is.
|
||||
if ((languageVersion < ScriptTarget.ES8) && (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions)) {
|
||||
writeLines(awaiterHelper);
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
writeLines(generatorHelper);
|
||||
|
||||
@ -115,7 +115,9 @@ namespace ts {
|
||||
transformers.push(transformJsx);
|
||||
}
|
||||
|
||||
transformers.push(transformES7);
|
||||
if (languageVersion < ScriptTarget.ES8) {
|
||||
transformers.push(transformES7);
|
||||
}
|
||||
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
transformers.push(transformES6);
|
||||
@ -339,4 +341,4 @@ namespace ts {
|
||||
return statements;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -2831,8 +2831,10 @@ namespace ts {
|
||||
ES3 = 0,
|
||||
ES5 = 1,
|
||||
ES6 = 2,
|
||||
ES8 = 3,
|
||||
ES2015 = ES6,
|
||||
Latest = ES6,
|
||||
ES2017 = ES8,
|
||||
Latest = ES8,
|
||||
}
|
||||
|
||||
export const enum LanguageVariant {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user