writes the deletion of undeclared keys from a copy of data, after its transforms and defaults
( js: NodeCompiler, transformedProps: Prop.Node[] )
| 1410 | |
| 1411 | /** writes the deletion of undeclared keys from a copy of data, after its transforms and defaults */ |
| 1412 | private jsDeleteFromCopy( |
| 1413 | js: NodeCompiler, |
| 1414 | transformedProps: Prop.Node[] |
| 1415 | ): NodeCompiler { |
| 1416 | for (let i = 0; i < transformedProps.length; i++) { |
| 1417 | const prop = transformedProps[i] |
| 1418 | const changed = js.cmpTfd( |
| 1419 | this.tfsOf(prop), |
| 1420 | `transformed${i}`, |
| 1421 | "!==", |
| 1422 | `value${i}` |
| 1423 | ) |
| 1424 | js.if(changed, () => |
| 1425 | this.jsCopy(js).line( |
| 1426 | jsSetOwnProp(js, "out", prop.key, `transformed${i}`) |
| 1427 | ) |
| 1428 | ) |
| 1429 | } |
| 1430 | this.jsDefaults(js) |
| 1431 | const deletes = () => |
| 1432 | this.jsForOwnKeys( |
| 1433 | js, |
| 1434 | "data", |
| 1435 | () => |
| 1436 | js.if( |
| 1437 | `!(k in ${js.ref(this.byKey)}) && !(${this._jsDeclaresKey(js)})`, |
| 1438 | () => this.jsCopy(js).line("delete out[k]") |
| 1439 | ), |
| 1440 | "dataKeys", |
| 1441 | "dataSymbols", |
| 1442 | true |
| 1443 | ) |
| 1444 | if (this.sequence) js.if("!indexed", deletes) |
| 1445 | else deletes() |
| 1446 | this.jsDeclaredCopy(js) |
| 1447 | return js.return("out") |
| 1448 | } |
| 1449 | |
| 1450 | /** writes the deletion of undeclared keys: from a copy where data has them, else into a literal of the declared ones */ |
| 1451 | private jsDeleteTransform( |
no test coverage detected