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

Workaround issue with hasOwnProperty #1481

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Monoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const reverse = <A>(M: Monoid<A>): Monoid<A> => ({
export const struct = <A>(monoids: { [K in keyof A]: Monoid<A[K]> }): 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
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/ReadonlyRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const size = (r: ReadonlyRecord<string, unknown>): number => Object.keys(
*/
export const isEmpty = (r: ReadonlyRecord<string, unknown>): boolean => {
for (const k in r) {
if (_.hasOwnProperty.call(r, k)) {
if (_.has.call(r, k)) {
return false
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export function toUnfoldable<F>(U: Unfoldable<F>): <A>(r: ReadonlyRecord<string,
* @since 2.10.0
*/
export const upsertAt = <A>(k: string, a: A) => (r: ReadonlyRecord<string, A>): ReadonlyRecord<string, A> => {
if (_.hasOwnProperty.call(r, k) && r[k] === a) {
if (_.has.call(r, k) && r[k] === a) {
return r
}
const out: Record<string, A> = Object.assign({}, r)
Expand All @@ -159,7 +159,7 @@ export const upsertAt = <A>(k: string, a: A) => (r: ReadonlyRecord<string, A>):
*
* @since 2.10.0
*/
export const has = <K extends string>(k: string, r: ReadonlyRecord<K, unknown>): k is K => _.hasOwnProperty.call(r, k)
export const has = <K extends string>(k: string, r: ReadonlyRecord<K, unknown>): k is K => _.has.call(r, k)

/**
* Delete a key and value from a `ReadonlyRecord`.
Expand All @@ -172,7 +172,7 @@ export function deleteAt<K extends string>(
): <KS extends string, A>(r: ReadonlyRecord<KS, A>) => ReadonlyRecord<string extends K ? string : Exclude<KS, K>, A>
export function deleteAt(k: string): <A>(r: ReadonlyRecord<string, A>) => ReadonlyRecord<string, A> {
return <A>(r: ReadonlyRecord<string, A>) => {
if (!_.hasOwnProperty.call(r, k)) {
if (!_.has.call(r, k)) {
return r
}
const out: Record<string, A> = Object.assign({}, r)
Expand Down Expand Up @@ -258,7 +258,7 @@ export function isSubrecord<A>(
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
}
}
Expand All @@ -281,7 +281,7 @@ export function lookup<A>(
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
}

/**
Expand All @@ -304,7 +304,7 @@ export function mapWithIndex<A, B>(
return (r) => {
const out: Record<string, B> = {}
for (const k in r) {
if (_.hasOwnProperty.call(r, k)) {
if (_.has.call(r, k)) {
out[k] = f(k, r[k])
}
}
Expand Down Expand Up @@ -548,7 +548,7 @@ export function partitionMapWithIndex<A, B, C>(
const left: Record<string, B> = {}
const right: Record<string, C> = {}
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':
Expand Down Expand Up @@ -580,7 +580,7 @@ export function partitionWithIndex<A>(
const left: Record<string, A> = {}
const right: Record<string, A> = {}
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
Expand All @@ -606,7 +606,7 @@ export function filterMapWithIndex<A, B>(
return (r) => {
const out: Record<string, B> = {}
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
Expand All @@ -633,7 +633,7 @@ export function filterWithIndex<A>(
const out: Record<string, A> = {}
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
Expand Down Expand Up @@ -734,7 +734,7 @@ export function fromFoldableMap<F, B>(
return <A>(ta: HKT<F, A>, f: (a: A) => readonly [string, B]) => {
return F.reduce<A, Record<string, B>>(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
})
}
Expand Down Expand Up @@ -957,7 +957,7 @@ export const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: Readonly<Re
export const compact = <A>(r: Readonly<Record<string, Option<A>>>): Readonly<Record<string, A>> => {
const out: Record<string, A> = {}
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
Expand All @@ -977,7 +977,7 @@ export const separate = <A, B>(
const left: Record<string, A> = {}
const right: Record<string, B> = {}
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
Expand Down Expand Up @@ -1059,8 +1059,8 @@ export function getMonoid<A>(S: Semigroup<A>): Monoid<ReadonlyRecord<string, A>>
}
const r: Record<string, A> = 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
Expand Down Expand Up @@ -1247,7 +1247,7 @@ export const insertAt: <A>(
*/
export function hasOwnProperty<K extends string>(k: string, r: ReadonlyRecord<K, unknown>): k is K
export function hasOwnProperty<K extends string>(this: any, k: string, r?: ReadonlyRecord<K, unknown>): k is K {
return _.hasOwnProperty.call(r === undefined ? this : r, k)
return _.has.call(r === undefined ? this : r, k)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Semigroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const struct = <A>(
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])
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const struct = <A>(shows: { [K in keyof A]: Show<A[K]> }): 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])},`
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const isLeft = <E, A>(ma: Either<E, A>): ma is Left<E> => ma._tag === 'Le
// -------------------------------------------------------------------------------------

/** @internal */
export const hasOwnProperty = Object.prototype.hasOwnProperty
OliverJAsh marked this conversation as resolved.
Show resolved Hide resolved
export const has = Object.prototype.hasOwnProperty

// -------------------------------------------------------------------------------------
// NonEmptyArray
Expand Down