Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ts {
["es2018", "lib.es2018.d.ts"],
["es2019", "lib.es2019.d.ts"],
["es2020", "lib.es2020.d.ts"],
["es2021", "lib.es2021.d.ts"],
["esnext", "lib.esnext.d.ts"],
// Host only
["dom", "lib.dom.d.ts"],
Expand Down Expand Up @@ -67,14 +68,17 @@ namespace ts {
["es2020.string", "lib.es2020.string.d.ts"],
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
["es2020.intl", "lib.es2020.intl.d.ts"],
["es2021.promise", "lib.es2021.promise.d.ts"],
["es2021.string", "lib.es2021.string.d.ts"],
["es2021.weakref", "lib.es2021.weakref.d.ts"],
["esnext.array", "lib.es2019.array.d.ts"],
["esnext.symbol", "lib.es2019.symbol.d.ts"],
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
["esnext.intl", "lib.esnext.intl.d.ts"],
["esnext.bigint", "lib.es2020.bigint.d.ts"],
["esnext.string", "lib.esnext.string.d.ts"],
Comment thread
sandersn marked this conversation as resolved.
["esnext.promise", "lib.esnext.promise.d.ts"],
["esnext.weakref", "lib.esnext.weakref.d.ts"]
["esnext.string", "lib.es2021.string.d.ts"],
["esnext.promise", "lib.es2021.promise.d.ts"],
["esnext.weakref", "lib.es2021.weakref.d.ts"]
];

/**
Expand Down Expand Up @@ -290,6 +294,7 @@ namespace ts {
es2018: ScriptTarget.ES2018,
es2019: ScriptTarget.ES2019,
es2020: ScriptTarget.ES2020,
es2021: ScriptTarget.ES2021,
esnext: ScriptTarget.ESNext,
})),
affectsSourceFile: true,
Expand All @@ -298,7 +303,7 @@ namespace ts {
paramType: Diagnostics.VERSION,
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_ES2019_ES2020_or_ESNEXT,
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_ES2019_ES2020_ES2021_or_ESNEXT,
};

/* @internal */
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3915,7 +3915,7 @@
"category": "Message",
"code": 6014
},
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'.": {
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'.": {
"category": "Message",
"code": 6015
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2713,7 +2713,7 @@ namespace ts {
node.transformFlags |= TransformFlags.ContainsES2016;
}
else if (isLogicalOrCoalescingAssignmentOperator(operatorKind)) {
node.transformFlags |= TransformFlags.ContainsESNext;
node.transformFlags |= TransformFlags.ContainsES2021;
}
return node;
}
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace ts {
transformers.push(transformESNext);
}

if (languageVersion < ScriptTarget.ES2021) {
transformers.push(transformES2021);
}

if (languageVersion < ScriptTarget.ES2020) {
transformers.push(transformES2020);
}
Expand Down
91 changes: 91 additions & 0 deletions src/compiler/transformers/es2021.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*@internal*/
namespace ts {
export function transformES2021(context: TransformationContext) {
const {
hoistVariableDeclaration,
factory
} = context;
return chainBundle(context, transformSourceFile);

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
return node;
}

return visitEachChild(node, visitor, context);
}

function visitor(node: Node): VisitResult<Node> {
if ((node.transformFlags & TransformFlags.ContainsES2021) === 0) {
return node;
}
switch (node.kind) {
case SyntaxKind.BinaryExpression:
const binaryExpression = <BinaryExpression>node;
if (isLogicalOrCoalescingAssignmentExpression(binaryExpression)) {
return transformLogicalAssignment(binaryExpression);
}
// falls through
default:
return visitEachChild(node, visitor, context);
}
}

function transformLogicalAssignment(binaryExpression: AssignmentExpression<Token<LogicalOrCoalescingAssignmentOperator>>): VisitResult<Node> {
const operator = binaryExpression.operatorToken;
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
let assignmentTarget = left;
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));

if (isAccessExpression(left)) {
const propertyAccessTargetSimpleCopiable = isSimpleCopiableExpression(left.expression);
const propertyAccessTarget = propertyAccessTargetSimpleCopiable ? left.expression :
factory.createTempVariable(hoistVariableDeclaration);
const propertyAccessTargetAssignment = propertyAccessTargetSimpleCopiable ? left.expression : factory.createAssignment(
propertyAccessTarget,
left.expression
);

if (isPropertyAccessExpression(left)) {
assignmentTarget = factory.createPropertyAccessExpression(
propertyAccessTarget,
left.name
);
left = factory.createPropertyAccessExpression(
propertyAccessTargetAssignment,
left.name
);
}
else {
const elementAccessArgumentSimpleCopiable = isSimpleCopiableExpression(left.argumentExpression);
const elementAccessArgument = elementAccessArgumentSimpleCopiable ? left.argumentExpression :
factory.createTempVariable(hoistVariableDeclaration);

assignmentTarget = factory.createElementAccessExpression(
propertyAccessTarget,
elementAccessArgument
);
left = factory.createElementAccessExpression(
propertyAccessTargetAssignment,
elementAccessArgumentSimpleCopiable ? left.argumentExpression : factory.createAssignment(
elementAccessArgument,
left.argumentExpression
)
);
}
}

return factory.createBinaryExpression(
left,
nonAssignmentOperator,
factory.createParenthesizedExpression(
factory.createAssignment(
assignmentTarget,
right
)
)
);
}
}
}
109 changes: 21 additions & 88 deletions src/compiler/transformers/esnext.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,24 @@
/*@internal*/
namespace ts {
export function transformESNext(context: TransformationContext) {
const {
hoistVariableDeclaration,
factory
} = context;
return chainBundle(context, transformSourceFile);

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
return node;
}

return visitEachChild(node, visitor, context);
}

function visitor(node: Node): VisitResult<Node> {
if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) {
return node;
}
switch (node.kind) {
case SyntaxKind.BinaryExpression:
const binaryExpression = <BinaryExpression>node;
if (isLogicalOrCoalescingAssignmentExpression(binaryExpression)) {
return transformLogicalAssignment(binaryExpression);
}
// falls through
default:
return visitEachChild(node, visitor, context);
}
}

function transformLogicalAssignment(binaryExpression: AssignmentExpression<Token<LogicalOrCoalescingAssignmentOperator>>): VisitResult<Node> {
const operator = binaryExpression.operatorToken;
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
let assignmentTarget = left;
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));

if (isAccessExpression(left)) {
const propertyAccessTargetSimpleCopiable = isSimpleCopiableExpression(left.expression);
const propertyAccessTarget = propertyAccessTargetSimpleCopiable ? left.expression :
factory.createTempVariable(hoistVariableDeclaration);
const propertyAccessTargetAssignment = propertyAccessTargetSimpleCopiable ? left.expression : factory.createAssignment(
propertyAccessTarget,
left.expression
);

if (isPropertyAccessExpression(left)) {
assignmentTarget = factory.createPropertyAccessExpression(
propertyAccessTarget,
left.name
);
left = factory.createPropertyAccessExpression(
propertyAccessTargetAssignment,
left.name
);
}
else {
const elementAccessArgumentSimpleCopiable = isSimpleCopiableExpression(left.argumentExpression);
const elementAccessArgument = elementAccessArgumentSimpleCopiable ? left.argumentExpression :
factory.createTempVariable(hoistVariableDeclaration);

assignmentTarget = factory.createElementAccessExpression(
propertyAccessTarget,
elementAccessArgument
);
left = factory.createElementAccessExpression(
propertyAccessTargetAssignment,
elementAccessArgumentSimpleCopiable ? left.argumentExpression : factory.createAssignment(
elementAccessArgument,
left.argumentExpression
)
);
}
}

return factory.createBinaryExpression(
left,
nonAssignmentOperator,
factory.createParenthesizedExpression(
factory.createAssignment(
assignmentTarget,
right
)
)
);
}
}
export function transformESNext(context: TransformationContext) {
return chainBundle(context, transformSourceFile);

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
return node;
}

return visitEachChild(node, visitor, context);
}

function visitor(node: Node): VisitResult<Node> {
if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) {
return node;
}
switch (node.kind) {
default:
return visitEachChild(node, visitor, context);
}
}
}
}
1 change: 1 addition & 0 deletions src/compiler/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"transformers/es2018.ts",
"transformers/es2019.ts",
"transformers/es2020.ts",
"transformers/es2021.ts",
"transformers/esnext.ts",
"transformers/jsx.ts",
"transformers/es2016.ts",
Expand Down
45 changes: 24 additions & 21 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6032,6 +6032,7 @@ namespace ts {
ES2018 = 5,
ES2019 = 6,
ES2020 = 7,
ES2021 = 8,
ESNext = 99,
JSON = 100,
Latest = ESNext,
Expand Down Expand Up @@ -6443,30 +6444,31 @@ namespace ts {
ContainsTypeScript = 1 << 0,
ContainsJsx = 1 << 1,
ContainsESNext = 1 << 2,
ContainsES2020 = 1 << 3,
ContainsES2019 = 1 << 4,
ContainsES2018 = 1 << 5,
ContainsES2017 = 1 << 6,
ContainsES2016 = 1 << 7,
ContainsES2015 = 1 << 8,
ContainsGenerator = 1 << 9,
ContainsDestructuringAssignment = 1 << 10,
ContainsES2021 = 1 << 3,
ContainsES2020 = 1 << 4,
ContainsES2019 = 1 << 5,
ContainsES2018 = 1 << 6,
ContainsES2017 = 1 << 7,
ContainsES2016 = 1 << 8,
ContainsES2015 = 1 << 9,
ContainsGenerator = 1 << 10,
ContainsDestructuringAssignment = 1 << 11,

// Markers
// - Flags used to indicate that a subtree contains a specific transformation.
ContainsTypeScriptClassSyntax = 1 << 11, // Decorators, Property Initializers, Parameter Property Initializers
ContainsLexicalThis = 1 << 12,
ContainsRestOrSpread = 1 << 13,
ContainsObjectRestOrSpread = 1 << 14,
ContainsComputedPropertyName = 1 << 15,
ContainsBlockScopedBinding = 1 << 16,
ContainsBindingPattern = 1 << 17,
ContainsYield = 1 << 18,
ContainsAwait = 1 << 19,
ContainsHoistedDeclarationOrCompletion = 1 << 20,
ContainsDynamicImport = 1 << 21,
ContainsClassFields = 1 << 22,
ContainsPossibleTopLevelAwait = 1 << 23,
ContainsTypeScriptClassSyntax = 1 << 12, // Decorators, Property Initializers, Parameter Property Initializers
ContainsLexicalThis = 1 << 13,
ContainsRestOrSpread = 1 << 14,
ContainsObjectRestOrSpread = 1 << 15,
ContainsComputedPropertyName = 1 << 16,
ContainsBlockScopedBinding = 1 << 17,
ContainsBindingPattern = 1 << 18,
ContainsYield = 1 << 19,
ContainsAwait = 1 << 20,
ContainsHoistedDeclarationOrCompletion = 1 << 21,
ContainsDynamicImport = 1 << 22,
ContainsClassFields = 1 << 23,
ContainsPossibleTopLevelAwait = 1 << 24,

// Please leave this as 1 << 29.
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.
Expand All @@ -6478,6 +6480,7 @@ namespace ts {
AssertTypeScript = ContainsTypeScript,
AssertJsx = ContainsJsx,
AssertESNext = ContainsESNext,
AssertES2021 = ContainsES2021,
AssertES2020 = ContainsES2020,
AssertES2019 = ContainsES2019,
AssertES2018 = ContainsES2018,
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,11 @@ namespace ts {
DataView: ["setBigInt64", "setBigUint64", "getBigInt64", "getBigUint64"],
RelativeTimeFormat: ["format", "formatToParts", "resolvedOptions"]
},
esnext: {
es2021: {
PromiseConstructor: ["any"],
String: ["replaceAll"],
String: ["replaceAll"]
},
esnext: {
NumberFormat: ["formatToParts"]
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace ts {
switch (options.target) {
case ScriptTarget.ESNext:
return "lib.esnext.full.d.ts";
case ScriptTarget.ES2021:
return "lib.es2021.full.d.ts";
case ScriptTarget.ES2020:
return "lib.es2020.full.d.ts";
case ScriptTarget.ES2019:
Expand Down
4 changes: 4 additions & 0 deletions src/lib/es2021.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference lib="es2020" />
/// <reference lib="es2021.promise" />
/// <reference lib="es2021.string" />
/// <reference lib="es2021.weakref" />
5 changes: 5 additions & 0 deletions src/lib/es2021.full.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference lib="es2021" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions src/lib/esnext.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
/// <reference lib="es2020" />
/// <reference lib="es2021" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.string" />
/// <reference lib="esnext.promise" />
/// <reference lib="esnext.weakref" />
Loading