[57e58a3] | 1 | export interface BundleOptions {
|
---|
| 2 | intro?: string;
|
---|
| 3 | separator?: string;
|
---|
| 4 | }
|
---|
| 5 |
|
---|
| 6 | export interface SourceMapOptions {
|
---|
| 7 | /**
|
---|
| 8 | * Whether the mapping should be high-resolution.
|
---|
| 9 | * Hi-res mappings map every single character, meaning (for example) your devtools will always
|
---|
| 10 | * be able to pinpoint the exact location of function calls and so on.
|
---|
| 11 | * With lo-res mappings, devtools may only be able to identify the correct
|
---|
| 12 | * line - but they're quicker to generate and less bulky.
|
---|
| 13 | * You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary
|
---|
| 14 | * instead of per character, suitable for string semantics that are separated by words.
|
---|
| 15 | * If sourcemap locations have been specified with s.addSourceMapLocation(), they will be used here.
|
---|
| 16 | */
|
---|
| 17 | hires?: boolean | 'boundary';
|
---|
| 18 | /**
|
---|
| 19 | * The filename where you plan to write the sourcemap.
|
---|
| 20 | */
|
---|
| 21 | file?: string;
|
---|
| 22 | /**
|
---|
| 23 | * The filename of the file containing the original source.
|
---|
| 24 | */
|
---|
| 25 | source?: string;
|
---|
| 26 | /**
|
---|
| 27 | * Whether to include the original content in the map's sourcesContent array.
|
---|
| 28 | */
|
---|
| 29 | includeContent?: boolean;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | export type SourceMapSegment =
|
---|
| 33 | | [number]
|
---|
| 34 | | [number, number, number, number]
|
---|
| 35 | | [number, number, number, number, number];
|
---|
| 36 |
|
---|
| 37 | export interface DecodedSourceMap {
|
---|
| 38 | file: string;
|
---|
| 39 | sources: string[];
|
---|
| 40 | sourcesContent?: string[];
|
---|
| 41 | names: string[];
|
---|
| 42 | mappings: SourceMapSegment[][];
|
---|
| 43 | x_google_ignoreList?: number[];
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | export class SourceMap {
|
---|
| 47 | constructor(properties: DecodedSourceMap);
|
---|
| 48 |
|
---|
| 49 | version: number;
|
---|
| 50 | file: string;
|
---|
| 51 | sources: string[];
|
---|
| 52 | sourcesContent?: string[];
|
---|
| 53 | names: string[];
|
---|
| 54 | mappings: string;
|
---|
| 55 | x_google_ignoreList?: number[];
|
---|
| 56 | debugId?: string;
|
---|
| 57 |
|
---|
| 58 | /**
|
---|
| 59 | * Returns the equivalent of `JSON.stringify(map)`
|
---|
| 60 | */
|
---|
| 61 | toString(): string;
|
---|
| 62 | /**
|
---|
| 63 | * Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
|
---|
| 64 | * `generateMap(options?: SourceMapOptions): SourceMap;`
|
---|
| 65 | */
|
---|
| 66 | toUrl(): string;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | export class Bundle {
|
---|
| 70 | constructor(options?: BundleOptions);
|
---|
| 71 | /**
|
---|
| 72 | * Adds the specified source to the bundle, which can either be a `MagicString` object directly,
|
---|
| 73 | * or an options object that holds a magic string `content` property and optionally provides
|
---|
| 74 | * a `filename` for the source within the bundle, as well as an optional `ignoreList` hint
|
---|
| 75 | * (which defaults to `false`). The `filename` is used when constructing the source map for the
|
---|
| 76 | * bundle, to identify this `source` in the source map's `sources` field. The `ignoreList` hint
|
---|
| 77 | * is used to populate the `x_google_ignoreList` extension field in the source map, which is a
|
---|
| 78 | * mechanism for tools to signal to debuggers that certain sources should be ignored by default
|
---|
| 79 | * (depending on user preferences).
|
---|
| 80 | */
|
---|
| 81 | addSource(
|
---|
| 82 | source: MagicString | { filename?: string; content: MagicString; ignoreList?: boolean },
|
---|
| 83 | ): this;
|
---|
| 84 | append(str: string, options?: BundleOptions): this;
|
---|
| 85 | clone(): this;
|
---|
| 86 | generateMap(
|
---|
| 87 | options?: SourceMapOptions,
|
---|
| 88 | ): Omit<SourceMap, 'sourcesContent'> & { sourcesContent: Array<string | null> };
|
---|
| 89 | generateDecodedMap(
|
---|
| 90 | options?: SourceMapOptions,
|
---|
| 91 | ): Omit<DecodedSourceMap, 'sourcesContent'> & { sourcesContent: Array<string | null> };
|
---|
| 92 | getIndentString(): string;
|
---|
| 93 | indent(indentStr?: string): this;
|
---|
| 94 | indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
|
---|
| 95 | prepend(str: string): this;
|
---|
| 96 | toString(): string;
|
---|
| 97 | trimLines(): this;
|
---|
| 98 | trim(charType?: string): this;
|
---|
| 99 | trimStart(charType?: string): this;
|
---|
| 100 | trimEnd(charType?: string): this;
|
---|
| 101 | isEmpty(): boolean;
|
---|
| 102 | length(): number;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | export type ExclusionRange = [number, number];
|
---|
| 106 |
|
---|
| 107 | export interface MagicStringOptions {
|
---|
| 108 | filename?: string;
|
---|
| 109 | indentExclusionRanges?: ExclusionRange | Array<ExclusionRange>;
|
---|
| 110 | offset?: number;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | export interface IndentOptions {
|
---|
| 114 | exclude?: ExclusionRange | Array<ExclusionRange>;
|
---|
| 115 | indentStart?: boolean;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | export interface OverwriteOptions {
|
---|
| 119 | storeName?: boolean;
|
---|
| 120 | contentOnly?: boolean;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | export interface UpdateOptions {
|
---|
| 124 | storeName?: boolean;
|
---|
| 125 | overwrite?: boolean;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | export default class MagicString {
|
---|
| 129 | constructor(str: string, options?: MagicStringOptions);
|
---|
| 130 | /**
|
---|
| 131 | * Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
|
---|
| 132 | */
|
---|
| 133 | addSourcemapLocation(char: number): void;
|
---|
| 134 | /**
|
---|
| 135 | * Appends the specified content to the end of the string.
|
---|
| 136 | */
|
---|
| 137 | append(content: string): this;
|
---|
| 138 | /**
|
---|
| 139 | * Appends the specified content at the index in the original string.
|
---|
| 140 | * If a range *ending* with index is subsequently moved, the insert will be moved with it.
|
---|
| 141 | * See also `s.prependLeft(...)`.
|
---|
| 142 | */
|
---|
| 143 | appendLeft(index: number, content: string): this;
|
---|
| 144 | /**
|
---|
| 145 | * Appends the specified content at the index in the original string.
|
---|
| 146 | * If a range *starting* with index is subsequently moved, the insert will be moved with it.
|
---|
| 147 | * See also `s.prependRight(...)`.
|
---|
| 148 | */
|
---|
| 149 | appendRight(index: number, content: string): this;
|
---|
| 150 | /**
|
---|
| 151 | * Does what you'd expect.
|
---|
| 152 | */
|
---|
| 153 | clone(): this;
|
---|
| 154 | /**
|
---|
| 155 | * Generates a version 3 sourcemap.
|
---|
| 156 | */
|
---|
| 157 | generateMap(options?: SourceMapOptions): SourceMap;
|
---|
| 158 | /**
|
---|
| 159 | * Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
|
---|
| 160 | * Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
|
---|
| 161 | */
|
---|
| 162 | generateDecodedMap(options?: SourceMapOptions): DecodedSourceMap;
|
---|
| 163 | getIndentString(): string;
|
---|
| 164 |
|
---|
| 165 | /**
|
---|
| 166 | * Prefixes each line of the string with prefix.
|
---|
| 167 | * If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
|
---|
| 168 | */
|
---|
| 169 | indent(options?: IndentOptions): this;
|
---|
| 170 | /**
|
---|
| 171 | * Prefixes each line of the string with prefix.
|
---|
| 172 | * If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
|
---|
| 173 | *
|
---|
| 174 | * The options argument can have an exclude property, which is an array of [start, end] character ranges.
|
---|
| 175 | * These ranges will be excluded from the indentation - useful for (e.g.) multiline strings.
|
---|
| 176 | */
|
---|
| 177 | indent(indentStr?: string, options?: IndentOptions): this;
|
---|
| 178 | indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
|
---|
| 179 |
|
---|
| 180 | /**
|
---|
| 181 | * Moves the characters from `start` and `end` to `index`.
|
---|
| 182 | */
|
---|
| 183 | move(start: number, end: number, index: number): this;
|
---|
| 184 | /**
|
---|
| 185 | * Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in
|
---|
| 186 | * that range. The same restrictions as `s.remove()` apply.
|
---|
| 187 | *
|
---|
| 188 | * The fourth argument is optional. It can have a storeName property — if true, the original name will be stored
|
---|
| 189 | * for later inclusion in a sourcemap's names array — and a contentOnly property which determines whether only
|
---|
| 190 | * the content is overwritten, or anything that was appended/prepended to the range as well.
|
---|
| 191 | *
|
---|
| 192 | * It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
|
---|
| 193 | */
|
---|
| 194 | overwrite(
|
---|
| 195 | start: number,
|
---|
| 196 | end: number,
|
---|
| 197 | content: string,
|
---|
| 198 | options?: boolean | OverwriteOptions,
|
---|
| 199 | ): this;
|
---|
| 200 | /**
|
---|
| 201 | * Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
|
---|
| 202 | *
|
---|
| 203 | * The fourth argument is optional. It can have a storeName property — if true, the original name will be stored
|
---|
| 204 | * for later inclusion in a sourcemap's names array — and an overwrite property which determines whether only
|
---|
| 205 | * the content is overwritten, or anything that was appended/prepended to the range as well.
|
---|
| 206 | */
|
---|
| 207 | update(start: number, end: number, content: string, options?: boolean | UpdateOptions): this;
|
---|
| 208 | /**
|
---|
| 209 | * Prepends the string with the specified content.
|
---|
| 210 | */
|
---|
| 211 | prepend(content: string): this;
|
---|
| 212 | /**
|
---|
| 213 | * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
|
---|
| 214 | */
|
---|
| 215 | prependLeft(index: number, content: string): this;
|
---|
| 216 | /**
|
---|
| 217 | * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
|
---|
| 218 | */
|
---|
| 219 | prependRight(index: number, content: string): this;
|
---|
| 220 | /**
|
---|
| 221 | * Removes the characters from `start` to `end` (of the original string, **not** the generated string).
|
---|
| 222 | * Removing the same content twice, or making removals that partially overlap, will cause an error.
|
---|
| 223 | */
|
---|
| 224 | remove(start: number, end: number): this;
|
---|
| 225 | /**
|
---|
| 226 | * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
|
---|
| 227 | */
|
---|
| 228 | reset(start: number, end: number): this;
|
---|
| 229 | /**
|
---|
| 230 | * Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
|
---|
| 231 | * Throws error if the indices are for characters that were already removed.
|
---|
| 232 | */
|
---|
| 233 | slice(start: number, end: number): string;
|
---|
| 234 | /**
|
---|
| 235 | * Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
|
---|
| 236 | */
|
---|
| 237 | snip(start: number, end: number): this;
|
---|
| 238 | /**
|
---|
| 239 | * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
|
---|
| 240 | */
|
---|
| 241 | trim(charType?: string): this;
|
---|
| 242 | /**
|
---|
| 243 | * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
|
---|
| 244 | */
|
---|
| 245 | trimStart(charType?: string): this;
|
---|
| 246 | /**
|
---|
| 247 | * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
|
---|
| 248 | */
|
---|
| 249 | trimEnd(charType?: string): this;
|
---|
| 250 | /**
|
---|
| 251 | * Removes empty lines from the start and end.
|
---|
| 252 | */
|
---|
| 253 | trimLines(): this;
|
---|
| 254 | /**
|
---|
| 255 | * String replacement with RegExp or string.
|
---|
| 256 | */
|
---|
| 257 | replace(
|
---|
| 258 | regex: RegExp | string,
|
---|
| 259 | replacement: string | ((substring: string, ...args: any[]) => string),
|
---|
| 260 | ): this;
|
---|
| 261 | /**
|
---|
| 262 | * Same as `s.replace`, but replace all matched strings instead of just one.
|
---|
| 263 | */
|
---|
| 264 | replaceAll(
|
---|
| 265 | regex: RegExp | string,
|
---|
| 266 | replacement: string | ((substring: string, ...args: any[]) => string),
|
---|
| 267 | ): this;
|
---|
| 268 |
|
---|
| 269 | lastChar(): string;
|
---|
| 270 | lastLine(): string;
|
---|
| 271 | /**
|
---|
| 272 | * Returns true if the resulting source is empty (disregarding white space).
|
---|
| 273 | */
|
---|
| 274 | isEmpty(): boolean;
|
---|
| 275 | length(): number;
|
---|
| 276 |
|
---|
| 277 | /**
|
---|
| 278 | * Indicates if the string has been changed.
|
---|
| 279 | */
|
---|
| 280 | hasChanged(): boolean;
|
---|
| 281 |
|
---|
| 282 | original: string;
|
---|
| 283 | /**
|
---|
| 284 | * Returns the generated string.
|
---|
| 285 | */
|
---|
| 286 | toString(): string;
|
---|
| 287 |
|
---|
| 288 | offset: number;
|
---|
| 289 | }
|
---|