Skip to content

Commit 1e65b33

Browse files
authored
Merge 'decorators' into 'modifiers' on various nodes (#49089)
* Merge 'decorators' into 'modifiers' on various Nodes * Drop RESERVED argument in favor of removing parameter * Ignore grammar error nodes when asserting invariants * Revert 'illegalX' property renames * PR Feedback
1 parent 00c7c47 commit 1e65b33

File tree

94 files changed

+5756
-2971
lines changed

Some content is hidden

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

94 files changed

+5756
-2971
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,8 +1661,6 @@ namespace ts {
16611661
// - `BindingElement: BindingPattern Initializer?`
16621662
// - https://tc39.es/ecma262/#sec-runtime-semantics-keyedbindinginitialization
16631663
// - `BindingElement: BindingPattern Initializer?`
1664-
bindEach(node.decorators);
1665-
bindEach(node.modifiers);
16661664
bind(node.dotDotDotToken);
16671665
bind(node.propertyName);
16681666
bind(node.initializer);
@@ -2794,7 +2792,7 @@ namespace ts {
27942792
}
27952793

27962794
function bindNamespaceExportDeclaration(node: NamespaceExportDeclaration) {
2797-
if (node.modifiers && node.modifiers.length) {
2795+
if (some(node.modifiers)) {
27982796
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Modifiers_cannot_appear_here));
27992797
}
28002798
const diag = !isSourceFile(node.parent) ? Diagnostics.Global_module_exports_may_only_appear_at_top_level

src/compiler/checker.ts

Lines changed: 95 additions & 107 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ namespace ts {
163163
}
164164

165165
/** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
166-
export function find<T, U extends T>(array: readonly T[], predicate: (element: T, index: number) => element is U): U | undefined;
167-
export function find<T>(array: readonly T[], predicate: (element: T, index: number) => boolean): T | undefined;
168-
export function find<T>(array: readonly T[], predicate: (element: T, index: number) => boolean): T | undefined {
169-
for (let i = 0; i < array.length; i++) {
166+
export function find<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => element is U, startIndex?: number): U | undefined;
167+
export function find<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): T | undefined;
168+
export function find<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): T | undefined {
169+
if (array === undefined) return undefined;
170+
for (let i = startIndex ?? 0; i < array.length; i++) {
170171
const value = array[i];
171172
if (predicate(value, i)) {
172173
return value;
@@ -175,10 +176,11 @@ namespace ts {
175176
return undefined;
176177
}
177178

178-
export function findLast<T, U extends T>(array: readonly T[], predicate: (element: T, index: number) => element is U): U | undefined;
179-
export function findLast<T>(array: readonly T[], predicate: (element: T, index: number) => boolean): T | undefined;
180-
export function findLast<T>(array: readonly T[], predicate: (element: T, index: number) => boolean): T | undefined {
181-
for (let i = array.length - 1; i >= 0; i--) {
179+
export function findLast<T, U extends T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => element is U, startIndex?: number): U | undefined;
180+
export function findLast<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): T | undefined;
181+
export function findLast<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): T | undefined {
182+
if (array === undefined) return undefined;
183+
for (let i = startIndex ?? array.length - 1; i >= 0; i--) {
182184
const value = array[i];
183185
if (predicate(value, i)) {
184186
return value;
@@ -188,17 +190,19 @@ namespace ts {
188190
}
189191

190192
/** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
191-
export function findIndex<T>(array: readonly T[], predicate: (element: T, index: number) => boolean, startIndex?: number): number {
192-
for (let i = startIndex || 0; i < array.length; i++) {
193+
export function findIndex<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): number {
194+
if (array === undefined) return -1;
195+
for (let i = startIndex ?? 0; i < array.length; i++) {
193196
if (predicate(array[i], i)) {
194197
return i;
195198
}
196199
}
197200
return -1;
198201
}
199202

200-
export function findLastIndex<T>(array: readonly T[], predicate: (element: T, index: number) => boolean, startIndex?: number): number {
201-
for (let i = startIndex === undefined ? array.length - 1 : startIndex; i >= 0; i--) {
203+
export function findLastIndex<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): number {
204+
if (array === undefined) return -1;
205+
for (let i = startIndex ?? array.length - 1; i >= 0; i--) {
202206
if (predicate(array[i], i)) {
203207
return i;
204208
}
@@ -1079,8 +1083,8 @@ namespace ts {
10791083
/**
10801084
* Returns the first element of an array if non-empty, `undefined` otherwise.
10811085
*/
1082-
export function firstOrUndefined<T>(array: readonly T[]): T | undefined {
1083-
return array.length === 0 ? undefined : array[0];
1086+
export function firstOrUndefined<T>(array: readonly T[] | undefined): T | undefined {
1087+
return array === undefined || array.length === 0 ? undefined : array[0];
10841088
}
10851089

10861090
export function first<T>(array: readonly T[]): T {
@@ -1091,8 +1095,8 @@ namespace ts {
10911095
/**
10921096
* Returns the last element of an array if non-empty, `undefined` otherwise.
10931097
*/
1094-
export function lastOrUndefined<T>(array: readonly T[]): T | undefined {
1095-
return array.length === 0 ? undefined : array[array.length - 1];
1098+
export function lastOrUndefined<T>(array: readonly T[] | undefined): T | undefined {
1099+
return array === undefined || array.length === 0 ? undefined : array[array.length - 1];
10961100
}
10971101

10981102
export function last<T>(array: readonly T[]): T {

src/compiler/debug.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace ts {
1919
warnAfter?: Version | string;
2020
errorAfter?: Version | string;
2121
typeScriptVersion?: Version | string;
22+
name?: string;
2223
}
2324

2425
export namespace Debug {
@@ -191,8 +192,10 @@ namespace ts {
191192

192193
export function assertEachNode<T extends Node, U extends T>(nodes: NodeArray<T>, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is NodeArray<U>;
193194
export function assertEachNode<T extends Node, U extends T>(nodes: readonly T[], test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is readonly U[];
195+
export function assertEachNode<T extends Node, U extends T>(nodes: NodeArray<T> | undefined, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is NodeArray<U> | undefined;
196+
export function assertEachNode<T extends Node, U extends T>(nodes: readonly T[] | undefined, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is readonly U[] | undefined;
194197
export function assertEachNode(nodes: readonly Node[], test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction): void;
195-
export function assertEachNode(nodes: readonly Node[], test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction) {
198+
export function assertEachNode(nodes: readonly Node[] | undefined, test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction) {
196199
if (shouldAssertFunction(AssertionLevel.Normal, "assertEachNode")) {
197200
assert(
198201
test === undefined || every(nodes, test),
@@ -708,9 +711,9 @@ namespace ts {
708711
};
709712
}
710713

711-
function createDeprecation(name: string, options: DeprecationOptions & { error: true }): () => never;
712-
function createDeprecation(name: string, options?: DeprecationOptions): () => void;
713-
function createDeprecation(name: string, options: DeprecationOptions = {}) {
714+
export function createDeprecation(name: string, options: DeprecationOptions & { error: true }): () => never;
715+
export function createDeprecation(name: string, options?: DeprecationOptions): () => void;
716+
export function createDeprecation(name: string, options: DeprecationOptions = {}) {
714717
const version = typeof options.typeScriptVersion === "string" ? new Version(options.typeScriptVersion) : options.typeScriptVersion ?? getTypeScriptVersion();
715718
const errorAfter = typeof options.errorAfter === "string" ? new Version(options.errorAfter) : options.errorAfter;
716719
const warnAfter = typeof options.warnAfter === "string" ? new Version(options.warnAfter) : options.warnAfter;
@@ -730,7 +733,7 @@ namespace ts {
730733
}
731734

732735
export function deprecate<F extends (...args: any[]) => any>(func: F, options?: DeprecationOptions): F {
733-
const deprecation = createDeprecation(getFunctionName(func), options);
736+
const deprecation = createDeprecation(options?.name ?? getFunctionName(func), options);
734737
return wrapFunction(deprecation, func);
735738
}
736739
}

0 commit comments

Comments
 (0)