MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / resolve

Method resolve

www/js/_hyperscript.js:4753–4806  ·  view source on GitHub ↗
(context, { lhs: lhsVal, rhs: rhsVal, rhs2: rhs2Val })

Source from the content-addressed store, hash-verified

4751 return expr;
4752 }
4753 resolve(context, { lhs: lhsVal, rhs: rhsVal, rhs2: rhs2Val }) {
4754 const operator = this.operator;
4755 const lhs = this.lhs;
4756 const rhs = this.rhs;
4757 const typeName = this.typeName;
4758 const nullOk = this.nullOk;
4759 if (this.ignoringCase) {
4760 if (typeof lhsVal === "string") lhsVal = lhsVal.toLowerCase();
4761 if (typeof rhsVal === "string") rhsVal = rhsVal.toLowerCase();
4762 }
4763 if (operator === "is") {
4764 if (rhsVal === void 0 && rhs.type === "symbol" && rhs.scope === "local" && rhs.name !== "undefined" && rhs.name !== "null") {
4765 return !!context.meta.runtime.resolveProperty(lhsVal, rhs.name);
4766 }
4767 return lhsVal == rhsVal;
4768 }
4769 if (operator === "is not") {
4770 if (rhsVal === void 0 && rhs.type === "symbol" && rhs.scope === "local" && rhs.name !== "undefined" && rhs.name !== "null") {
4771 return !context.meta.runtime.resolveProperty(lhsVal, rhs.name);
4772 }
4773 return lhsVal != rhsVal;
4774 }
4775 if (operator === "==") return lhsVal == rhsVal;
4776 if (operator === "!=") return lhsVal != rhsVal;
4777 if (operator === "===") return lhsVal === rhsVal;
4778 if (operator === "!==") return lhsVal !== rhsVal;
4779 if (operator === "<") return lhsVal < rhsVal;
4780 if (operator === ">") return lhsVal > rhsVal;
4781 if (operator === "<=") return lhsVal <= rhsVal;
4782 if (operator === ">=") return lhsVal >= rhsVal;
4783 if (operator === "match") return lhsVal != null && this.sloppyMatches(lhs, lhsVal, rhsVal);
4784 if (operator === "not match") return lhsVal == null || !this.sloppyMatches(lhs, lhsVal, rhsVal);
4785 if (operator === "in") return rhsVal != null && this.sloppyContains(rhs, rhsVal, lhsVal);
4786 if (operator === "not in") return rhsVal == null || !this.sloppyContains(rhs, rhsVal, lhsVal);
4787 if (operator === "contain" || operator === "include") return lhsVal != null && this.sloppyContains(lhs, lhsVal, rhsVal);
4788 if (operator === "not contain" || operator === "not include") return lhsVal == null || !this.sloppyContains(lhs, lhsVal, rhsVal);
4789 if (operator === "start with") return lhsVal != null && String(lhsVal).startsWith(rhsVal);
4790 if (operator === "not start with") return lhsVal == null || !String(lhsVal).startsWith(rhsVal);
4791 if (operator === "end with") return lhsVal != null && String(lhsVal).endsWith(rhsVal);
4792 if (operator === "not end with") return lhsVal == null || !String(lhsVal).endsWith(rhsVal);
4793 if (operator === "between") return lhsVal >= rhsVal && lhsVal <= rhs2Val;
4794 if (operator === "not between") return lhsVal < rhsVal || lhsVal > rhs2Val;
4795 if (operator === "precede") return lhsVal != null && rhsVal != null && (lhsVal.compareDocumentPosition(rhsVal) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
4796 if (operator === "not precede") return lhsVal == null || rhsVal == null || (lhsVal.compareDocumentPosition(rhsVal) & Node.DOCUMENT_POSITION_FOLLOWING) === 0;
4797 if (operator === "follow") return lhsVal != null && rhsVal != null && (lhsVal.compareDocumentPosition(rhsVal) & Node.DOCUMENT_POSITION_PRECEDING) !== 0;
4798 if (operator === "not follow") return lhsVal == null || rhsVal == null || (lhsVal.compareDocumentPosition(rhsVal) & Node.DOCUMENT_POSITION_PRECEDING) === 0;
4799 if (operator === "empty") return context.meta.runtime.isEmpty(lhsVal);
4800 if (operator === "not empty") return !context.meta.runtime.isEmpty(lhsVal);
4801 if (operator === "exist") return context.meta.runtime.doesExist(lhsVal);
4802 if (operator === "not exist") return !context.meta.runtime.doesExist(lhsVal);
4803 if (operator === "a") return context.meta.runtime.typeCheck(lhsVal, typeName.value, nullOk);
4804 if (operator === "not a") return !context.meta.runtime.typeCheck(lhsVal, typeName.value, nullOk);
4805 throw new Error("Unknown comparison : " + operator);
4806 }
4807 };
4808 var LogicalOperator = class _LogicalOperator extends Expression {
4809 static grammarName = "logicalOperator";

Callers

nothing calls this directly

Calls 6

sloppyMatchesMethod · 0.95
sloppyContainsMethod · 0.95
resolvePropertyMethod · 0.45
isEmptyMethod · 0.45
doesExistMethod · 0.45
typeCheckMethod · 0.45

Tested by

no test coverage detected