UNPKG

6 kBTypeScriptView Raw
1import { RawSourceMap } from "source-map";
2
3/**
4 * Output of `retrieveSourceMap()`.
5 * The map field may be either a string or the parsed JSON object (i.e.,
6 * it must be a valid argument to the SourceMapConsumer constructor).
7 */
8export interface UrlAndMap {
9 url?: string | undefined;
10 map: string | RawSourceMap;
11}
12
13export type Environment = "auto" | "browser" | "node";
14
15/**
16 * Options to install().
17 */
18export interface Options {
19 /**
20 * This module installs two things: a change to the `stack` property on `Error`
21 * objects and a handler for uncaught exceptions that mimics node's default exception
22 * handler (the handler can be seen in the demos below). You may want to disable the
23 * handler if you have your own uncaught exception handler. This can be done by passing
24 * an argument to the installer.
25 *
26 * @example
27 * import { install } from 'source-map-support';
28 *
29 * install({
30 * handleUncaughtExceptions: false
31 * });
32 */
33 handleUncaughtExceptions?: boolean | undefined;
34 /**
35 * To support files with inline source maps, the `hookRequire` options can be specified,
36 * which will monitor all source files for inline source maps.
37 *
38 * This monkey patches the `require` module loading chain, so is not enabled by default
39 * and is not recommended for any sort of production usage.
40 *
41 * @example
42 * import { install } from 'source-map-support';
43 *
44 * install({
45 * hookRequire: true
46 * });
47 * ```
48 */
49 hookRequire?: boolean | undefined;
50 /**
51 * If `true`, the caches are reset before a stack trace formatting operation.
52 */
53 emptyCacheBetweenOperations?: boolean | undefined;
54 /**
55 * The module will by default assume a browser environment if `XMLHttpRequest` and `window`
56 * are defined. If either of these do not exist it will instead assume a node environment.
57 * In some rare cases, e.g. when running a browser emulation and where both variables are
58 * also set, you can explicitly specify the environment to be either `'browser'` or `'node'`.
59 *
60 * @example
61 * import { install } from 'source-map-support';
62 *
63 * install({
64 * environment: 'node'
65 * });
66 */
67 environment?: Environment | undefined;
68 /**
69 * Disable all other means of retrieving file contents and use only the provided
70 * `retrieveFile` handler.
71 */
72 overrideRetrieveFile?: boolean | undefined;
73 /**
74 * Disable all other means of retrieving source maps and use only the provided
75 * `retrieveSourceMap` handler.
76 */
77 overrideRetrieveSourceMap?: boolean | undefined;
78 /**
79 * Allow sources to be found by methods other than reading the files
80 * directly from disk.
81 */
82 retrieveFile?(path: string): string | null;
83 /**
84 * This module loads source maps from the filesystem by default. You can provide alternate
85 * loading behavior through a callback as shown below. For example, [Meteor](https://github.com/meteor)
86 * keeps all source maps cached in memory to avoid disk access.
87 *
88 * @example
89 * import { install } from 'source-map-support';
90 *
91 * install({
92 * retrieveSourceMap(source) {
93 * if (source === 'compiled.js') {
94 * return {
95 * url: 'original.js',
96 * map: fs.readFileSync('compiled.js.map', 'utf8')
97 * };
98 * }
99 * return null;
100 * }
101 * });
102 */
103 retrieveSourceMap?(source: string): UrlAndMap | null;
104}
105
106export interface Position {
107 source: string;
108 line: number;
109 column: number;
110}
111
112export interface State {
113 nextPosition: Position | null;
114 curPosition: Position | null;
115}
116
117export interface CallSite {
118 /**
119 * Value of "this"
120 */
121 getThis(): any;
122
123 /**
124 * Type of "this" as a string.
125 * This is the name of the function stored in the constructor field of
126 * "this", if available. Otherwise the object's [[Class]] internal
127 * property.
128 */
129 getTypeName(): string | null;
130
131 /**
132 * Current function
133 */
134 getFunction(): ((...args: unknown[]) => any) | undefined;
135
136 /**
137 * Name of the current function, typically its name property.
138 * If a name property is not available an attempt will be made to try
139 * to infer a name from the function's context.
140 */
141 getFunctionName(): string | null;
142
143 /**
144 * Name of the property [of "this" or one of its prototypes] that holds
145 * the current function
146 */
147 getMethodName(): string | null;
148
149 /**
150 * Name of the script [if this function was defined in a script]
151 */
152 getFileName(): string | null;
153
154 /**
155 * Current line number [if this function was defined in a script]
156 */
157 getLineNumber(): number | null;
158
159 /**
160 * Current column number [if this function was defined in a script]
161 */
162 getColumnNumber(): number | null;
163
164 /**
165 * A call site object representing the location where eval was called
166 * [if this function was created using a call to eval]
167 */
168 getEvalOrigin(): string | undefined;
169
170 /**
171 * Is this a toplevel invocation, that is, is "this" the global object?
172 */
173 isToplevel(): boolean;
174
175 /**
176 * Does this call take place in code defined by a call to eval?
177 */
178 isEval(): boolean;
179
180 /**
181 * Is this call in native V8 code?
182 */
183 isNative(): boolean;
184
185 /**
186 * Is this a constructor call?
187 */
188 isConstructor(): boolean;
189
190 getScriptNameOrSourceURL?(): string;
191}
192
193export function wrapCallSite(frame: CallSite, state?: State): CallSite;
194export function getErrorSource(error: Error): string | null;
195export function mapSourcePosition(position: Position): Position;
196export function retrieveSourceMap(source: string): UrlAndMap | null;
197export function resetRetrieveHandlers(): void;
198
199/**
200 * Install SourceMap support.
201 */
202export function install(options?: Options): void;
203
\No newline at end of file