writes the deletion of undeclared keys: from a copy where data has them, else into a literal of the declared ones
( js: NodeCompiler, transformedProps: Prop.Node[], outMayBeCopied: boolean )
| 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( |
| 1452 | js: NodeCompiler, |
| 1453 | transformedProps: Prop.Node[], |
| 1454 | outMayBeCopied: boolean |
| 1455 | ): void { |
| 1456 | const deleteFromCopy = (js: NodeCompiler) => |
| 1457 | this.jsDeleteFromCopy(js, transformedProps) |
| 1458 | if (this.sequence) { |
| 1459 | // only an array with non-index keys is scanned for undeclared ones |
| 1460 | js.const( |
| 1461 | "indexed", |
| 1462 | `${this.slicesSeq ? "out !== data || " : ""}${js.ref(holdsOnlyIndices)}(data)` |
| 1463 | ) |
| 1464 | const unchanged = ["indexed"] |
| 1465 | if (outMayBeCopied) unchanged.push("out === data") |
| 1466 | for (let i = 0; i < transformedProps.length; i++) { |
| 1467 | unchanged.push( |
| 1468 | js.cmpTfd( |
| 1469 | this.tfsOf(transformedProps[i]), |
| 1470 | `transformed${i}`, |
| 1471 | "===", |
| 1472 | `value${i}` |
| 1473 | ) |
| 1474 | ) |
| 1475 | } |
| 1476 | for (const node of this.defaultable) |
| 1477 | unchanged.push(node.jsHoldsValue(js, "data")) |
| 1478 | const sequence = this.sequence |
| 1479 | if (sequence.defaultsUndefined) { |
| 1480 | // an undefined element is replaced too, so each is checked on its own |
| 1481 | for (let i = 0; i < sequence.defLen; i++) { |
| 1482 | unchanged.push( |
| 1483 | `(${sequence.jsHoldsElement(true, sequence.preLen + i)})` |
| 1484 | ) |
| 1485 | } |
| 1486 | } else if (sequence.defaultables) |
| 1487 | unchanged.push(`data.length >= ${sequence.preLen + sequence.defLen}`) |
| 1488 | js.if(unchanged.join(" && "), () => js.return("data")) |
| 1489 | deleteFromCopy(js) |
| 1490 | return |
| 1491 | } |
| 1492 | // out is data unless an index signature's value changed, when it's a |
| 1493 | // spread of data, which skips a declared key data holds as a |
| 1494 | // non-enumerable own prop. Nothing has written a declared key to it |
| 1495 | const unchanged = outMayBeCopied ? "data" : "out" |
| 1496 | const outputOf = (prop: Prop.Node) => { |
| 1497 | const i = transformedProps.indexOf(prop) |
| 1498 | return i === -1 ? `${unchanged}${js.prop(prop.key)}` : `transformed${i}` |
| 1499 | } |
| 1500 | const [literal, added] = this.resultLayout |
| 1501 | const literalOf = ( |
| 1502 | props: array<Prop.Node>, |
| 1503 | valueOf: (prop: Prop.Node) => string |
| 1504 | ) => |
| 1505 | `{ ${props |
| 1506 | .map( |
| 1507 | prop => |
| 1508 | `${ |
no test coverage detected