@nodesecure/js-x-ray
Version:
JavaScript AST XRay analysis
79 lines • 2.22 kB
TypeScript
import type { ESTree } from "meriyah";
import { type Warning, type OptionalWarningName } from "./warnings.js";
import { SourceFile, type SourceFlags } from "./SourceFile.js";
import { type SourceParser } from "./JsSourceParser.js";
import { type Probe } from "./ProbeRunner.js";
import { type Pipeline } from "./pipelines/index.js";
export interface Dependency {
unsafe: boolean;
inTry: boolean;
location?: null | ESTree.SourceLocation;
}
export interface RuntimeOptions {
/**
* @default true
*/
module?: boolean;
/**
* @default false
*/
removeHTMLComments?: boolean;
/**
* @default false
*/
isMinified?: boolean;
initialize?: (sourceFile: SourceFile) => void;
finalize?: (sourceFile: SourceFile) => void;
}
export interface RuntimeFileOptions extends Omit<RuntimeOptions, "isMinified"> {
packageName?: string;
}
export interface Report {
dependencies: Map<string, Dependency>;
warnings: Warning[];
flags: Set<SourceFlags>;
idsLengthAvg: number;
stringScore: number;
}
export type ReportOnFile = {
ok: true;
warnings: Warning[];
dependencies: Map<string, Dependency>;
flags: Set<SourceFlags>;
} | {
ok: false;
warnings: Warning[];
};
export interface AstAnalyserOptions {
/**
* @default JsSourceParser
*/
customParser?: SourceParser;
/**
* @default []
*/
customProbes?: Probe[];
/**
* @default false
*/
skipDefaultProbes?: boolean;
/**
* @default false
*/
optionalWarnings?: boolean | Iterable<OptionalWarningName>;
pipelines?: Pipeline[];
}
export interface PrepareSourceOptions {
removeHTMLComments?: boolean;
}
export declare class AstAnalyser {
#private;
parser: SourceParser;
probes: Probe[];
constructor(options?: AstAnalyserOptions);
analyse(str: string, options?: RuntimeOptions): Report;
analyseFile(pathToFile: string | URL, options?: RuntimeFileOptions): Promise<ReportOnFile>;
analyseFileSync(pathToFile: string | URL, options?: RuntimeFileOptions): ReportOnFile;
prepareSource(source: string, options?: PrepareSourceOptions): string;
}
//# sourceMappingURL=AstAnalyser.d.ts.map