diff --git a/__tests__/frozen.js b/__tests__/frozen.js index f130f3c2..3a6d8bcb 100644 --- a/__tests__/frozen.js +++ b/__tests__/frozen.js @@ -147,10 +147,12 @@ function runTests(name) { const res = produce(base, draft => { draft.set("a", 1) + draft.set("o", {b: 1}) }) expect(() => res.set("b", 2)).toThrowErrorMatchingSnapshot() expect(() => res.clear()).toThrowErrorMatchingSnapshot() expect(() => res.delete("b")).toThrowErrorMatchingSnapshot() + expect(Object.isFrozen(res.get("o"))).toBe(true) // In draft, still editable expect(produce(res, d => void d.set("a", 2))).not.toBe(res) diff --git a/src/core/finalize.ts b/src/core/finalize.ts index 6ee69ce6..bf1ac742 100644 --- a/src/core/finalize.ts +++ b/src/core/finalize.ts @@ -15,7 +15,8 @@ import { getPlugin, die, revokeScope, - isFrozen + isFrozen, + isMap } from "../internal" export function processResult(result: any, scope: ImmerScope) { @@ -151,7 +152,9 @@ function finalizeProperty( if ( (!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && - Object.prototype.propertyIsEnumerable.call(targetObject, prop) + (isMap(targetObject) + ? targetObject.has(prop) + : Object.prototype.propertyIsEnumerable.call(targetObject, prop)) ) maybeFreeze(rootScope, childValue) }