writes `onCount` for a plain object whose key count is that of the declared keys it holds
(js: NodeCompiler, onCount: () => NodeCompiler)
| 1114 | |
| 1115 | /** writes `onCount` for a plain object whose key count is that of the declared keys it holds */ |
| 1116 | private jsKeyCount(js: NodeCompiler, onCount: () => NodeCompiler): void { |
| 1117 | const held = [ |
| 1118 | `${this.required?.length ?? 0}`, |
| 1119 | ...(this.optional ?? []).map( |
| 1120 | prop => `+(${js.serialize(prop.key)} in data)` |
| 1121 | ) |
| 1122 | ] |
| 1123 | js.if("Object.getPrototypeOf(data) === Object.prototype", () => |
| 1124 | js |
| 1125 | .let("n", 0) |
| 1126 | .loop("for (const k in data)", () => js.line("n++")) |
| 1127 | .if(`n === ${held.join(" + ")}`, onCount) |
| 1128 | ) |
| 1129 | } |
| 1130 | |
| 1131 | // an Apply reporting one issue checks props as Allows does |
| 1132 | private propsOf(js: NodeCompiler): array<Prop.Node> { |