Skip to content

Commit 63160de

Browse files
authored
Merge pull request #11407 from andrejbaran/es2017-target
Add ES2017 target
2 parents ce6ae0e + 17d60d5 commit 63160de

File tree

220 files changed

+5114
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+5114
-403
lines changed

Jakefile.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ var compilerSources = [
7070
"visitor.ts",
7171
"transformers/destructuring.ts",
7272
"transformers/ts.ts",
73-
"transformers/module/es6.ts",
73+
"transformers/module/es2015.ts",
7474
"transformers/module/system.ts",
7575
"transformers/module/module.ts",
7676
"transformers/jsx.ts",
77-
"transformers/es7.ts",
77+
"transformers/es2017.ts",
78+
"transformers/es2016.ts",
79+
"transformers/es2015.ts",
7880
"transformers/generators.ts",
79-
"transformers/es6.ts",
8081
"transformer.ts",
8182
"sourcemap.ts",
8283
"comments.ts",
@@ -104,13 +105,14 @@ var servicesSources = [
104105
"visitor.ts",
105106
"transformers/destructuring.ts",
106107
"transformers/ts.ts",
107-
"transformers/module/es6.ts",
108+
"transformers/module/es2015.ts",
108109
"transformers/module/system.ts",
109110
"transformers/module/module.ts",
110111
"transformers/jsx.ts",
111-
"transformers/es7.ts",
112+
"transformers/es2017.ts",
113+
"transformers/es2016.ts",
114+
"transformers/es2015.ts",
112115
"transformers/generators.ts",
113-
"transformers/es6.ts",
114116
"transformer.ts",
115117
"sourcemap.ts",
116118
"comments.ts",

src/compiler/binder.ts

Lines changed: 54 additions & 45 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ namespace ts {
32253225
const elements = pattern.elements;
32263226
const lastElement = lastOrUndefined(elements);
32273227
if (elements.length === 0 || (!isOmittedExpression(lastElement) && lastElement.dotDotDotToken)) {
3228-
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
3228+
return languageVersion >= ScriptTarget.ES2015 ? createIterableType(anyType) : anyArrayType;
32293229
}
32303230
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
32313231
const elementTypes = map(elements, e => isOmittedExpression(e) ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
@@ -9286,7 +9286,7 @@ namespace ts {
92869286
// can explicitly bound arguments objects
92879287
if (symbol === argumentsSymbol) {
92889288
const container = getContainingFunction(node);
9289-
if (languageVersion < ScriptTarget.ES6) {
9289+
if (languageVersion < ScriptTarget.ES2015) {
92909290
if (container.kind === SyntaxKind.ArrowFunction) {
92919291
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
92929292
}
@@ -9311,7 +9311,7 @@ namespace ts {
93119311
// Due to the emit for class decorators, any reference to the class from inside of the class body
93129312
// must instead be rewritten to point to a temporary variable to avoid issues with the double-bind
93139313
// behavior of class names in ES6.
9314-
if (languageVersion === ScriptTarget.ES6
9314+
if (languageVersion === ScriptTarget.ES2015
93159315
&& declaration.kind === SyntaxKind.ClassDeclaration
93169316
&& nodeIsDecorated(declaration)) {
93179317
let container = getContainingClass(node);
@@ -9410,7 +9410,7 @@ namespace ts {
94109410
}
94119411

94129412
function checkNestedBlockScopedBinding(node: Identifier, symbol: Symbol): void {
9413-
if (languageVersion >= ScriptTarget.ES6 ||
9413+
if (languageVersion >= ScriptTarget.ES2015 ||
94149414
(symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.Class)) === 0 ||
94159415
symbol.valueDeclaration.parent.kind === SyntaxKind.CatchClause) {
94169416
return;
@@ -9576,7 +9576,7 @@ namespace ts {
95769576
container = getThisContainer(container, /* includeArrowFunctions */ false);
95779577

95789578
// When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code
9579-
needToCaptureLexicalThis = (languageVersion < ScriptTarget.ES6);
9579+
needToCaptureLexicalThis = (languageVersion < ScriptTarget.ES2015);
95809580
}
95819581

95829582
switch (container.kind) {
@@ -9684,7 +9684,7 @@ namespace ts {
96849684
if (!isCallExpression) {
96859685
while (container && container.kind === SyntaxKind.ArrowFunction) {
96869686
container = getSuperContainer(container, /*stopOnFunctions*/ true);
9687-
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
9687+
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES2015;
96889688
}
96899689
}
96909690

@@ -9798,7 +9798,7 @@ namespace ts {
97989798
}
97999799

98009800
if (container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
9801-
if (languageVersion < ScriptTarget.ES6) {
9801+
if (languageVersion < ScriptTarget.ES2015) {
98029802
error(node, Diagnostics.super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher);
98039803
return unknownType;
98049804
}
@@ -10166,7 +10166,7 @@ namespace ts {
1016610166
const index = indexOf(arrayLiteral.elements, node);
1016710167
return getTypeOfPropertyOfContextualType(type, "" + index)
1016810168
|| getIndexTypeOfContextualType(type, IndexKind.Number)
10169-
|| (languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(type, /*errorNode*/ undefined) : undefined);
10169+
|| (languageVersion >= ScriptTarget.ES2015 ? getElementTypeOfIterable(type, /*errorNode*/ undefined) : undefined);
1017010170
}
1017110171
return undefined;
1017210172
}
@@ -10399,7 +10399,7 @@ namespace ts {
1039910399
// if there is no index type / iterated type.
1040010400
const restArrayType = checkExpression((<SpreadElementExpression>e).expression, contextualMapper);
1040110401
const restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) ||
10402-
(languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined);
10402+
(languageVersion >= ScriptTarget.ES2015 ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined);
1040310403
if (restElementType) {
1040410404
elementTypes.push(restElementType);
1040510405
}
@@ -11146,7 +11146,7 @@ namespace ts {
1114611146
// - In a static member function or static member accessor
1114711147
// where this references the constructor function object of a derived class,
1114811148
// a super property access is permitted and must specify a public static member function of the base class.
11149-
if (languageVersion < ScriptTarget.ES6 && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) {
11149+
if (languageVersion < ScriptTarget.ES2015 && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) {
1115011150
// `prop` refers to a *property* declared in the super class
1115111151
// rather than a *method*, so it does not satisfy the above criteria.
1115211152

@@ -14468,7 +14468,7 @@ namespace ts {
1446814468
}
1446914469

1447014470
if (node.type) {
14471-
if (languageVersion >= ScriptTarget.ES6 && isSyntacticallyValidGenerator(node)) {
14471+
if (languageVersion >= ScriptTarget.ES2015 && isSyntacticallyValidGenerator(node)) {
1447214472
const returnType = getTypeFromTypeNode(node.type);
1447314473
if (returnType === voidType) {
1447414474
error(node.type, Diagnostics.A_generator_cannot_have_a_void_type_annotation);
@@ -15429,7 +15429,7 @@ namespace ts {
1542915429
* callable `then` signature.
1543015430
*/
1543115431
function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type {
15432-
if (languageVersion >= ScriptTarget.ES6) {
15432+
if (languageVersion >= ScriptTarget.ES2015) {
1543315433
const returnType = getTypeFromTypeNode(node.type);
1543415434
return checkCorrectPromiseType(returnType, node.type, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type);
1543515435
}
@@ -15958,7 +15958,7 @@ namespace ts {
1595815958

1595915959
function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier) {
1596015960
// No need to check for require or exports for ES6 modules and later
15961-
if (modulekind >= ModuleKind.ES6) {
15961+
if (modulekind >= ModuleKind.ES2015) {
1596215962
return;
1596315963
}
1596415964

@@ -16454,7 +16454,7 @@ namespace ts {
1645416454
if (isTypeAny(inputType)) {
1645516455
return inputType;
1645616456
}
16457-
if (languageVersion >= ScriptTarget.ES6) {
16457+
if (languageVersion >= ScriptTarget.ES2015) {
1645816458
return checkElementTypeOfIterable(inputType, errorNode);
1645916459
}
1646016460
if (allowStringInput) {
@@ -16632,7 +16632,7 @@ namespace ts {
1663216632
* 2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
1663316633
*/
1663416634
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, errorNode: Node): Type {
16635-
Debug.assert(languageVersion < ScriptTarget.ES6);
16635+
Debug.assert(languageVersion < ScriptTarget.ES2015);
1663616636

1663716637
// After we remove all types that are StringLike, we will know if there was a string constituent
1663816638
// based on whether the remaining type is the same as the initial type.
@@ -17943,7 +17943,7 @@ namespace ts {
1794317943
}
1794417944
}
1794517945
else {
17946-
if (modulekind === ModuleKind.ES6 && !isInAmbientContext(node)) {
17946+
if (modulekind === ModuleKind.ES2015 && !isInAmbientContext(node)) {
1794717947
// Import equals declaration is deprecated in es6 or above
1794817948
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_2015_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
1794917949
}
@@ -18031,7 +18031,7 @@ namespace ts {
1803118031
checkExternalModuleExports(container);
1803218032

1803318033
if (node.isExportEquals && !isInAmbientContext(node)) {
18034-
if (modulekind === ModuleKind.ES6) {
18034+
if (modulekind === ModuleKind.ES2015) {
1803518035
// export assignment is not supported in es6 modules
1803618036
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_2015_modules_Consider_using_export_default_or_another_module_format_instead);
1803718037
}
@@ -19543,7 +19543,7 @@ namespace ts {
1954319543

1954419544
getGlobalTemplateStringsArrayType = memoize(() => getGlobalType("TemplateStringsArray"));
1954519545

19546-
if (languageVersion >= ScriptTarget.ES6) {
19546+
if (languageVersion >= ScriptTarget.ES2015) {
1954719547
getGlobalESSymbolType = memoize(() => getGlobalType("Symbol"));
1954819548
getGlobalIterableType = memoize(() => <GenericType>getGlobalType("Iterable", /*arity*/ 1));
1954919549
getGlobalIteratorType = memoize(() => <GenericType>getGlobalType("Iterator", /*arity*/ 1));
@@ -19577,7 +19577,7 @@ namespace ts {
1957719577
// If we found the module, report errors if it does not have the necessary exports.
1957819578
if (helpersModule) {
1957919579
const exports = helpersModule.exports;
19580-
if (requestedExternalEmitHelpers & NodeFlags.HasClassExtends && languageVersion < ScriptTarget.ES6) {
19580+
if (requestedExternalEmitHelpers & NodeFlags.HasClassExtends && languageVersion < ScriptTarget.ES2015) {
1958119581
verifyHelperSymbol(exports, "__extends", SymbolFlags.Value);
1958219582
}
1958319583
if (requestedExternalEmitHelpers & NodeFlags.HasJsxSpreadAttributes && compilerOptions.jsx !== JsxEmit.Preserve) {
@@ -19594,7 +19594,7 @@ namespace ts {
1959419594
}
1959519595
if (requestedExternalEmitHelpers & NodeFlags.HasAsyncFunctions) {
1959619596
verifyHelperSymbol(exports, "__awaiter", SymbolFlags.Value);
19597-
if (languageVersion < ScriptTarget.ES6) {
19597+
if (languageVersion < ScriptTarget.ES2015) {
1959819598
verifyHelperSymbol(exports, "__generator", SymbolFlags.Value);
1959919599
}
1960019600
}
@@ -20171,7 +20171,7 @@ namespace ts {
2017120171
if (!node.body) {
2017220172
return grammarErrorOnNode(node.asteriskToken, Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
2017320173
}
20174-
if (languageVersion < ScriptTarget.ES6) {
20174+
if (languageVersion < ScriptTarget.ES2015) {
2017520175
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_2015_or_higher);
2017620176
}
2017720177
}

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace ts {
101101
"amd": ModuleKind.AMD,
102102
"system": ModuleKind.System,
103103
"umd": ModuleKind.UMD,
104-
"es6": ModuleKind.ES6,
104+
"es6": ModuleKind.ES2015,
105105
"es2015": ModuleKind.ES2015,
106106
}),
107107
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
@@ -261,8 +261,10 @@ namespace ts {
261261
type: createMap({
262262
"es3": ScriptTarget.ES3,
263263
"es5": ScriptTarget.ES5,
264-
"es6": ScriptTarget.ES6,
264+
"es6": ScriptTarget.ES2015,
265265
"es2015": ScriptTarget.ES2015,
266+
"es2016": ScriptTarget.ES2016,
267+
"es2017": ScriptTarget.ES2017,
266268
}),
267269
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
268270
paramType: Diagnostics.VERSION,

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ namespace ts {
12381238
export function getEmitModuleKind(compilerOptions: CompilerOptions) {
12391239
return typeof compilerOptions.module === "number" ?
12401240
compilerOptions.module :
1241-
getEmitScriptTarget(compilerOptions) === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.CommonJS;
1241+
getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS;
12421242
}
12431243

12441244
/* @internal */

src/compiler/emitter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ const _super = (function (geti, seti) {
21652165

21662166
// Only Emit __extends function when target ES5.
21672167
// For target ES6 and above, we can emit classDeclaration as is.
2168-
if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && node.flags & NodeFlags.HasClassExtends)) {
2168+
if ((languageVersion < ScriptTarget.ES2015) && (!extendsEmitted && node.flags & NodeFlags.HasClassExtends)) {
21692169
writeLines(extendsHelper);
21702170
extendsEmitted = true;
21712171
helpersEmitted = true;
@@ -2192,9 +2192,12 @@ const _super = (function (geti, seti) {
21922192
helpersEmitted = true;
21932193
}
21942194

2195-
if (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions) {
2195+
// Only emit __awaiter function when target ES5/ES6.
2196+
// Only emit __generator function when target ES5.
2197+
// For target ES2017 and above, we can emit async/await as is.
2198+
if ((languageVersion < ScriptTarget.ES2017) && (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions)) {
21962199
writeLines(awaiterHelper);
2197-
if (languageVersion < ScriptTarget.ES6) {
2200+
if (languageVersion < ScriptTarget.ES2015) {
21982201
writeLines(generatorHelper);
21992202
}
22002203

0 commit comments

Comments
 (0)