UNPKG

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