@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
84 lines (83 loc) • 2.85 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.includesNode = void 0;
var IRCase_1 = require("../../IRNodes/IRCase.js");
var IRApp_1 = require("../../IRNodes/IRApp.js");
var IRDelayed_1 = require("../../IRNodes/IRDelayed.js");
var IRForced_1 = require("../../IRNodes/IRForced.js");
var IRFunc_1 = require("../../IRNodes/IRFunc.js");
var IRHoisted_1 = require("../../IRNodes/IRHoisted.js");
var IRLetted_1 = require("../../IRNodes/IRLetted.js");
var IRConstr_1 = require("../../IRNodes/IRConstr.js");
var IRRecursive_1 = require("../../IRNodes/IRRecursive.js");
function includesNode(parent, predicate) {
var stack = [parent];
while (stack.length > 0) {
var t = stack.pop();
if (predicate(t))
return true;
if (t instanceof IRLetted_1.IRLetted) {
stack.push(t.value);
continue;
}
if (t instanceof IRApp_1.IRApp) {
stack.push(t.fn, t.arg);
continue;
}
if (t instanceof IRCase_1.IRCase) {
stack.push.apply(stack, __spreadArray([t.constrTerm], __read(t.continuations), false));
continue;
}
if (t instanceof IRConstr_1.IRConstr) {
stack.push.apply(stack, __spreadArray([], __read(t.fields), false));
continue;
}
if (t instanceof IRDelayed_1.IRDelayed) {
stack.push(t.delayed);
continue;
}
if (t instanceof IRForced_1.IRForced) {
stack.push(t.forced);
continue;
}
if (t instanceof IRFunc_1.IRFunc) {
stack.push(t.body);
continue;
}
if (t instanceof IRRecursive_1.IRRecursive) {
stack.push(t.body);
continue;
}
if (t instanceof IRHoisted_1.IRHoisted) {
stack.push(t.hoisted);
continue;
}
}
return false;
}
exports.includesNode = includesNode;