UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

43 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerFilePlugin = void 0; const flowr_analyzer_plugin_1 = require("../flowr-analyzer-plugin"); const flowr_file_1 = require("../../context/flowr-file"); const semver_1 = require("semver"); /** * This is the base class for all plugins that load and possibly transform files when they are loaded. * Different from other plugins, these plugins trigger for each file that is loaded (if they {@link applies} to the file). * See the {@link FlowrAnalyzer.addFile} for more information on how files are loaded and managed. * * It is up to the construction to ensure that no two file plugins {@link applies} to the same file, otherwise, the loading order * of these plugins will determine which plugin gets to process the file. * On transforming a file, your plugin can indicate whether other plugins should still get to process the file, * by returning a tuple of `[transformedFile, <boolean>]` where a boolean `true` indicates that other plugins should still get to process the file. * One example of a plugin doing this is the {@link FlowrAnalyzerMetaVignetteFilesPlugin}. * * See {@link DefaultFlowrAnalyzerFilePlugin} for the no-op default implementation. */ class FlowrAnalyzerFilePlugin extends flowr_analyzer_plugin_1.FlowrAnalyzerPlugin { type = flowr_analyzer_plugin_1.PluginType.FileLoad; static defaultPlugin() { return new DefaultFlowrAnalyzerFilePlugin(); } } exports.FlowrAnalyzerFilePlugin = FlowrAnalyzerFilePlugin; class DefaultFlowrAnalyzerFilePlugin extends FlowrAnalyzerFilePlugin { name = 'default-file-plugin'; description = 'This is the default file plugin that does nothing (but assigning default .r/.R files).'; version = new semver_1.SemVer('0.0.0'); applies() { return true; } process(_ctx, arg) { const path = arg.path().toString(); if (/\.r$/i.test(path)) { // we just assign the role :D arg.assignRole(flowr_file_1.FileRole.Source); } return arg; } } //# sourceMappingURL=flowr-analyzer-file-plugin.js.map