Skip to content

Commit 4a4b5d9

Browse files
committed
Merge 'decorators' into 'modifiers' on various Nodes
1 parent 0414dee commit 4a4b5d9

File tree

90 files changed

+4827
-2792
lines changed

Some content is hidden

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

90 files changed

+4827
-2792
lines changed

Diff for: src/compiler/binder.ts

+1-3
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.illegalModifiers)) {
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

Diff for: src/compiler/checker.ts

+150-114
Large diffs are not rendered by default.

Diff for: src/compiler/commandLineParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,8 @@ namespace ts {
20582058
continue;
20592059
}
20602060

2061-
if (element.questionToken) {
2062-
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.questionToken, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, "?"));
2061+
if (element.illegalQuestionToken) {
2062+
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.illegalQuestionToken, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, "?"));
20632063
}
20642064
if (!isDoubleQuotedString(element.name)) {
20652065
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, Diagnostics.String_literal_with_double_quotes_expected));

Diff for: src/compiler/core.ts

+20-16
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 {

Diff for: src/compiler/debug.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ namespace ts {
191191

192192
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>;
193193
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[];
194+
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;
195+
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;
194196
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) {
197+
export function assertEachNode(nodes: readonly Node[] | undefined, test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction) {
196198
if (shouldAssertFunction(AssertionLevel.Normal, "assertEachNode")) {
197199
assert(
198200
test === undefined || every(nodes, test),
@@ -708,9 +710,9 @@ namespace ts {
708710
};
709711
}
710712

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 = {}) {
713+
export function createDeprecation(name: string, options: DeprecationOptions & { error: true }): () => never;
714+
export function createDeprecation(name: string, options?: DeprecationOptions): () => void;
715+
export function createDeprecation(name: string, options: DeprecationOptions = {}) {
714716
const version = typeof options.typeScriptVersion === "string" ? new Version(options.typeScriptVersion) : options.typeScriptVersion ?? getTypeScriptVersion();
715717
const errorAfter = typeof options.errorAfter === "string" ? new Version(options.errorAfter) : options.errorAfter;
716718
const warnAfter = typeof options.warnAfter === "string" ? new Version(options.warnAfter) : options.warnAfter;

0 commit comments

Comments
 (0)