UNPKG

1.85 kBTypeScriptView Raw
1import * as babelTypes from "babel-types";
2import { FileCoverage, FileCoverageData, Range } from "istanbul-lib-coverage";
3import { RawSourceMap } from "source-map";
4
5export interface InstrumenterOptions {
6 coverageVariable: string;
7 preserveComments: boolean;
8 compact: boolean;
9 esModules: boolean;
10 autoWrap: boolean;
11 produceSourceMap: boolean;
12 sourceMapUrlCallback(filename: string, url: string): void;
13 debug: boolean;
14}
15
16export type InstrumenterCallback = (error: Error | null, code: string) => void;
17
18export class Instrumenter {
19 fileCoverage: FileCoverage;
20 sourceMap: RawSourceMap | null;
21 opts: InstrumenterOptions;
22
23 constructor(options?: Partial<InstrumenterOptions>);
24
25 normalizeOpts(options?: Partial<InstrumenterOptions>): InstrumenterOptions;
26
27 instrumentSync(
28 code: string,
29 filename: string,
30 inputSourceMap?: RawSourceMap,
31 ): string;
32
33 instrument(
34 code: string,
35 filenameOrCallback: string | InstrumenterCallback,
36 callback?: InstrumenterCallback,
37 inputSourceMap?: RawSourceMap,
38 ): void;
39
40 lastFileCoverage(): FileCoverageData;
41 lastSourceMap(): RawSourceMap;
42}
43
44export function createInstrumenter(
45 options?: Partial<InstrumenterOptions>,
46): Instrumenter;
47
48export interface InitialCoverage {
49 path: string;
50 hash: string;
51 gcv: any;
52 coverageData: any;
53}
54
55export function readInitialCoverage(code: string): InitialCoverage;
56
57export interface Visitor {
58 enter(path: string): void;
59 exit(path: string): { fileCoverage: FileCoverage; sourceMappingURL: string };
60}
61
62export interface VisitorOptions {
63 coverageVariable: string;
64 inputSourceMap: RawSourceMap;
65}
66
67export function programVisitor(
68 types: typeof babelTypes,
69 sourceFilePath?: string,
70 opts?: Partial<VisitorOptions>,
71): Visitor;