Repository: immerjs/immer (js)

Issue:
clear Map produces incorrect patches
## 🐛 Bug Report

clear Map produce incorrect patches

## Link to repro

codebox link: https://codesandbox.io/s/immer-sandbox-forked-zz8le

### immer source code
https://github.com/immerjs/immer/blob/bf90358c1bfedf0afb6e3bb016d6e6233b96e3ac/src/plugins/mapset.ts#L112
this line clears the `assigned_`, and Patch Plugin gen patches depends on `each(state.assigned_)`

https://github.com/immerjs/immer/blob/bf90358c1bfedf0afb6e3bb016d6e6233b96e3ac/src/plugins/patches.ts#L121-L143

is this by design? or a bug.

## To Reproduce

just run the  codesanbox link  above

## Observed behavior

`changes` is a empty array.

## Expected behavior

`changes` is `[{ type: 'Remove', path: ['t2', 't'] }]`

## Environment

We only accept bug reports against the latest Immer version.

- **Immer version:**
- [x] I filed this report against the _latest_ version of Immer
- [x] Occurs with `setUseProxies(true)`
- [ ] Occurs with `setUseProxies(false)` (ES5 only)


Pull request description:
set assigned keys when clear map
fix #663 

Patch:
diff --git a/src/plugins/mapset.ts b/src/plugins/mapset.ts
index 8bb2d09..6dd579a 100644
--- a/src/plugins/mapset.ts
+++ b/src/plugins/mapset.ts
@@ -15,7 +15,8 @@ import {
 	markChanged,
 	ProxyTypeMap,
 	ProxyTypeSet,
-	die
+	die,
+	each
 } from "../internal"
 
 export function enableMapSet() {
@@ -110,6 +111,9 @@ export function enableMapSet() {
 			prepareMapCopy(state)
 			markChanged(state)
 			state.assigned_ = new Map()
+			each(state.base_, key => {
+				state.assigned_!.set(key, false)
+			})
 			return state.copy_!.clear()
 		}
 


Test patch:
diff --git a/__tests__/map-set.js b/__tests__/map-set.js
index faa4680..bbe9d47 100644
--- a/__tests__/map-set.js
+++ b/__tests__/map-set.js
@@ -244,5 +244,27 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
 			expect(map1.has("key")).toBe(true)
 			expect(map1.get("key")).toBe(undefined)
 		})
+
+		test("#663 - clear map", () => {
+			const map = new Map([
+				["a", "b"],
+				["b", "c"]
+			])
+			const result = produceWithPatches(map, draft => {
+				draft.clear()
+			})
+
+			expect(result).toEqual([
+				new Map(),
+				[
+					{op: "remove", path: ["a"]},
+					{op: "remove", path: ["b"]}
+				],
+				[
+					{op: "add", path: ["a"], value: "b"},
+					{op: "add", path: ["b"], value: "c"}
+				]
+			])
+		})
 	})
 }