From f42c79150253b003f6f7e38011d57cf0af77df10 Mon Sep 17 00:00:00 2001 From: Andrej Baran Date: Wed, 12 Oct 2016 21:28:11 +0200 Subject: [PATCH] Don't use es8. Add es2016 target. Rename es7 to es2016. Update getDefaultLibFileName for new targets. --- Jakefile.js | 4 +- src/compiler/binder.ts | 4 +- src/compiler/commandLineParser.ts | 2 +- src/compiler/emitter.ts | 4 +- src/compiler/transformer.ts | 7 +-- .../transformers/{es7.ts => es2016.ts} | 10 ++-- src/compiler/transformers/ts.ts | 3 +- src/compiler/tsconfig.json | 2 +- src/compiler/types.ts | 53 ++++++++++--------- src/compiler/utilities.ts | 10 +++- src/harness/harness.ts | 10 +++- src/harness/tsconfig.json | 2 +- src/harness/unittests/commandLineParsing.ts | 2 +- .../convertCompilerOptionsFromJson.ts | 2 +- src/services/tsconfig.json | 2 +- .../{es8-async.ts => es2017basicAsync.ts} | 2 +- 16 files changed, 69 insertions(+), 50 deletions(-) rename src/compiler/transformers/{es7.ts => es2016.ts} (91%) rename tests/cases/compiler/{es8-async.ts => es2017basicAsync.ts} (97%) diff --git a/Jakefile.js b/Jakefile.js index 64a8553ef39..ecbd0ae2be2 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -74,7 +74,7 @@ var compilerSources = [ "transformers/module/system.ts", "transformers/module/module.ts", "transformers/jsx.ts", - "transformers/es7.ts", + "transformers/es2016.ts", "transformers/generators.ts", "transformers/es6.ts", "transformer.ts", @@ -108,7 +108,7 @@ var servicesSources = [ "transformers/module/system.ts", "transformers/module/module.ts", "transformers/jsx.ts", - "transformers/es7.ts", + "transformers/es2016.ts", "transformers/generators.ts", "transformers/es6.ts", "transformer.ts", diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2fe7d30ab56..ce482dcdfd9 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -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; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 16d338cac6a..b77f6898b3c 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -262,8 +262,8 @@ namespace ts { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5, "es6": ScriptTarget.ES6, - "es8": ScriptTarget.ES8, "es2015": ScriptTarget.ES2015, + "es2016": ScriptTarget.ES2016, "es2017": ScriptTarget.ES2017, }), description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b0e31278ff0..a3f69e2fd4b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2194,8 +2194,8 @@ const _super = (function (geti, seti) { // 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)) { + // 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); diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index 415a9ecd1d7..9e548268052 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -1,7 +1,7 @@ /// /// /// -/// +/// /// /// /// @@ -115,8 +115,9 @@ namespace ts { transformers.push(transformJsx); } - if (languageVersion < ScriptTarget.ES8) { - transformers.push(transformES7); + + if (languageVersion < ScriptTarget.ES2016) { + transformers.push(transformES2016); } if (languageVersion < ScriptTarget.ES6) { diff --git a/src/compiler/transformers/es7.ts b/src/compiler/transformers/es2016.ts similarity index 91% rename from src/compiler/transformers/es7.ts rename to src/compiler/transformers/es2016.ts index 4d5e96134c4..fba1d300903 100644 --- a/src/compiler/transformers/es7.ts +++ b/src/compiler/transformers/es2016.ts @@ -3,7 +3,7 @@ /*@internal*/ namespace ts { - export function transformES7(context: TransformationContext) { + export function transformES2016(context: TransformationContext) { const { hoistVariableDeclaration } = context; return transformSourceFile; @@ -17,10 +17,10 @@ namespace ts { } function visitor(node: Node): VisitResult { - 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 { @@ -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) { @@ -98,4 +98,4 @@ namespace ts { } } } -} \ No newline at end of file +} diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 40b9e7f64e1..c98fbfc26cc 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -241,8 +241,7 @@ namespace ts { return currentNamespace ? undefined : node; case SyntaxKind.AsyncKeyword: - // Async keyword is not elided for target ES8 - return languageVersion < ScriptTarget.ES8 ? undefined : node; + return node; case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index f128c994af1..fc0f016f664 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -24,7 +24,7 @@ "visitor.ts", "transformers/ts.ts", "transformers/jsx.ts", - "transformers/es7.ts", + "transformers/es2016.ts", "transformers/es6.ts", "transformers/generators.ts", "transformers/destructuring.ts", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5b193beb155..b89887cafa0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2831,10 +2831,10 @@ namespace ts { ES3 = 0, ES5 = 1, ES6 = 2, - ES8 = 3, ES2015 = ES6, - ES2017 = ES8, - Latest = ES8, + ES2016 = 3, + ES2017 = 4, + Latest = ES2017, } export const enum LanguageVariant { @@ -3119,29 +3119,31 @@ namespace ts { ContainsTypeScript = 1 << 1, Jsx = 1 << 2, ContainsJsx = 1 << 3, - ES7 = 1 << 4, - ContainsES7 = 1 << 5, - ES6 = 1 << 6, - ContainsES6 = 1 << 7, - DestructuringAssignment = 1 << 8, - Generator = 1 << 9, - ContainsGenerator = 1 << 10, + ES2017 = 1 << 4, + ContainsES2017 = 1 << 5, + ES2016 = 1 << 6, + ContainsES2016 = 1 << 7, + ES6 = 1 << 8, + ContainsES6 = 1 << 9, + DestructuringAssignment = 1 << 10, + Generator = 1 << 11, + ContainsGenerator = 1 << 12, // Markers // - Flags used to indicate that a subtree contains a specific transformation. - ContainsDecorators = 1 << 11, - ContainsPropertyInitializer = 1 << 12, - ContainsLexicalThis = 1 << 13, - ContainsCapturedLexicalThis = 1 << 14, - ContainsLexicalThisInComputedPropertyName = 1 << 15, - ContainsDefaultValueAssignments = 1 << 16, - ContainsParameterPropertyAssignments = 1 << 17, - ContainsSpreadElementExpression = 1 << 18, - ContainsComputedPropertyName = 1 << 19, - ContainsBlockScopedBinding = 1 << 20, - ContainsBindingPattern = 1 << 21, - ContainsYield = 1 << 22, - ContainsHoistedDeclarationOrCompletion = 1 << 23, + ContainsDecorators = 1 << 13, + ContainsPropertyInitializer = 1 << 14, + ContainsLexicalThis = 1 << 15, + ContainsCapturedLexicalThis = 1 << 16, + ContainsLexicalThisInComputedPropertyName = 1 << 17, + ContainsDefaultValueAssignments = 1 << 18, + ContainsParameterPropertyAssignments = 1 << 19, + ContainsSpreadElementExpression = 1 << 20, + ContainsComputedPropertyName = 1 << 21, + ContainsBlockScopedBinding = 1 << 22, + ContainsBindingPattern = 1 << 23, + ContainsYield = 1 << 24, + ContainsHoistedDeclarationOrCompletion = 1 << 25, HasComputedFlags = 1 << 29, // Transform flags have been computed. @@ -3149,14 +3151,15 @@ namespace ts { // - 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, AssertGenerator = Generator | ContainsGenerator, // Scope Exclusions // - Bitmasks that exclude flags from propagating out of a specific context // into the subtree flags of their container. - NodeExcludes = TypeScript | Jsx | ES7 | ES6 | DestructuringAssignment | Generator | HasComputedFlags, + NodeExcludes = TypeScript | Jsx | ES2017 | ES2016 | ES6 | DestructuringAssignment | Generator | HasComputedFlags, ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion, FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion, ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1a4d95feca5..b661cefb5a6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4141,7 +4141,15 @@ namespace ts { namespace ts { export function getDefaultLibFileName(options: CompilerOptions): string { - return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; + switch (options.target) { + case ScriptTarget.ES2016: + return "lib.es2016.d.ts"; + case ScriptTarget.ES6: + return "lib.es2015.d.ts"; + + default: + return "lib.d.ts"; + } } export function textSpanEnd(span: TextSpan) { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 7c82aeece78..b8703ebc8f2 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -941,7 +941,15 @@ namespace Harness { } export function getDefaultLibFileName(options: ts.CompilerOptions): string { - return options.target === ts.ScriptTarget.ES6 ? es2015DefaultLibFileName : defaultLibFileName; + switch (options.target) { + case ts.ScriptTarget.ES2016: + return "lib.es2016.d.ts"; + case ts.ScriptTarget.ES6: + return es2015DefaultLibFileName; + + default: + return defaultLibFileName; + } } // Cache these between executions so we don't have to re-parse them for every test diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index f9d302ace81..aa46c8ee8d0 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -26,7 +26,7 @@ "../compiler/visitor.ts", "../compiler/transformers/ts.ts", "../compiler/transformers/jsx.ts", - "../compiler/transformers/es7.ts", + "../compiler/transformers/es2016.ts", "../compiler/transformers/es6.ts", "../compiler/transformers/generators.ts", "../compiler/transformers/destructuring.ts", diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 42fc242f08e..cd9bf88df60 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -165,7 +165,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es8', 'es2015', 'es2017'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index db3d6cfc102..13f54e369ed 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -176,7 +176,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es8', 'es2015', 'es2017'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 58312c6f38f..e759ab35b48 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -25,7 +25,7 @@ "../compiler/visitor.ts", "../compiler/transformers/ts.ts", "../compiler/transformers/jsx.ts", - "../compiler/transformers/es7.ts", + "../compiler/transformers/es2016.ts", "../compiler/transformers/es6.ts", "../compiler/transformers/generators.ts", "../compiler/transformers/destructuring.ts", diff --git a/tests/cases/compiler/es8-async.ts b/tests/cases/compiler/es2017basicAsync.ts similarity index 97% rename from tests/cases/compiler/es8-async.ts rename to tests/cases/compiler/es2017basicAsync.ts index 0ceb6e397e5..b13a5d29bc0 100644 --- a/tests/cases/compiler/es8-async.ts +++ b/tests/cases/compiler/es2017basicAsync.ts @@ -1,4 +1,4 @@ -// @target: es8 +// @target: es2017 // @lib: es2017 // @noEmitHelpers: true