Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Stage 3 Decorators Proposal #50820

Merged
merged 69 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
59162fd
Support for auto-accessor fields
rbuckton Jun 28, 2022
34da680
Add tests, ensure accessors are initialized in ctor
rbuckton Aug 9, 2022
02405ec
classFields cleanup and PR feedback
rbuckton Sep 1, 2022
9d1176a
Support for auto-accessor fields
rbuckton Jun 28, 2022
b853cb7
Add tests, ensure accessors are initialized in ctor
rbuckton Aug 9, 2022
96c9393
Thread 'experimentalDecorators' through some utility functions
rbuckton Aug 24, 2022
fdfb49c
Split out decorators types from the default lib
rbuckton Aug 25, 2022
beb8e0a
Allow 'export default' before decorators
rbuckton Aug 26, 2022
f5c6935
Clean up ts class transformation
rbuckton Aug 31, 2022
50c7e00
WIP Stage 3 Decorators
rbuckton Sep 17, 2022
86e0cd2
Evaluation tests and bug fixes
rbuckton Sep 19, 2022
e87b89c
Merge branch 'main' into decorators-stage-3
rbuckton Sep 20, 2022
8c33a18
Set script target for esDecorator evaluator tests to ES2021
rbuckton Sep 20, 2022
3da06f6
Merge branch 'main' into decorators-stage-3
rbuckton Sep 20, 2022
63df46d
Support static private elements with class decorators
rbuckton Sep 28, 2022
ba66494
Merge branch 'main' into decorators-stage-3
rbuckton Sep 28, 2022
5797ac7
Accept baselines after merge
rbuckton Sep 28, 2022
712b037
Contextual types for decorators
rbuckton Sep 30, 2022
8f3ee6a
Improve comment preservation
rbuckton Oct 10, 2022
24b18d7
SourceMap validation
rbuckton Oct 14, 2022
b289642
Remove excess temp in computed name, fix collision in generated names
rbuckton Oct 15, 2022
32c4ed6
Merge branch 'main' into decorators-stage-3
rbuckton Oct 17, 2022
caea4b0
Fix for ClassGetter/SetterDecoratorFunction target types
rbuckton Oct 20, 2022
8abe852
decorator typing updates, minor fixes, remove --annotateTransforms
rbuckton Oct 25, 2022
d330199
getDecoratorCallSignature clean up, make ES and legacy decorators han…
rbuckton Oct 26, 2022
49dbc72
Address additional PR feedback
rbuckton Oct 27, 2022
2142a10
Remove extranous loop in transformClassLike
rbuckton Oct 30, 2022
b5a2ad6
Additional PR feedback, cleanup and fixes
rbuckton Oct 31, 2022
c837d78
revert change to isParameterPropertyDeclaration
rbuckton Nov 1, 2022
c954517
Cleanup of lib.decorators types, added documentation
rbuckton Nov 4, 2022
aece08d
Merge branch 'main' into decorators-stage-3
rbuckton Nov 5, 2022
d65c50b
Fix for missing initializer, some decorators.d.ts type cleanup
rbuckton Nov 7, 2022
aaa2966
Merge branch 'main' into decorators-stage-3
rbuckton Nov 8, 2022
c2b35ff
Merge branch 'main' into decorators-stage-3
rbuckton Nov 8, 2022
995e961
Improve importHelper warnings for missing helpers
rbuckton Nov 8, 2022
0d9504e
Handle named evaluation in parameters, fix test failures
rbuckton Nov 9, 2022
c83e46d
Remove src/lib/decorators.parameters.d.ts
rbuckton Nov 9, 2022
f4294f3
Remove *DecoratorFunctionTypes
rbuckton Nov 9, 2022
1fbaa5c
Fix inconsistent indentation due to merge
rbuckton Nov 15, 2022
09a6a36
Merge branch 'main' into decorators-stage-3
rbuckton Nov 16, 2022
923ce71
Merge branch 'main' into decorators-stage-3
rbuckton Nov 28, 2022
4841c5f
Add cache for decorator context override type
rbuckton Dec 14, 2022
1717240
Merge branch 'main' into decorators-stage-3
rbuckton Dec 14, 2022
1746823
Update syntactic diagnostics for JS files
rbuckton Dec 16, 2022
82d822a
Merge branch 'main' into decorators-stage-3
rbuckton Dec 16, 2022
50ac2b8
Remove 'Experimental decorators' warning from diagnosticMessages.json
rbuckton Dec 16, 2022
50ae4df
Remove 'experimentalDecorators' quick fix
rbuckton Jan 5, 2023
31dfda9
Merge branch 'main' into decorators-stage-3
rbuckton Jan 5, 2023
b8885ae
Merge branch 'main' into decorators-stage-3
rbuckton Jan 9, 2023
ae3885a
Simplify decorators+modifiers merge
rbuckton Jan 10, 2023
fb0b9ee
Remove stub variables for potential type mutations
rbuckton Jan 10, 2023
6656953
Fix static accessor initialization order
rbuckton Jan 11, 2023
882e686
Merge branch 'main' into decorators-stage-3
rbuckton Jan 11, 2023
3cc86d9
Accept baselines
rbuckton Jan 11, 2023
57ef107
Fix class decorator+static auto-accessor transformation
rbuckton Jan 11, 2023
844c303
Add additional contextual typing test
rbuckton Jan 11, 2023
0d41f51
Amend decorator evaluation order
rbuckton Jan 11, 2023
e52ee01
Test evaluation order against multiple targets
rbuckton Jan 11, 2023
b476408
Add evaluation tests for decorator examples, fix parameter-property emit
rbuckton Jan 12, 2023
b9050d3
Merge branch 'main' into decorators-stage-3
rbuckton Jan 12, 2023
1e51d59
Fix lint after merge
rbuckton Jan 13, 2023
2c08e15
fix 'this' references in decorator expressions
rbuckton Jan 13, 2023
3def45f
Merge branch 'main' into decorators-stage-3
rbuckton Jan 13, 2023
298bce5
Accept baseline after merge
rbuckton Jan 13, 2023
b0020f6
Fix incorrectly renamed test
rbuckton Jan 13, 2023
02e93fd
Merge branch 'main' into decorators-stage-3
rbuckton Jan 18, 2023
673073c
Temporarily disable 'context.access'
rbuckton Jan 18, 2023
f0947fc
Merge branch 'main' into decorators-stage-3
rbuckton Jan 19, 2023
09855dc
Documentation comment updates
rbuckton Jan 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 @@ -1553,6 +1553,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 @@ -2771,13 +2787,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