writes the check of one of data's entries
( js: NodeCompiler, keyDomain: "string" | "symbol" )
| 1621 | |
| 1622 | /** writes the check of one of data's entries */ |
| 1623 | protected jsEntry( |
| 1624 | js: NodeCompiler, |
| 1625 | keyDomain: "string" | "symbol" |
| 1626 | ): NodeCompiler { |
| 1627 | if (this.index) { |
| 1628 | for (const node of this.index) { |
| 1629 | js.if(js.allows(node.signature, "k"), () => |
| 1630 | js.travKey( |
| 1631 | keyDomain === "string" ? jsArrayPathKey(js) : "k", |
| 1632 | "data[k]", |
| 1633 | node.value |
| 1634 | ) |
| 1635 | ) |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | if (this.undeclared === "reject" && keyDomain === "string") { |
| 1640 | // for...in also reaches inherited keys, which aren't undeclared |
| 1641 | const isOwn = "Object.prototype.hasOwnProperty.call(data, k)" |
| 1642 | const skipsInherited = |
| 1643 | !this.index && !this.sequence && js.trav === "Allows" |
| 1644 | if (skipsInherited) js.line(`if (!${isOwn}) continue`) |
| 1645 | const props = this.props.filter(prop => typeof prop.key === keyDomain) |
| 1646 | if (props.length) compileDeclaredKeySwitch(js, props) |
| 1647 | const reject = () => |
| 1648 | js.trav === "Allows" ? |
| 1649 | js.return(false) |
| 1650 | : js.if(js.undeclaredFails?.(this) ?? js.error(this, "k"), () => |
| 1651 | js.return(false) |
| 1652 | ) |
| 1653 | const declaresKey = this._jsDeclaresKey(js) |
| 1654 | const conditions = declaresKey === "false" ? [] : [`!(${declaresKey})`] |
| 1655 | if (!this.index && !skipsInherited) conditions.push(isOwn) |
| 1656 | if (conditions.length) js.if(conditions.join(" && "), reject) |
| 1657 | else reject() |
| 1658 | } |
| 1659 | |
| 1660 | return js |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | // a structure's props of the other kind as this one, all of them or those at |
no test coverage detected