Skip to content

Commit f4d0ea6

Browse files
saschanazsandersn
andauthored
Add target: ES2021 (#41239)
* Support `target: es2020` * use CRLF * update symbols Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent b20331a commit f4d0ea6

File tree

206 files changed

+2855
-792
lines changed

Some content is hidden

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

206 files changed

+2855
-792
lines changed

src/compiler/commandLineParser.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace ts {
2828
["es2018", "lib.es2018.d.ts"],
2929
["es2019", "lib.es2019.d.ts"],
3030
["es2020", "lib.es2020.d.ts"],
31+
["es2021", "lib.es2021.d.ts"],
3132
["esnext", "lib.esnext.d.ts"],
3233
// Host only
3334
["dom", "lib.dom.d.ts"],
@@ -67,14 +68,17 @@ namespace ts {
6768
["es2020.string", "lib.es2020.string.d.ts"],
6869
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
6970
["es2020.intl", "lib.es2020.intl.d.ts"],
71+
["es2021.promise", "lib.es2021.promise.d.ts"],
72+
["es2021.string", "lib.es2021.string.d.ts"],
73+
["es2021.weakref", "lib.es2021.weakref.d.ts"],
7074
["esnext.array", "lib.es2019.array.d.ts"],
7175
["esnext.symbol", "lib.es2019.symbol.d.ts"],
7276
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
7377
["esnext.intl", "lib.esnext.intl.d.ts"],
7478
["esnext.bigint", "lib.es2020.bigint.d.ts"],
75-
["esnext.string", "lib.esnext.string.d.ts"],
76-
["esnext.promise", "lib.esnext.promise.d.ts"],
77-
["esnext.weakref", "lib.esnext.weakref.d.ts"]
79+
["esnext.string", "lib.es2021.string.d.ts"],
80+
["esnext.promise", "lib.es2021.promise.d.ts"],
81+
["esnext.weakref", "lib.es2021.weakref.d.ts"]
7882
];
7983

8084
/**
@@ -290,6 +294,7 @@ namespace ts {
290294
es2018: ScriptTarget.ES2018,
291295
es2019: ScriptTarget.ES2019,
292296
es2020: ScriptTarget.ES2020,
297+
es2021: ScriptTarget.ES2021,
293298
esnext: ScriptTarget.ESNext,
294299
})),
295300
affectsSourceFile: true,
@@ -298,7 +303,7 @@ namespace ts {
298303
paramType: Diagnostics.VERSION,
299304
showInSimplifiedHelpView: true,
300305
category: Diagnostics.Basic_Options,
301-
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_ES2019_ES2020_or_ESNEXT,
306+
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_ES2019_ES2020_ES2021_or_ESNEXT,
302307
};
303308

304309
/* @internal */

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,7 @@
39153915
"category": "Message",
39163916
"code": 6014
39173917
},
3918-
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'.": {
3918+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'.": {
39193919
"category": "Message",
39203920
"code": 6015
39213921
},

src/compiler/factory/nodeFactory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ namespace ts {
27132713
node.transformFlags |= TransformFlags.ContainsES2016;
27142714
}
27152715
else if (isLogicalOrCoalescingAssignmentOperator(operatorKind)) {
2716-
node.transformFlags |= TransformFlags.ContainsESNext;
2716+
node.transformFlags |= TransformFlags.ContainsES2021;
27172717
}
27182718
return node;
27192719
}

src/compiler/transformer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ namespace ts {
5454
transformers.push(transformESNext);
5555
}
5656

57+
if (languageVersion < ScriptTarget.ES2021) {
58+
transformers.push(transformES2021);
59+
}
60+
5761
if (languageVersion < ScriptTarget.ES2020) {
5862
transformers.push(transformES2020);
5963
}

src/compiler/transformers/es2021.ts

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*@internal*/
2+
namespace ts {
3+
export function transformES2021(context: TransformationContext) {
4+
const {
5+
hoistVariableDeclaration,
6+
factory
7+
} = context;
8+
return chainBundle(context, transformSourceFile);
9+
10+
function transformSourceFile(node: SourceFile) {
11+
if (node.isDeclarationFile) {
12+
return node;
13+
}
14+
15+
return visitEachChild(node, visitor, context);
16+
}
17+
18+
function visitor(node: Node): VisitResult<Node> {
19+
if ((node.transformFlags & TransformFlags.ContainsES2021) === 0) {
20+
return node;
21+
}
22+
switch (node.kind) {
23+
case SyntaxKind.BinaryExpression:
24+
const binaryExpression = <BinaryExpression>node;
25+
if (isLogicalOrCoalescingAssignmentExpression(binaryExpression)) {
26+
return transformLogicalAssignment(binaryExpression);
27+
}
28+
// falls through
29+
default:
30+
return visitEachChild(node, visitor, context);
31+
}
32+
}
33+
34+
function transformLogicalAssignment(binaryExpression: AssignmentExpression<Token<LogicalOrCoalescingAssignmentOperator>>): VisitResult<Node> {
35+
const operator = binaryExpression.operatorToken;
36+
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
37+
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
38+
let assignmentTarget = left;
39+
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));
40+
41+
if (isAccessExpression(left)) {
42+
const propertyAccessTargetSimpleCopiable = isSimpleCopiableExpression(left.expression);
43+
const propertyAccessTarget = propertyAccessTargetSimpleCopiable ? left.expression :
44+
factory.createTempVariable(hoistVariableDeclaration);
45+
const propertyAccessTargetAssignment = propertyAccessTargetSimpleCopiable ? left.expression : factory.createAssignment(
46+
propertyAccessTarget,
47+
left.expression
48+
);
49+
50+
if (isPropertyAccessExpression(left)) {
51+
assignmentTarget = factory.createPropertyAccessExpression(
52+
propertyAccessTarget,
53+
left.name
54+
);
55+
left = factory.createPropertyAccessExpression(
56+
propertyAccessTargetAssignment,
57+
left.name
58+
);
59+
}
60+
else {
61+
const elementAccessArgumentSimpleCopiable = isSimpleCopiableExpression(left.argumentExpression);
62+
const elementAccessArgument = elementAccessArgumentSimpleCopiable ? left.argumentExpression :
63+
factory.createTempVariable(hoistVariableDeclaration);
64+
65+
assignmentTarget = factory.createElementAccessExpression(
66+
propertyAccessTarget,
67+
elementAccessArgument
68+
);
69+
left = factory.createElementAccessExpression(
70+
propertyAccessTargetAssignment,
71+
elementAccessArgumentSimpleCopiable ? left.argumentExpression : factory.createAssignment(
72+
elementAccessArgument,
73+
left.argumentExpression
74+
)
75+
);
76+
}
77+
}
78+
79+
return factory.createBinaryExpression(
80+
left,
81+
nonAssignmentOperator,
82+
factory.createParenthesizedExpression(
83+
factory.createAssignment(
84+
assignmentTarget,
85+
right
86+
)
87+
)
88+
);
89+
}
90+
}
91+
}

src/compiler/transformers/esnext.ts

+21-88
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,24 @@
11
/*@internal*/
22
namespace ts {
3-
export function transformESNext(context: TransformationContext) {
4-
const {
5-
hoistVariableDeclaration,
6-
factory
7-
} = context;
8-
return chainBundle(context, transformSourceFile);
9-
10-
function transformSourceFile(node: SourceFile) {
11-
if (node.isDeclarationFile) {
12-
return node;
13-
}
14-
15-
return visitEachChild(node, visitor, context);
16-
}
17-
18-
function visitor(node: Node): VisitResult<Node> {
19-
if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) {
20-
return node;
21-
}
22-
switch (node.kind) {
23-
case SyntaxKind.BinaryExpression:
24-
const binaryExpression = <BinaryExpression>node;
25-
if (isLogicalOrCoalescingAssignmentExpression(binaryExpression)) {
26-
return transformLogicalAssignment(binaryExpression);
27-
}
28-
// falls through
29-
default:
30-
return visitEachChild(node, visitor, context);
31-
}
32-
}
33-
34-
function transformLogicalAssignment(binaryExpression: AssignmentExpression<Token<LogicalOrCoalescingAssignmentOperator>>): VisitResult<Node> {
35-
const operator = binaryExpression.operatorToken;
36-
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
37-
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
38-
let assignmentTarget = left;
39-
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));
40-
41-
if (isAccessExpression(left)) {
42-
const propertyAccessTargetSimpleCopiable = isSimpleCopiableExpression(left.expression);
43-
const propertyAccessTarget = propertyAccessTargetSimpleCopiable ? left.expression :
44-
factory.createTempVariable(hoistVariableDeclaration);
45-
const propertyAccessTargetAssignment = propertyAccessTargetSimpleCopiable ? left.expression : factory.createAssignment(
46-
propertyAccessTarget,
47-
left.expression
48-
);
49-
50-
if (isPropertyAccessExpression(left)) {
51-
assignmentTarget = factory.createPropertyAccessExpression(
52-
propertyAccessTarget,
53-
left.name
54-
);
55-
left = factory.createPropertyAccessExpression(
56-
propertyAccessTargetAssignment,
57-
left.name
58-
);
59-
}
60-
else {
61-
const elementAccessArgumentSimpleCopiable = isSimpleCopiableExpression(left.argumentExpression);
62-
const elementAccessArgument = elementAccessArgumentSimpleCopiable ? left.argumentExpression :
63-
factory.createTempVariable(hoistVariableDeclaration);
64-
65-
assignmentTarget = factory.createElementAccessExpression(
66-
propertyAccessTarget,
67-
elementAccessArgument
68-
);
69-
left = factory.createElementAccessExpression(
70-
propertyAccessTargetAssignment,
71-
elementAccessArgumentSimpleCopiable ? left.argumentExpression : factory.createAssignment(
72-
elementAccessArgument,
73-
left.argumentExpression
74-
)
75-
);
76-
}
77-
}
78-
79-
return factory.createBinaryExpression(
80-
left,
81-
nonAssignmentOperator,
82-
factory.createParenthesizedExpression(
83-
factory.createAssignment(
84-
assignmentTarget,
85-
right
86-
)
87-
)
88-
);
89-
}
90-
}
3+
export function transformESNext(context: TransformationContext) {
4+
return chainBundle(context, transformSourceFile);
5+
6+
function transformSourceFile(node: SourceFile) {
7+
if (node.isDeclarationFile) {
8+
return node;
9+
}
10+
11+
return visitEachChild(node, visitor, context);
12+
}
13+
14+
function visitor(node: Node): VisitResult<Node> {
15+
if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) {
16+
return node;
17+
}
18+
switch (node.kind) {
19+
default:
20+
return visitEachChild(node, visitor, context);
21+
}
22+
}
23+
}
9124
}

src/compiler/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"transformers/es2018.ts",
5454
"transformers/es2019.ts",
5555
"transformers/es2020.ts",
56+
"transformers/es2021.ts",
5657
"transformers/esnext.ts",
5758
"transformers/jsx.ts",
5859
"transformers/es2016.ts",

src/compiler/types.ts

+24-21
Original file line numberDiff line numberDiff line change
@@ -6032,6 +6032,7 @@ namespace ts {
60326032
ES2018 = 5,
60336033
ES2019 = 6,
60346034
ES2020 = 7,
6035+
ES2021 = 8,
60356036
ESNext = 99,
60366037
JSON = 100,
60376038
Latest = ESNext,
@@ -6443,30 +6444,31 @@ namespace ts {
64436444
ContainsTypeScript = 1 << 0,
64446445
ContainsJsx = 1 << 1,
64456446
ContainsESNext = 1 << 2,
6446-
ContainsES2020 = 1 << 3,
6447-
ContainsES2019 = 1 << 4,
6448-
ContainsES2018 = 1 << 5,
6449-
ContainsES2017 = 1 << 6,
6450-
ContainsES2016 = 1 << 7,
6451-
ContainsES2015 = 1 << 8,
6452-
ContainsGenerator = 1 << 9,
6453-
ContainsDestructuringAssignment = 1 << 10,
6447+
ContainsES2021 = 1 << 3,
6448+
ContainsES2020 = 1 << 4,
6449+
ContainsES2019 = 1 << 5,
6450+
ContainsES2018 = 1 << 6,
6451+
ContainsES2017 = 1 << 7,
6452+
ContainsES2016 = 1 << 8,
6453+
ContainsES2015 = 1 << 9,
6454+
ContainsGenerator = 1 << 10,
6455+
ContainsDestructuringAssignment = 1 << 11,
64546456

64556457
// Markers
64566458
// - Flags used to indicate that a subtree contains a specific transformation.
6457-
ContainsTypeScriptClassSyntax = 1 << 11, // Decorators, Property Initializers, Parameter Property Initializers
6458-
ContainsLexicalThis = 1 << 12,
6459-
ContainsRestOrSpread = 1 << 13,
6460-
ContainsObjectRestOrSpread = 1 << 14,
6461-
ContainsComputedPropertyName = 1 << 15,
6462-
ContainsBlockScopedBinding = 1 << 16,
6463-
ContainsBindingPattern = 1 << 17,
6464-
ContainsYield = 1 << 18,
6465-
ContainsAwait = 1 << 19,
6466-
ContainsHoistedDeclarationOrCompletion = 1 << 20,
6467-
ContainsDynamicImport = 1 << 21,
6468-
ContainsClassFields = 1 << 22,
6469-
ContainsPossibleTopLevelAwait = 1 << 23,
6459+
ContainsTypeScriptClassSyntax = 1 << 12, // Decorators, Property Initializers, Parameter Property Initializers
6460+
ContainsLexicalThis = 1 << 13,
6461+
ContainsRestOrSpread = 1 << 14,
6462+
ContainsObjectRestOrSpread = 1 << 15,
6463+
ContainsComputedPropertyName = 1 << 16,
6464+
ContainsBlockScopedBinding = 1 << 17,
6465+
ContainsBindingPattern = 1 << 18,
6466+
ContainsYield = 1 << 19,
6467+
ContainsAwait = 1 << 20,
6468+
ContainsHoistedDeclarationOrCompletion = 1 << 21,
6469+
ContainsDynamicImport = 1 << 22,
6470+
ContainsClassFields = 1 << 23,
6471+
ContainsPossibleTopLevelAwait = 1 << 24,
64706472

64716473
// Please leave this as 1 << 29.
64726474
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.
@@ -6478,6 +6480,7 @@ namespace ts {
64786480
AssertTypeScript = ContainsTypeScript,
64796481
AssertJsx = ContainsJsx,
64806482
AssertESNext = ContainsESNext,
6483+
AssertES2021 = ContainsES2021,
64816484
AssertES2020 = ContainsES2020,
64826485
AssertES2019 = ContainsES2019,
64836486
AssertES2018 = ContainsES2018,

src/compiler/utilities.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,11 @@ namespace ts {
603603
DataView: ["setBigInt64", "setBigUint64", "getBigInt64", "getBigUint64"],
604604
RelativeTimeFormat: ["format", "formatToParts", "resolvedOptions"]
605605
},
606-
esnext: {
606+
es2021: {
607607
PromiseConstructor: ["any"],
608-
String: ["replaceAll"],
608+
String: ["replaceAll"]
609+
},
610+
esnext: {
609611
NumberFormat: ["formatToParts"]
610612
}
611613
};

src/compiler/utilitiesPublic.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace ts {
1414
switch (options.target) {
1515
case ScriptTarget.ESNext:
1616
return "lib.esnext.full.d.ts";
17+
case ScriptTarget.ES2021:
18+
return "lib.es2021.full.d.ts";
1719
case ScriptTarget.ES2020:
1820
return "lib.es2020.full.d.ts";
1921
case ScriptTarget.ES2019:

src/lib/es2021.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// <reference lib="es2020" />
2+
/// <reference lib="es2021.promise" />
3+
/// <reference lib="es2021.string" />
4+
/// <reference lib="es2021.weakref" />

src/lib/es2021.full.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2021" />
2+
/// <reference lib="dom" />
3+
/// <reference lib="webworker.importscripts" />
4+
/// <reference lib="scripthost" />
5+
/// <reference lib="dom.iterable" />
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/lib/esnext.d.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
/// <reference lib="es2020" />
1+
/// <reference lib="es2021" />
22
/// <reference lib="esnext.intl" />
3-
/// <reference lib="esnext.string" />
4-
/// <reference lib="esnext.promise" />
5-
/// <reference lib="esnext.weakref" />

0 commit comments

Comments
 (0)