From 4ae9e2075dc02dbaf5341bc03d364b824351ccdb Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Wed, 16 May 2018 12:57:52 -0700 Subject: [PATCH 1/8] further restrict property descriptor type definitions --- lib/core.js | 59 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/core.js b/lib/core.js index f8dd4adf2ae..7a9064d720c 100644 --- a/lib/core.js +++ b/lib/core.js @@ -21,17 +21,52 @@ declare function decodeURIComponent(encodedURIComponent: string): string; declare function encodeURI(uri: string): string; declare function encodeURIComponent(uriComponent: string): string; -type PropertyDescriptor = { +type ContraPropertyDescriptor = { enumerable?: boolean; configurable?: boolean; writable?: boolean; - value?: T; - get?: () => T; - set?: (value: T) => void; + value: T; +} | { + enumerable?: boolean; + configurable?: boolean; + get: () => T; + set: (value: T) => void; +} | { + enumerable?: boolean; + configurable?: boolean; + get: () => T; +} | { + enumerable?: boolean; + configurable?: boolean; + set: (value: T) => void; +}; + +type CoPropertyDescriptor = { + enumerable: boolean; + configurable: boolean; + writable: boolean; + value: T; +} | { + enumerable: boolean; + configurable: boolean; + get: () => T; + set: (value: T) => void; +} | { + enumerable: boolean; + configurable: boolean; + get: () => T; +} | { + enumerable: boolean; + configurable: boolean; + set: (value: T) => void; }; -type PropertyDescriptorMap = { - [s: string]: PropertyDescriptor; +type ContraPropertyDescriptorMap = { + [s: string]: ContraPropertyDescriptor; +} + +type CoPropertyDescriptorMap = { + [s: string]: CoPropertyDescriptor; } // TODO: instance @@ -42,12 +77,12 @@ declare class Object { static (o: string): String; static (o: T): T; static assign: Object$Assign; - static create(o: any, properties?: PropertyDescriptorMap): any; // compiler magic - static defineProperties(o: any, properties: PropertyDescriptorMap): any; - static defineProperty(o: any, p: any, attributes: PropertyDescriptor): any; + static create(o: any, properties?: ContraPropertyDescriptorMap): any; // compiler magic + static defineProperties(o: any, properties: ContraPropertyDescriptorMap): any; + static defineProperty(o: any, p: any, attributes: ContraPropertyDescriptor): any; static entries(object: any): Array<[string, mixed]>; static freeze(o: T): T; - static getOwnPropertyDescriptor(o: any, p: any): PropertyDescriptor | void; + static getOwnPropertyDescriptor(o: any, p: any): CoPropertyDescriptor | void; static getOwnPropertyNames(o: any): Array; static getOwnPropertySymbols(o: any): Symbol[]; static getPrototypeOf: Object$GetPrototypeOf; @@ -760,8 +795,8 @@ type Proxy$traps = { setPrototypeOf?: (target: T, prototype: Object|null) => boolean; isExtensible?: (target: T) => boolean; preventExtensions?: (target: T) => boolean; - getOwnPropertyDescriptor?: (target: T, property: string) => void | PropertyDescriptor; - defineProperty?: (target: T, property: string, descriptor: PropertyDescriptor) => boolean; + getOwnPropertyDescriptor?: (target: T, property: string) => void | CoPropertyDescriptor; + defineProperty?: (target: T, property: string, descriptor: ContraPropertyDescriptor) => boolean; has?: (target: T, key: string) => boolean; get?: (target: T, property: string, receiver: Proxy) => any; set?: (target: T, property: string, value: any, receiver: Proxy) => boolean; From 01c8dd033e3f0c99f55d77b62ed6d3b3c826a5f1 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 19 Apr 2019 15:45:46 -0700 Subject: [PATCH 2/8] Update core.js --- lib/core.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core.js b/lib/core.js index fe16148f094..3e9c9f4ff1e 100644 --- a/lib/core.js +++ b/lib/core.js @@ -80,14 +80,14 @@ declare class Object { static create(o: any, properties?: ContraPropertyDescriptorMap): any; // compiler magic static defineProperties(o: any, properties: ContraPropertyDescriptorMap): any; static defineProperty(o: any, p: any, attributes: ContraPropertyDescriptor): any; - static entries(object: any): Array<[string, mixed]>; + static entries(object: mixed): Array<[string, mixed]>; static freeze(o: T): T; static fromEntries(entries: Iterable<[K, V] | {'0': K, '1': V}>): {[K]: V}; - static getOwnPropertyDescriptor(o: any, p: any): CoPropertyDescriptor | void; + static getOwnPropertyDescriptor(o: mixed, p: any): CoPropertyDescriptor | void; static getOwnPropertyDescriptors(o: {}): CoPropertyDescriptorMap; - static getOwnPropertyNames(o: any): Array; - static getOwnPropertySymbols(o: any): Symbol[]; + static getOwnPropertyNames(o: mixed): Array; + static getOwnPropertySymbols(o: mixed): Symbol[]; static getPrototypeOf: Object$GetPrototypeOf; static is(a: T, b: T): boolean; static isExtensible(o: mixed): boolean; From 3ca8a08137f8f1a73138130c1bbab84afdf65265 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Thu, 27 Jun 2019 13:38:38 -0700 Subject: [PATCH 3/8] whitespace --- lib/core.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core.js b/lib/core.js index 2a451251028..ce3469631bc 100644 --- a/lib/core.js +++ b/lib/core.js @@ -98,6 +98,7 @@ declare class Object { '1': V, ... }>): { [K]: V, ... }; + static getOwnPropertyDescriptor(o: mixed, p: any): CoPropertyDescriptor | void; static getOwnPropertyDescriptors(o: {}): CoPropertyDescriptorMap; static getOwnPropertyNames(o: $NotNullOrVoid): Array; From 95a15ae25f75422256e59dc8f08f93f462cd2317 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Thu, 27 Jun 2019 13:40:00 -0700 Subject: [PATCH 4/8] fix bad merge conflict resolution --- lib/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core.js b/lib/core.js index ce3469631bc..11d5071969c 100644 --- a/lib/core.js +++ b/lib/core.js @@ -99,8 +99,8 @@ declare class Object { ... }>): { [K]: V, ... }; - static getOwnPropertyDescriptor(o: mixed, p: any): CoPropertyDescriptor | void; - static getOwnPropertyDescriptors(o: {}): CoPropertyDescriptorMap; + static getOwnPropertyDescriptor(o: $NotNullOrVoid, p: any): CoPropertyDescriptor | void; + static getOwnPropertyDescriptors(o: {...}): CoPropertyDescriptorMap; static getOwnPropertyNames(o: $NotNullOrVoid): Array; static getOwnPropertySymbols(o: $NotNullOrVoid): Symbol[]; static getPrototypeOf: Object$GetPrototypeOf; From 3354f3fe970ef53d8cdaeec2cc9ef2601f124ac2 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 15 Nov 2019 12:55:14 -0800 Subject: [PATCH 5/8] allow value to be missing in contravariant position --- lib/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core.js b/lib/core.js index 34b5b3bc21e..ccc50683b79 100644 --- a/lib/core.js +++ b/lib/core.js @@ -25,7 +25,7 @@ type ContraPropertyDescriptor = { enumerable?: boolean, configurable?: boolean, writable?: boolean, - value: T, + value?: T, ... } | { enumerable?: boolean, From b08c581c000a80e5a81907a72b3d550e9578aae2 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 15 Nov 2019 14:04:42 -0800 Subject: [PATCH 6/8] Update core.js --- lib/core.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core.js b/lib/core.js index ccc50683b79..bd2c45d3bd2 100644 --- a/lib/core.js +++ b/lib/core.js @@ -25,7 +25,11 @@ type ContraPropertyDescriptor = { enumerable?: boolean, configurable?: boolean, writable?: boolean, - value?: T, +} | { + enumerable?: boolean, + configurable?: boolean, + writable?: boolean, + value: T, ... } | { enumerable?: boolean, From c3e3ac13aea21e768c497e79bd16e5e910302339 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Mon, 18 Nov 2019 13:51:11 -0800 Subject: [PATCH 7/8] loosen up ContraPropertyDescriptor --- lib/core.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lib/core.js b/lib/core.js index bd2c45d3bd2..2577d301af6 100644 --- a/lib/core.js +++ b/lib/core.js @@ -25,26 +25,8 @@ type ContraPropertyDescriptor = { enumerable?: boolean, configurable?: boolean, writable?: boolean, -} | { - enumerable?: boolean, - configurable?: boolean, - writable?: boolean, value: T, - ... -} | { - enumerable?: boolean, - configurable?: boolean, - get: () => T, - set: (value: T) => void, - ... -} | { - enumerable?: boolean, - configurable?: boolean, get: () => T, - ... -} | { - enumerable?: boolean, - configurable?: boolean, set: (value: T) => void, ... }; From 794a313313949d66f84475e6a4d4610723f6f58b Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Mon, 18 Nov 2019 13:51:37 -0800 Subject: [PATCH 8/8] oops --- lib/core.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core.js b/lib/core.js index 2577d301af6..5d77d6c031f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -25,9 +25,9 @@ type ContraPropertyDescriptor = { enumerable?: boolean, configurable?: boolean, writable?: boolean, - value: T, - get: () => T, - set: (value: T) => void, + value?: T, + get?: () => T, + set?: (value: T) => void, ... };