Skip to content

Commit 5b18979

Browse files
authored
Implement the Stage 3 Decorators Proposal (#50820)
1 parent 20182cf commit 5b18979

File tree

1,263 files changed

+31184
-2585
lines changed

Some content is hidden

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

1,263 files changed

+31184
-2585
lines changed

src/compiler/_namespaces/ts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export * from "../transformers/ts";
3838
export * from "../transformers/classFields";
3939
export * from "../transformers/typeSerializer";
4040
export * from "../transformers/legacyDecorators";
41+
export * from "../transformers/esDecorators";
4142
export * from "../transformers/es2017";
4243
export * from "../transformers/es2018";
4344
export * from "../transformers/es2019";

src/compiler/checker.ts

+1,065-436
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ const libEntries: [string, string][] = [
218218
["esnext.bigint", "lib.es2020.bigint.d.ts"],
219219
["esnext.string", "lib.es2022.string.d.ts"],
220220
["esnext.promise", "lib.es2021.promise.d.ts"],
221-
["esnext.weakref", "lib.es2021.weakref.d.ts"]
221+
["esnext.weakref", "lib.es2021.weakref.d.ts"],
222+
["decorators", "lib.decorators.d.ts"],
223+
["decorators.legacy", "lib.decorators.legacy.d.ts"],
222224
];
223225

224226
/**
@@ -1157,10 +1159,11 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
11571159
{
11581160
name: "experimentalDecorators",
11591161
type: "boolean",
1162+
affectsEmit: true,
11601163
affectsSemanticDiagnostics: true,
11611164
affectsBuildInfo: true,
11621165
category: Diagnostics.Language_and_Environment,
1163-
description: Diagnostics.Enable_experimental_support_for_TC39_stage_2_draft_decorators,
1166+
description: Diagnostics.Enable_experimental_support_for_legacy_experimental_decorators,
11641167
defaultValueDescription: false,
11651168
},
11661169
{

src/compiler/core.ts

+41-6
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,22 @@ export function group<T, K>(values: readonly T[], getGroupId: (value: T) => K, r
15461546
return arrayFrom(arrayToMultiMap(values, getGroupId).values(), resultSelector);
15471547
}
15481548

1549+
/** @internal */
1550+
export function groupBy<T, U extends T>(values: readonly T[] | undefined, keySelector: (value: T) => value is U): { true?: U[], false?: Exclude<T, U>[] };
1551+
/** @internal */
1552+
export function groupBy<T, K extends string | number | boolean | null | undefined>(values: readonly T[] | undefined, keySelector: (value: T) => K): { [P in K as `${P}`]?: T[]; };
1553+
export function groupBy<T, K extends string | number | boolean | null | undefined>(values: readonly T[] | undefined, keySelector: (value: T) => K): { [P in K as `${P}`]?: T[]; } {
1554+
const result: Record<string, T[]> = {};
1555+
if (values) {
1556+
for (const value of values) {
1557+
const key = `${keySelector(value)}`;
1558+
const array = result[key] ??= [];
1559+
array.push(value);
1560+
}
1561+
}
1562+
return result as { [P in K as `${P}`]?: T[]; };
1563+
}
1564+
15491565
/** @internal */
15501566
export function clone<T>(object: T): T {
15511567
const result: any = {};
@@ -2822,13 +2838,32 @@ export function padRight(s: string, length: number, padString: " " = " ") {
28222838
/** @internal */
28232839
export function takeWhile<T, U extends T>(array: readonly T[], predicate: (element: T) => element is U): U[];
28242840
/** @internal */
2825-
export function takeWhile<T>(array: readonly T[], predicate: (element: T) => boolean): T[] {
2826-
const len = array.length;
2827-
let index = 0;
2828-
while (index < len && predicate(array[index])) {
2829-
index++;
2841+
export function takeWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): U[] | undefined;
2842+
export function takeWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): U[] | undefined {
2843+
if (array) {
2844+
const len = array.length;
2845+
let index = 0;
2846+
while (index < len && predicate(array[index])) {
2847+
index++;
2848+
}
2849+
return array.slice(0, index) as U[];
2850+
}
2851+
}
2852+
2853+
/** @internal */
2854+
export function skipWhile<T, U extends T>(array: readonly T[], predicate: (element: T) => element is U): Exclude<T, U>[];
2855+
/** @internal */
2856+
export function skipWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): Exclude<T, U>[] | undefined;
2857+
/** @internal */
2858+
export function skipWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): Exclude<T, U>[] | undefined {
2859+
if (array) {
2860+
const len = array.length;
2861+
let index = 0;
2862+
while (index < len && predicate(array[index])) {
2863+
index++;
2864+
}
2865+
return array.slice(index) as Exclude<T, U>[];
28302866
}
2831-
return array.slice(0, index);
28322867
}
28332868

28342869
/**

src/compiler/diagnosticMessages.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,6 @@
687687
"category": "Error",
688688
"code": 1218
689689
},
690-
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.": {
691-
"category": "Error",
692-
"code": 1219
693-
},
694690
"Generators are not allowed in an ambient context.": {
695691
"category": "Error",
696692
"code": 1221
@@ -911,6 +907,14 @@
911907
"category": "Error",
912908
"code": 1277
913909
},
910+
"The runtime will invoke the decorator with {1} arguments, but the decorator expects {0}.": {
911+
"category": "Error",
912+
"code": 1278
913+
},
914+
"The runtime will invoke the decorator with {1} arguments, but the decorator expects at least {0}.": {
915+
"category": "Error",
916+
"code": 1279
917+
},
914918

915919
"'with' statements are not allowed in an async function block.": {
916920
"category": "Error",
@@ -1388,7 +1392,7 @@
13881392
"category": "Error",
13891393
"code": 1432
13901394
},
1391-
"Decorators may not be applied to 'this' parameters.": {
1395+
"Neither decorators nor modifiers may be applied to 'this' parameters.": {
13921396
"category": "Error",
13931397
"code": 1433
13941398
},
@@ -5655,7 +5659,7 @@
56555659
"category": "Message",
56565660
"code": 6629
56575661
},
5658-
"Enable experimental support for TC39 stage 2 draft decorators.": {
5662+
"Enable experimental support for legacy experimental decorators.": {
56595663
"category": "Message",
56605664
"code": 6630
56615665
},
@@ -6488,6 +6492,10 @@
64886492
"category": "Error",
64896493
"code": 8037
64906494
},
6495+
"Decorators must come after 'export' or 'export default' in JavaScript files.": {
6496+
"category": "Error",
6497+
"code": 8038
6498+
},
64916499

64926500
"Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit.": {
64936501
"category": "Error",

0 commit comments

Comments
 (0)