@@ -12,7 +12,9 @@ import {
1212 StrictMode
1313} from "../internal"
1414
15- export const getPrototypeOf = Object . getPrototypeOf
15+ const O = Object
16+
17+ export const getPrototypeOf = O . getPrototypeOf
1618
1719/** Returns true if the given value is an Immer draft */
1820/*#__PURE__*/
@@ -34,15 +36,15 @@ export function isDraftable(value: any): boolean {
3436 )
3537}
3638
37- const objectCtorString = Object . prototype . constructor . toString ( )
39+ const objectCtorString = O . prototype . constructor . toString ( )
3840const cachedCtorStrings = new WeakMap ( )
3941/*#__PURE__*/
4042export function isPlainObject ( value : any ) : boolean {
41- const proto = Object . getPrototypeOf ( value )
42- if ( proto === null || proto === Object . prototype ) return true
43+ if ( ! value || ! isObjectish ( value ) ) return false
44+ const proto = O . getPrototypeOf ( value )
45+ if ( proto === null || proto === O . prototype ) return true
4346
44- const Ctor =
45- Object . hasOwnProperty . call ( proto , "constructor" ) && proto . constructor
47+ const Ctor = O . hasOwnProperty . call ( proto , "constructor" ) && proto . constructor
4648 if ( Ctor === Object ) return true
4749
4850 if ( ! isFunction ( Ctor ) ) return false
@@ -82,7 +84,7 @@ export function each(obj: any, iter: any, strict: boolean = true) {
8284 if ( getArchtype ( obj ) === ArchType . Object ) {
8385 // If strict, we do a full iteration including symbols and non-enumerable properties
8486 // Otherwise, we only iterate enumerable string properties for performance
85- const keys = strict ? Reflect . ownKeys ( obj ) : Object . keys ( obj )
87+ const keys = strict ? Reflect . ownKeys ( obj ) : O . keys ( obj )
8688 keys . forEach ( key => {
8789 iter ( key , obj [ key ] , obj )
8890 } )
@@ -113,7 +115,7 @@ export function has(
113115) : boolean {
114116 return type === ArchType . Map
115117 ? thing . has ( prop )
116- : Object . prototype . hasOwnProperty . call ( thing , prop )
118+ : O . prototype . hasOwnProperty . call ( thing , prop )
117119}
118120
119121/*#__PURE__*/
@@ -204,7 +206,7 @@ export function shallowCopy(base: any, strict: StrictMode) {
204206
205207 if ( strict === true || ( strict === "class_only" && ! isPlain ) ) {
206208 // Perform a strict copy
207- const descriptors = Object . getOwnPropertyDescriptors ( base )
209+ const descriptors = O . getOwnPropertyDescriptors ( base )
208210 delete descriptors [ DRAFT_STATE as any ]
209211 let keys = Reflect . ownKeys ( descriptors )
210212 for ( let i = 0 ; i < keys . length ; i ++ ) {
@@ -225,15 +227,15 @@ export function shallowCopy(base: any, strict: StrictMode) {
225227 value : base [ key ]
226228 }
227229 }
228- return Object . create ( getPrototypeOf ( base ) , descriptors )
230+ return O . create ( getPrototypeOf ( base ) , descriptors )
229231 } else {
230232 // perform a sloppy copy
231233 const proto = getPrototypeOf ( base )
232234 if ( proto !== null && isPlain ) {
233235 return { ...base } // assumption: better inner class optimization than the assign below
234236 }
235- const obj = Object . create ( proto )
236- return Object . assign ( obj , base )
237+ const obj = O . create ( proto )
238+ return O . assign ( obj , base )
237239 }
238240}
239241
@@ -248,14 +250,14 @@ export function freeze<T>(obj: T, deep?: boolean): T
248250export function freeze < T > ( obj : any , deep : boolean = false ) : T {
249251 if ( isFrozen ( obj ) || isDraft ( obj ) ) return obj
250252 if ( getArchtype ( obj ) > 1 /* Map or Set */ ) {
251- Object . defineProperties ( obj , {
253+ O . defineProperties ( obj , {
252254 set : dontMutateMethodOverride ,
253255 add : dontMutateMethodOverride ,
254256 clear : dontMutateMethodOverride ,
255257 delete : dontMutateMethodOverride
256258 } )
257259 }
258- Object . freeze ( obj )
260+ O . freeze ( obj )
259261 if ( deep )
260262 // See #590, don't recurse into non-enumerable / Symbol properties when freezing
261263 // So use Object.values (only string-like, enumerables) instead of each()
@@ -279,6 +281,6 @@ const dontMutateMethodOverride = {
279281
280282export function isFrozen ( obj : any ) : boolean {
281283 // Fast path: primitives and null/undefined are always "frozen"
282- return Object . isFrozen ( obj )
283284 if ( obj === null || ! isObjectish ( obj ) ) return true
285+ return O . isFrozen ( obj )
284286}
0 commit comments