@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
62 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dataflowGraphToJson = dataflowGraphToJson;
exports.dataflowGraphToQuads = dataflowGraphToQuads;
const json_1 = require("../../util/json");
const quads_1 = require("../../dataflow/graph/quads");
function mayObjectJson(d) {
if (typeof d === 'object') {
return objectJson(d);
}
else {
return JSON.stringify(d, json_1.jsonReplacer);
}
}
function objectJson(df) {
if (df === null) {
return 'null';
}
const elems = [];
for (const [key, value] of Object.entries(df)) {
switch (typeof value) {
case 'undefined':
case 'function':
continue;
case 'object':
if (Array.isArray(value)) {
elems.push([key, `[${value.map(x => mayObjectJson(x)).join(',')}]`]);
}
else if (value instanceof Set) {
elems.push([key, `[${[...value].map(x => mayObjectJson(x)).join(',')}]`]);
}
else if (value instanceof Map) {
elems.push([key, `[${[...value].map(([k, v]) => `[${mayObjectJson(k)},${mayObjectJson(v)}]`).join(',')}]`]);
}
else {
elems.push([key, objectJson(value)]);
}
break;
case 'bigint':
elems.push([key, `${value.toString()}n`]);
break;
default:
elems.push([key, JSON.stringify(value, json_1.jsonReplacer)]);
}
}
return `{${elems.map(([key, value]) => `"${key}":${value}`).join(',')}}`;
}
/** Should work with larger things as well */
function dataflowGraphToJson(df) {
return objectJson(df);
}
/**
* Transforms the dataflow graph into a quad serialization.
* @see {@link df2quads}
* @see {@link dataflowGraphToMermaidUrl}
* @see {@link dataflowGraphToMermaid}
* @see {@link dataflowGraphToJson}
*/
function dataflowGraphToQuads(df, config) {
return (0, quads_1.df2quads)(df.graph, config);
}
//# sourceMappingURL=dataflow-printer.js.map