@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
38 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KnownHooks = void 0;
exports.compactHookStates = compactHookStates;
exports.getHookInformation = getHookInformation;
const info_1 = require("./info");
const defaultmap_1 = require("../util/collections/defaultmap");
var KnownHooks;
(function (KnownHooks) {
/** Triggers on the exit of a function, no matter how this exit is enforced. */
KnownHooks["OnFnExit"] = "fn-exit";
})(KnownHooks || (exports.KnownHooks = KnownHooks = {}));
/**
* Compacts a list of hook registrations by removing redundant and dominated ones.
*/
function compactHookStates(hooks) {
const hooksByType = new defaultmap_1.DefaultMap(() => []);
for (const hook of hooks) {
if (!hook.add && (0, info_1.happensInEveryBranch)(hook.cds)) {
hooksByType.set(hook.type, [hook]);
}
else if (hook.after) {
hooksByType.get(hook.type).push(hook);
}
else {
hooksByType.get(hook.type).unshift(hook);
}
}
return hooksByType.values().flatMap(f => f).toArray();
}
/**
* Extracts all hooks of the given type from the list of hooks.
* Please consider {@link compactHookStates} to remove redundant or dominated hooks first.
*/
function getHookInformation(hooks, type) {
return hooks.filter(h => h.type === type);
}
//# sourceMappingURL=hooks.js.map