UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

34 lines (33 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dependsByDbns = void 0; var iterTree_1 = require("../../toUPLC/_internal/iterTree.js"); var IRSelfCall_1 = require("../IRSelfCall.js"); var IRVar_1 = require("../IRVar.js"); /** * returns true if the term depends on *ANY* of the deBrujin indices specified */ function dependsByDbns(term, depsDbns) { if (depsDbns.length === 0) return false; var doesDepend = false; (0, iterTree_1.iterTree)(term, function (node, diff) { if (node instanceof IRVar_1.IRVar || node instanceof IRSelfCall_1.IRSelfCall) { doesDepend = doesDepend || depsDbns.some(function (dbn) { var realDbn = dbn + diff; // realDbn === 0 implies no variables are in scope // so if node.dbn === 0 and realDbn === 1 then the // variable is pointing to that definition return node.dbn === realDbn; }); } }, // shouldSkipNode undefined, // shouldStop function () { return doesDepend; } // exit early ); return doesDepend; } exports.dependsByDbns = dependsByDbns;