UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

64 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dataflowGraphToJson = dataflowGraphToJson; exports.dataflowGraphToMermaid = dataflowGraphToMermaid; exports.dataflowGraphToMermaidUrl = dataflowGraphToMermaidUrl; exports.dataflowGraphToQuads = dataflowGraphToQuads; const json_1 = require("../../util/json"); const quads_1 = require("../../dataflow/graph/quads"); const dfg_1 = require("../../util/mermaid/dfg"); 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); } function dataflowGraphToMermaid(df) { return (0, dfg_1.graphToMermaid)({ graph: df.graph }).string; } function dataflowGraphToMermaidUrl(df) { return (0, dfg_1.graphToMermaidUrl)(df.graph); } function dataflowGraphToQuads(df, config) { return (0, quads_1.df2quads)(df.graph, config); } //# sourceMappingURL=dataflow-printer.js.map