Skip to content

Commit

Permalink
Implement the Stage 3 Decorators Proposal (#50820)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton authored Jan 19, 2023
1 parent 20182cf commit 5b18979
Show file tree
Hide file tree
Showing 1,263 changed files with 31,184 additions and 2,585 deletions.
1 change: 1 addition & 0 deletions src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export * from "../transformers/ts";
export * from "../transformers/classFields";
export * from "../transformers/typeSerializer";
export * from "../transformers/legacyDecorators";
export * from "../transformers/esDecorators";
export * from "../transformers/es2017";
export * from "../transformers/es2018";
export * from "../transformers/es2019";
Expand Down
1,501 changes: 1,065 additions & 436 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ const libEntries: [string, string][] = [
["esnext.bigint", "lib.es2020.bigint.d.ts"],
["esnext.string", "lib.es2022.string.d.ts"],
["esnext.promise", "lib.es2021.promise.d.ts"],
["esnext.weakref", "lib.es2021.weakref.d.ts"]
["esnext.weakref", "lib.es2021.weakref.d.ts"],
["decorators", "lib.decorators.d.ts"],
["decorators.legacy", "lib.decorators.legacy.d.ts"],
];

/**
Expand Down Expand Up @@ -1157,10 +1159,11 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
{
name: "experimentalDecorators",
type: "boolean",
affectsEmit: true,
affectsSemanticDiagnostics: true,
affectsBuildInfo: true,
category: Diagnostics.Language_and_Environment,
description: Diagnostics.Enable_experimental_support_for_TC39_stage_2_draft_decorators,
description: Diagnostics.Enable_experimental_support_for_legacy_experimental_decorators,
defaultValueDescription: false,
},
{
Expand Down
47 changes: 41 additions & 6 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,22 @@ export function group<T, K>(values: readonly T[], getGroupId: (value: T) => K, r
return arrayFrom(arrayToMultiMap(values, getGroupId).values(), resultSelector);
}

/** @internal */
export function groupBy<T, U extends T>(values: readonly T[] | undefined, keySelector: (value: T) => value is U): { true?: U[], false?: Exclude<T, U>[] };
/** @internal */
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[]; };
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[]; } {
const result: Record<string, T[]> = {};
if (values) {
for (const value of values) {
const key = `${keySelector(value)}`;
const array = result[key] ??= [];
array.push(value);
}
}
return result as { [P in K as `${P}`]?: T[]; };
}

/** @internal */
export function clone<T>(object: T): T {
const result: any = {};
Expand Down Expand Up @@ -2822,13 +2838,32 @@ export function padRight(s: string, length: number, padString: " " = " ") {
/** @internal */
export function takeWhile<T, U extends T>(array: readonly T[], predicate: (element: T) => element is U): U[];
/** @internal */
export function takeWhile<T>(array: readonly T[], predicate: (element: T) => boolean): T[] {
const len = array.length;
let index = 0;
while (index < len && predicate(array[index])) {
index++;
export function takeWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): U[] | undefined;
export function takeWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): U[] | undefined {
if (array) {
const len = array.length;
let index = 0;
while (index < len && predicate(array[index])) {
index++;
}
return array.slice(0, index) as U[];
}
}

/** @internal */
export function skipWhile<T, U extends T>(array: readonly T[], predicate: (element: T) => element is U): Exclude<T, U>[];
/** @internal */
export function skipWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): Exclude<T, U>[] | undefined;
/** @internal */
export function skipWhile<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T) => element is U): Exclude<T, U>[] | undefined {
if (array) {
const len = array.length;
let index = 0;
while (index < len && predicate(array[index])) {
index++;
}
return array.slice(index) as Exclude<T, U>[];
}
return array.slice(0, index);
}

/**
Expand Down
20 changes: 14 additions & 6 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,6 @@
"category": "Error",
"code": 1218
},
"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.": {
"category": "Error",
"code": 1219
},
"Generators are not allowed in an ambient context.": {
"category": "Error",
"code": 1221
Expand Down Expand Up @@ -911,6 +907,14 @@
"category": "Error",
"code": 1277
},
"The runtime will invoke the decorator with {1} arguments, but the decorator expects {0}.": {
"category": "Error",
"code": 1278
},
"The runtime will invoke the decorator with {1} arguments, but the decorator expects at least {0}.": {
"category": "Error",
"code": 1279
},

"'with' statements are not allowed in an async function block.": {
"category": "Error",
Expand Down Expand Up @@ -1388,7 +1392,7 @@
"category": "Error",
"code": 1432
},
"Decorators may not be applied to 'this' parameters.": {
"Neither decorators nor modifiers may be applied to 'this' parameters.": {
"category": "Error",
"code": 1433
},
Expand Down Expand Up @@ -5655,7 +5659,7 @@
"category": "Message",
"code": 6629
},
"Enable experimental support for TC39 stage 2 draft decorators.": {
"Enable experimental support for legacy experimental decorators.": {
"category": "Message",
"code": 6630
},
Expand Down Expand Up @@ -6488,6 +6492,10 @@
"category": "Error",
"code": 8037
},
"Decorators must come after 'export' or 'export default' in JavaScript files.": {
"category": "Error",
"code": 8038
},

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

0 comments on commit 5b18979

Please sign in to comment.