writes the copy of data's declared keys, those in `written` aside
(js: NodeCompiler, written?: Key[])
| 1330 | |
| 1331 | /** writes the copy of data's declared keys, those in `written` aside */ |
| 1332 | jsDeclaredCopy(js: NodeCompiler, written?: Key[]): NodeCompiler { |
| 1333 | if (this.sequence || this.writesInto(js)) return js |
| 1334 | const copyKeys = () => { |
| 1335 | for (const prop of this.inOrder) { |
| 1336 | if (written?.includes(prop.key) || prop.key in Object.prototype) |
| 1337 | continue |
| 1338 | js.line(`${js.ref(keepOwn)}(out, data, ${js.serialize(prop.key)})`) |
| 1339 | } |
| 1340 | // out inherits these, so only an own one is missing |
| 1341 | for (const prop of this.protoProps) { |
| 1342 | js.if( |
| 1343 | `!Object.prototype.hasOwnProperty.call(out, ${js.serialize(prop.key)}) && Object.prototype.hasOwnProperty.call(data, ${js.serialize(prop.key)})`, |
| 1344 | () => |
| 1345 | js.line( |
| 1346 | jsSetOwnProp(js, "out", prop.key, `data${js.prop(prop.key)}`) |
| 1347 | ) |
| 1348 | ) |
| 1349 | } |
| 1350 | return js |
| 1351 | } |
| 1352 | return written === undefined ? js.if("out !== data", copyKeys) : copyKeys() |
| 1353 | } |
| 1354 | |
| 1355 | /** writes the copy of data's props: an array's copy has only its enumerable props */ |
| 1356 | private jsCopyProps( |
no test coverage detected