@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
84 lines • 2.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Package = void 0;
const assert_1 = require("../../../util/assert");
const r_version_1 = require("../../../util/r-version");
class Package {
name;
derivedVersion;
type;
dependencies;
namespaceInfo;
versionConstraints = [];
constructor(info) {
this.name = info.name;
this.addInfo(info);
}
has(name, className) {
if (!this.namespaceInfo) {
return false;
}
if (name.includes('.')) {
const [genericSplit, classSplit] = name.split('.');
const classes = this.namespaceInfo.exportS3Generics.get(genericSplit);
return classes ? classes.includes(classSplit) : false;
}
if (className) {
const classes = this.namespaceInfo.exportS3Generics.get(name);
return classes ? classes.includes(className) : false;
}
return this.namespaceInfo.exportedFunctions.includes(name) || this.namespaceInfo.exportedSymbols.includes(name);
}
s3For(generic) {
return this.namespaceInfo?.exportS3Generics.get(generic) ?? [];
}
mergeInPlace(other) {
(0, assert_1.guard)(this.name === other.name, 'Can only merge packages with the same name');
this.addInfo({
type: other.type,
dependencies: other.dependencies,
namespaceInfo: other.namespaceInfo,
versionConstraints: other.versionConstraints
});
}
addInfo(info) {
const { type, dependencies, namespaceInfo, versionConstraints } = info;
if (type !== undefined) {
this.type = type;
}
if (dependencies !== undefined) {
this.dependencies = dependencies;
}
if (namespaceInfo !== undefined) {
this.namespaceInfo = namespaceInfo;
}
if (versionConstraints !== undefined) {
this.derivedVersion ??= versionConstraints[0];
for (const constraint of versionConstraints) {
if (!this.derivedVersion?.intersects(constraint)) {
throw new Error('Version constraint mismatch!');
}
this.versionConstraints.push(constraint);
this.derivedVersion = this.deriveVersion();
}
}
}
getInfo() {
return this;
}
deriveVersion() {
return this.versionConstraints.length > 0
? (0, r_version_1.parseRRange)(this.versionConstraints.map(c => c.raw).join(' '))
: undefined;
}
static parsePackageVersionRange(constraint, version) {
if (version) {
return constraint ? (0, r_version_1.parseRRange)(constraint + version) : (0, r_version_1.parseRRange)(version);
}
else {
return undefined;
}
}
}
exports.Package = Package;
//# sourceMappingURL=package.js.map