From 8718afef60daebf27bd372014561fff2607c9c96 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 15 Apr 2021 09:34:30 +0100 Subject: [PATCH 1/3] Workaround issue with `hasOwnProperty` Re. https://github.com/gcanti/fp-ts/issues/1249#issuecomment-820232156 --- src/internal.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/internal.ts b/src/internal.ts index c923ad7a0..cf2eb7bd1 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -24,8 +24,17 @@ export const isLeft = (ma: Either): ma is Left => ma._tag === 'Le // Record // ------------------------------------------------------------------------------------- -/** @internal */ -export const hasOwnProperty = Object.prototype.hasOwnProperty +const _hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * This wrapper is needed to workaround https://github.com/gcanti/fp-ts/issues/1249. + * + * @internal + */ +export function hasOwnProperty(this: any, k: string, r?: object) { + /* istanbul ignore next */ + return _hasOwnProperty.call(r === undefined ? this : r, k) +} // ------------------------------------------------------------------------------------- // NonEmptyArray From f23b699a5b9864ad64d47961bf98144a0b0e1500 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 15 Apr 2021 10:03:50 +0100 Subject: [PATCH 2/3] Revert "Workaround issue with `hasOwnProperty`" This reverts commit 8718afef60daebf27bd372014561fff2607c9c96. --- src/internal.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/internal.ts b/src/internal.ts index cf2eb7bd1..c923ad7a0 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -24,17 +24,8 @@ export const isLeft = (ma: Either): ma is Left => ma._tag === 'Le // Record // ------------------------------------------------------------------------------------- -const _hasOwnProperty = Object.prototype.hasOwnProperty - -/** - * This wrapper is needed to workaround https://github.com/gcanti/fp-ts/issues/1249. - * - * @internal - */ -export function hasOwnProperty(this: any, k: string, r?: object) { - /* istanbul ignore next */ - return _hasOwnProperty.call(r === undefined ? this : r, k) -} +/** @internal */ +export const hasOwnProperty = Object.prototype.hasOwnProperty // ------------------------------------------------------------------------------------- // NonEmptyArray From bf85845aee25ed69aa7b762a006bba02fcede5e7 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 15 Apr 2021 10:04:04 +0100 Subject: [PATCH 3/3] Rename to workaround issue with `hasOwnProperty` Re. https://github.com/gcanti/fp-ts/issues/1249#issuecomment-820232156 --- src/Monoid.ts | 2 +- src/ReadonlyRecord.ts | 34 +++++++++++++++++----------------- src/Semigroup.ts | 2 +- src/Show.ts | 2 +- src/internal.ts | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Monoid.ts b/src/Monoid.ts index 3a5933290..ca8a7217a 100644 --- a/src/Monoid.ts +++ b/src/Monoid.ts @@ -141,7 +141,7 @@ export const reverse = (M: Monoid): Monoid => ({ export const struct = (monoids: { [K in keyof A]: Monoid }): Monoid<{ readonly [K in keyof A]: A[K] }> => { const empty: A = {} as any for (const k in monoids) { - if (_.hasOwnProperty.call(monoids, k)) { + if (_.has.call(monoids, k)) { empty[k] = monoids[k].empty } } diff --git a/src/ReadonlyRecord.ts b/src/ReadonlyRecord.ts index 2734e6243..ffb3ef97d 100644 --- a/src/ReadonlyRecord.ts +++ b/src/ReadonlyRecord.ts @@ -71,7 +71,7 @@ export const size = (r: ReadonlyRecord): number => Object.keys( */ export const isEmpty = (r: ReadonlyRecord): boolean => { for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { return false } } @@ -144,7 +144,7 @@ export function toUnfoldable(U: Unfoldable): (r: ReadonlyRecord(k: string, a: A) => (r: ReadonlyRecord): ReadonlyRecord => { - if (_.hasOwnProperty.call(r, k) && r[k] === a) { + if (_.has.call(r, k) && r[k] === a) { return r } const out: Record = Object.assign({}, r) @@ -159,7 +159,7 @@ export const upsertAt = (k: string, a: A) => (r: ReadonlyRecord): * * @since 2.10.0 */ -export const has = (k: string, r: ReadonlyRecord): k is K => _.hasOwnProperty.call(r, k) +export const has = (k: string, r: ReadonlyRecord): k is K => _.has.call(r, k) /** * Delete a key and value from a `ReadonlyRecord`. @@ -172,7 +172,7 @@ export function deleteAt( ): (r: ReadonlyRecord) => ReadonlyRecord, A> export function deleteAt(k: string): (r: ReadonlyRecord) => ReadonlyRecord { return (r: ReadonlyRecord) => { - if (!_.hasOwnProperty.call(r, k)) { + if (!_.has.call(r, k)) { return r } const out: Record = Object.assign({}, r) @@ -258,7 +258,7 @@ export function isSubrecord( return (that) => isSubrecordE(that, me) } for (const k in me) { - if (!_.hasOwnProperty.call(that, k) || !E.equals(me[k], that[k])) { + if (!_.has.call(that, k) || !E.equals(me[k], that[k])) { return false } } @@ -281,7 +281,7 @@ export function lookup( if (r === undefined) { return (r) => lookup(k, r) } - return _.hasOwnProperty.call(r, k) ? O.some(r[k]) : O.none + return _.has.call(r, k) ? O.some(r[k]) : O.none } /** @@ -304,7 +304,7 @@ export function mapWithIndex( return (r) => { const out: Record = {} for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { out[k] = f(k, r[k]) } } @@ -548,7 +548,7 @@ export function partitionMapWithIndex( const left: Record = {} const right: Record = {} for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { const e = f(k, r[k]) switch (e._tag) { case 'Left': @@ -580,7 +580,7 @@ export function partitionWithIndex( const left: Record = {} const right: Record = {} for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { const a = r[k] if (predicateWithIndex(k, a)) { right[k] = a @@ -606,7 +606,7 @@ export function filterMapWithIndex( return (r) => { const out: Record = {} for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { const ob = f(k, r[k]) if (_.isSome(ob)) { out[k] = ob.value @@ -633,7 +633,7 @@ export function filterWithIndex( const out: Record = {} let changed = false for (const key in fa) { - if (_.hasOwnProperty.call(fa, key)) { + if (_.has.call(fa, key)) { const a = fa[key] if (predicateWithIndex(key, a)) { out[key] = a @@ -734,7 +734,7 @@ export function fromFoldableMap( return (ta: HKT, f: (a: A) => readonly [string, B]) => { return F.reduce>(ta, {}, (r, a) => { const [k, b] = f(a) - r[k] = _.hasOwnProperty.call(r, k) ? M.concat(r[k], b) : b + r[k] = _.has.call(r, k) ? M.concat(r[k], b) : b return r }) } @@ -957,7 +957,7 @@ export const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: Readonly(r: Readonly>>): Readonly> => { const out: Record = {} for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { const oa = r[k] if (_.isSome(oa)) { out[k] = oa.value @@ -977,7 +977,7 @@ export const separate = ( const left: Record = {} const right: Record = {} for (const k in r) { - if (_.hasOwnProperty.call(r, k)) { + if (_.has.call(r, k)) { const e = r[k] if (_.isLeft(e)) { left[k] = e.left @@ -1059,8 +1059,8 @@ export function getMonoid(S: Semigroup): Monoid> } const r: Record = Object.assign({}, first) for (const k in second) { - if (_.hasOwnProperty.call(second, k)) { - r[k] = _.hasOwnProperty.call(first, k) ? S.concat(first[k], second[k]) : second[k] + if (_.has.call(second, k)) { + r[k] = _.has.call(first, k) ? S.concat(first[k], second[k]) : second[k] } } return r @@ -1247,7 +1247,7 @@ export const insertAt: ( */ export function hasOwnProperty(k: string, r: ReadonlyRecord): k is K export function hasOwnProperty(this: any, k: string, r?: ReadonlyRecord): k is K { - return _.hasOwnProperty.call(r === undefined ? this : r, k) + return _.has.call(r === undefined ? this : r, k) } /** diff --git a/src/Semigroup.ts b/src/Semigroup.ts index 4bb79d9a7..75bc0f6de 100644 --- a/src/Semigroup.ts +++ b/src/Semigroup.ts @@ -151,7 +151,7 @@ export const struct = ( concat: (first, second) => { const r: A = {} as any for (const k in semigroups) { - if (_.hasOwnProperty.call(semigroups, k)) { + if (_.has.call(semigroups, k)) { r[k] = semigroups[k].concat(first[k], second[k]) } } diff --git a/src/Show.ts b/src/Show.ts index dd42bc141..baed4b062 100644 --- a/src/Show.ts +++ b/src/Show.ts @@ -35,7 +35,7 @@ export const struct = (shows: { [K in keyof A]: Show }): Show<{ readonl show: (a) => { let s = '{' for (const k in shows) { - if (_.hasOwnProperty.call(shows, k)) { + if (_.has.call(shows, k)) { s += ` ${k}: ${shows[k].show(a[k])},` } } diff --git a/src/internal.ts b/src/internal.ts index c923ad7a0..61c4fbbd9 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -25,7 +25,7 @@ export const isLeft = (ma: Either): ma is Left => ma._tag === 'Le // ------------------------------------------------------------------------------------- /** @internal */ -export const hasOwnProperty = Object.prototype.hasOwnProperty +export const has = Object.prototype.hasOwnProperty // ------------------------------------------------------------------------------------- // NonEmptyArray