Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@syntest/analysis

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@syntest/analysis - npm Package Compare versions

Comparing version 0.3.0-beta.1 to 0.3.0-beta.2

17

dist/lib/RootContext.d.ts

@@ -9,2 +9,4 @@ import { ControlFlowProgram } from "@syntest/cfg";

import { SubTarget, Target } from "./Target";
export declare function cache(cacheName: string): (_: RootContext<unknown>, __: string, descriptor: TypedPropertyDescriptor<(filePath: string) => Result<any>>) => void;
export declare function resolvePath(): (_: RootContext<unknown>, __: string, descriptor: TypedPropertyDescriptor<(filePath: string) => Result<any>>) => void;
export declare class RootContext<S> {

@@ -17,9 +19,4 @@ protected _rootPath: string;

protected dependencyFactory: DependencyFactory<S>;
protected _sources: Map<string, string>;
protected _abstractSyntaxTrees: Map<string, S>;
protected _controlFlowProgramMap: Map<string, ControlFlowProgram>;
protected _targetMap: Map<string, Target>;
protected _dependenciesMap: Map<string, string[]>;
constructor(rootPath: string, sourceFactory: SourceFactory, abstractSyntaxTreeFactory: AbstractSyntaxTreeFactory<S>, controlFlowGraphFactory: ControlFlowGraphFactory<S>, targetFactory: TargetFactory<S>, dependencyFactory: DependencyFactory<S>);
protected resolvePath(filePath: string): Result<string>;
resolvePath(filePath: string): Result<string>;
protected verifyTargetPath(filePath: string): boolean;

@@ -48,12 +45,12 @@ /**

/**
* gets all sub-targets from the given filePath
* Loads all dependencies from the given filePath
* @param filePath
*/
getSubTargets(filePath: string): Result<SubTarget[]>;
getDependencies(filePath: string): Result<string[]>;
/**
* Loads all dependencies from the given filePath
* gets all sub-targets from the given filePath
* @param filePath
*/
getDependencies(filePath: string): Result<string[]>;
getSubTargets(filePath: string): Result<SubTarget[]>;
}
//# sourceMappingURL=RootContext.d.ts.map
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RootContext = void 0;
exports.RootContext = exports.resolvePath = exports.cache = void 0;
/*

@@ -23,2 +29,33 @@ * Copyright 2020-2023 SynTest contributors

const diagnostics_1 = require("@syntest/diagnostics");
const caches = {};
function cache(cacheName) {
const cache = new Map();
caches[cacheName] = cache;
return function (_, __, descriptor) {
const method = descriptor.value;
descriptor.value = function (filePath) {
const key = filePath;
if (caches[cacheName].has(key)) {
return caches[cacheName].get(key);
}
const result = Reflect.apply(method, this, [filePath]);
caches[cacheName].set(key, result);
return result;
};
};
}
exports.cache = cache;
function resolvePath() {
return function (_, __, descriptor) {
const method = descriptor.value;
descriptor.value = function (filePath) {
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
return Reflect.apply(method, this, [absolutePath]);
};
};
}
exports.resolvePath = resolvePath;
class RootContext {

@@ -32,7 +69,2 @@ constructor(rootPath, sourceFactory, abstractSyntaxTreeFactory, controlFlowGraphFactory, targetFactory, dependencyFactory) {

this.dependencyFactory = dependencyFactory;
this._sources = new Map();
this._abstractSyntaxTrees = new Map();
this._controlFlowProgramMap = new Map();
this._targetMap = new Map();
this._dependenciesMap = new Map();
}

@@ -56,16 +88,7 @@ resolvePath(filePath) {

getSource(filePath) {
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
// this takes up too much memory we should do some kind of garbage collection if we want to save it all
if (!this._sources.has(absolutePath)) {
process.emit("sourceResolvingStart", this, absolutePath);
const result = this.sourceFactory.produce(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
this._sources.set(absolutePath, (0, diagnostics_1.unwrap)(result));
process.emit("sourceResolvingComplete", this, absolutePath, this._sources.get(absolutePath));
}
return (0, diagnostics_1.success)(this._sources.get(absolutePath));
const sourceResult = this.sourceFactory.produce(filePath);
if ((0, diagnostics_1.isFailure)(sourceResult))
return sourceResult;
process.emit("sourceResolvingComplete", this, filePath, (0, diagnostics_1.unwrap)(sourceResult));
return sourceResult;
}

@@ -77,19 +100,11 @@ /**

getAbstractSyntaxTree(filePath) {
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
// this takes up too much memory we should do some kind of garbage collection if we want to save it all
if (!this._abstractSyntaxTrees.has(absolutePath)) {
process.emit("abstractSyntaxTreeResolvingStart", this, absolutePath);
const result = this.getSource(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const astResult = this.abstractSyntaxTreeFactory.convert(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(astResult))
return astResult;
this._abstractSyntaxTrees.set(absolutePath, (0, diagnostics_1.unwrap)(astResult));
process.emit("abstractSyntaxTreeResolvingComplete", this, absolutePath, this._abstractSyntaxTrees.get(absolutePath));
}
return (0, diagnostics_1.success)(this._abstractSyntaxTrees.get(absolutePath));
process.emit("abstractSyntaxTreeResolvingStart", this, filePath);
const sourceResult = this.getSource(filePath);
if ((0, diagnostics_1.isFailure)(sourceResult))
return sourceResult;
const astResult = this.abstractSyntaxTreeFactory.convert(filePath, (0, diagnostics_1.unwrap)(sourceResult));
if ((0, diagnostics_1.isFailure)(astResult))
return astResult;
process.emit("abstractSyntaxTreeResolvingComplete", this, filePath, (0, diagnostics_1.unwrap)(astResult));
return astResult;
}

@@ -101,18 +116,11 @@ /**

getControlFlowProgram(filePath) {
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
if (!this._controlFlowProgramMap.has(absolutePath)) {
process.emit("controlFlowGraphResolvingStart", this, absolutePath);
const result = this.getAbstractSyntaxTree(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const cfgResult = this.controlFlowGraphFactory.convert(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(cfgResult))
return cfgResult;
this._controlFlowProgramMap.set(absolutePath, (0, diagnostics_1.unwrap)(cfgResult));
process.emit("controlFlowGraphResolvingComplete", this, absolutePath, this._controlFlowProgramMap.get(absolutePath));
}
return (0, diagnostics_1.success)(this._controlFlowProgramMap.get(absolutePath));
process.emit("controlFlowGraphResolvingStart", this, filePath);
const astResult = this.getAbstractSyntaxTree(filePath);
if ((0, diagnostics_1.isFailure)(astResult))
return astResult;
const cfgResult = this.controlFlowGraphFactory.convert(filePath, (0, diagnostics_1.unwrap)(astResult));
if ((0, diagnostics_1.isFailure)(cfgResult))
return cfgResult;
process.emit("controlFlowGraphResolvingComplete", this, filePath, (0, diagnostics_1.unwrap)(cfgResult));
return cfgResult;
}

@@ -125,20 +133,28 @@ /**

getTarget(filePath) {
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
if (!this._targetMap.has(absolutePath)) {
process.emit("targetExtractionStart", this, absolutePath);
const result = this.getAbstractSyntaxTree(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const targetResult = this.targetFactory.extract(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(targetResult))
return targetResult;
this._targetMap.set(absolutePath, (0, diagnostics_1.unwrap)(targetResult));
process.emit("targetExtractionComplete", this, absolutePath, this._targetMap.get(absolutePath));
}
return (0, diagnostics_1.success)(this._targetMap.get(absolutePath));
process.emit("targetExtractionStart", this, filePath);
const astResult = this.getAbstractSyntaxTree(filePath);
if ((0, diagnostics_1.isFailure)(astResult))
return astResult;
const targetResult = this.targetFactory.extract(filePath, (0, diagnostics_1.unwrap)(astResult));
if ((0, diagnostics_1.isFailure)(targetResult))
return targetResult;
process.emit("targetExtractionComplete", this, filePath, (0, diagnostics_1.unwrap)(targetResult));
return targetResult;
}
/**
* Loads all dependencies from the given filePath
* @param filePath
*/
getDependencies(filePath) {
process.emit("dependencyResolvingStart", this, filePath);
const astResult = this.getAbstractSyntaxTree(filePath);
if ((0, diagnostics_1.isFailure)(astResult))
return astResult;
const dependencyResult = this.dependencyFactory.extract(filePath, (0, diagnostics_1.unwrap)(astResult));
if ((0, diagnostics_1.isFailure)(dependencyResult))
return dependencyResult;
process.emit("dependencyResolvingComplete", this, filePath, (0, diagnostics_1.unwrap)(dependencyResult));
return dependencyResult;
}
/**
* gets all sub-targets from the given filePath

@@ -153,26 +169,24 @@ * @param filePath

}
/**
* Loads all dependencies from the given filePath
* @param filePath
*/
getDependencies(filePath) {
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
if (!this._dependenciesMap.has(absolutePath)) {
process.emit("dependencyResolvingStart", this, absolutePath);
const result = this.getAbstractSyntaxTree(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const dependencyResult = this.dependencyFactory.extract(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(dependencyResult))
return dependencyResult;
this._dependenciesMap.set(absolutePath, (0, diagnostics_1.unwrap)(dependencyResult));
process.emit("dependencyResolvingComplete", this, absolutePath, this._dependenciesMap.get(absolutePath));
}
return (0, diagnostics_1.success)(this._dependenciesMap.get(absolutePath));
}
}
__decorate([
cache("source"),
resolvePath()
], RootContext.prototype, "getSource", null);
__decorate([
cache("ast"),
resolvePath()
], RootContext.prototype, "getAbstractSyntaxTree", null);
__decorate([
cache("cfp"),
resolvePath()
], RootContext.prototype, "getControlFlowProgram", null);
__decorate([
cache("target"),
resolvePath()
], RootContext.prototype, "getTarget", null);
__decorate([
cache("dependencies"),
resolvePath()
], RootContext.prototype, "getDependencies", null);
exports.RootContext = RootContext;
//# sourceMappingURL=RootContext.js.map
{
"name": "@syntest/analysis",
"version": "0.3.0-beta.1",
"version": "0.3.0-beta.2",
"description": "SynTest library for analyzing code",

@@ -65,3 +65,3 @@ "keywords": [

},
"gitHead": "3f6b9612c030ffc79d5e79c5c1c126ca816a87a6"
"gitHead": "9f1596cdb871f5327dfa3f41a913b46f37d20969"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc