@@ -2,6 +2,9 @@ import type { IDataObject } from './Interfaces';
2
2
3
3
const defaultPropertyDescriptor = Object . freeze ( { enumerable : true , configurable : true } ) ;
4
4
5
+ // eslint-disable-next-line @typescript-eslint/unbound-method
6
+ const { hasOwnProperty } = Object . prototype ;
7
+
5
8
const augmentedObjects = new WeakSet < object > ( ) ;
6
9
7
10
function augment < T > ( value : T ) : T {
@@ -84,7 +87,7 @@ export function augmentObject<T extends object>(data: T): T {
84
87
return undefined ;
85
88
}
86
89
87
- if ( newData [ key ] !== undefined ) {
90
+ if ( hasOwnProperty . call ( newData , key ) ) {
88
91
return newData [ key ] ;
89
92
}
90
93
@@ -102,11 +105,11 @@ export function augmentObject<T extends object>(data: T): T {
102
105
103
106
return value ;
104
107
} ,
105
- deleteProperty ( target , key : string ) {
106
- if ( key in newData ) {
108
+ deleteProperty ( _target , key : string ) {
109
+ if ( hasOwnProperty . call ( newData , key ) ) {
107
110
delete newData [ key ] ;
108
111
}
109
- if ( key in target ) {
112
+ if ( hasOwnProperty . call ( data , key ) ) {
110
113
deletedProperties . add ( key ) ;
111
114
}
112
115
@@ -131,9 +134,10 @@ export function augmentObject<T extends object>(data: T): T {
131
134
132
135
return true ;
133
136
} ,
134
- has ( target , key ) {
137
+ has ( _target , key ) {
135
138
if ( deletedProperties . has ( key ) ) return false ;
136
- return Reflect . has ( newData , key ) || Reflect . has ( target , key ) ;
139
+ const target = hasOwnProperty . call ( newData , key ) ? newData : data ;
140
+ return Reflect . has ( target , key ) ;
137
141
} ,
138
142
ownKeys ( target ) {
139
143
const originalKeys = Reflect . ownKeys ( target ) ;
@@ -145,7 +149,8 @@ export function augmentObject<T extends object>(data: T): T {
145
149
146
150
getOwnPropertyDescriptor ( _target , key ) {
147
151
if ( deletedProperties . has ( key ) ) return undefined ;
148
- return Object . getOwnPropertyDescriptor ( key in newData ? newData : data , key ) ;
152
+ const target = hasOwnProperty . call ( newData , key ) ? newData : data ;
153
+ return Object . getOwnPropertyDescriptor ( target , key ) ;
149
154
} ,
150
155
} ) ;
151
156
0 commit comments