| 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 | * If sourcemap locations have been specified with s.addSourceMapLocation(), they will be used here.
|
|---|
| 14 | */
|
|---|
| 15 | hires?: boolean;
|
|---|
| 16 | /**
|
|---|
| 17 | * The filename where you plan to write the sourcemap.
|
|---|
| 18 | */
|
|---|
| 19 | file?: string;
|
|---|
| 20 | /**
|
|---|
| 21 | * The filename of the file containing the original source.
|
|---|
| 22 | */
|
|---|
| 23 | source?: string;
|
|---|
| 24 | /**
|
|---|
| 25 | * Whether to include the original content in the map's sourcesContent array.
|
|---|
| 26 | */
|
|---|
| 27 | includeContent?: boolean;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | export type SourceMapSegment =
|
|---|
| 31 | | [number]
|
|---|
| 32 | | [number, number, number, number]
|
|---|
| 33 | | [number, number, number, number, number];
|
|---|
| 34 |
|
|---|
| 35 | export interface DecodedSourceMap {
|
|---|
| 36 | file: string;
|
|---|
| 37 | sources: string[];
|
|---|
| 38 | sourcesContent: string[];
|
|---|
| 39 | names: string[];
|
|---|
| 40 | mappings: SourceMapSegment[][];
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | export class SourceMap {
|
|---|
| 44 | constructor(properties: DecodedSourceMap);
|
|---|
| 45 |
|
|---|
| 46 | version: number;
|
|---|
| 47 | file: string;
|
|---|
| 48 | sources: string[];
|
|---|
| 49 | sourcesContent: string[];
|
|---|
| 50 | names: string[];
|
|---|
| 51 | mappings: string;
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * Returns the equivalent of `JSON.stringify(map)`
|
|---|
| 55 | */
|
|---|
| 56 | toString(): string;
|
|---|
| 57 | /**
|
|---|
| 58 | * Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
|
|---|
| 59 | * `generateMap(options?: SourceMapOptions): SourceMap;`
|
|---|
| 60 | */
|
|---|
| 61 | toUrl(): string;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | export class Bundle {
|
|---|
| 65 | constructor(options?: BundleOptions);
|
|---|
| 66 | addSource(source: MagicString | { filename?: string, content: MagicString }): Bundle;
|
|---|
| 67 | append(str: string, options?: BundleOptions): Bundle;
|
|---|
| 68 | clone(): Bundle;
|
|---|
| 69 | generateMap(options?: SourceMapOptions): SourceMap;
|
|---|
| 70 | generateDecodedMap(options?: SourceMapOptions): DecodedSourceMap;
|
|---|
| 71 | getIndentString(): string;
|
|---|
| 72 | indent(indentStr?: string): Bundle;
|
|---|
| 73 | indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
|
|---|
| 74 | prepend(str: string): Bundle;
|
|---|
| 75 | toString(): string;
|
|---|
| 76 | trimLines(): Bundle;
|
|---|
| 77 | trim(charType?: string): Bundle;
|
|---|
| 78 | trimStart(charType?: string): Bundle;
|
|---|
| 79 | trimEnd(charType?: string): Bundle;
|
|---|
| 80 | isEmpty(): boolean;
|
|---|
| 81 | length(): number;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | export type ExclusionRange = [ number, number ];
|
|---|
| 85 |
|
|---|
| 86 | export interface MagicStringOptions {
|
|---|
| 87 | filename?: string,
|
|---|
| 88 | indentExclusionRanges?: ExclusionRange | Array<ExclusionRange>;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | export interface IndentOptions {
|
|---|
| 92 | exclude?: ExclusionRange | Array<ExclusionRange>;
|
|---|
| 93 | indentStart?: boolean;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | export interface OverwriteOptions {
|
|---|
| 97 | storeName?: boolean;
|
|---|
| 98 | contentOnly?: boolean;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | export default class MagicString {
|
|---|
| 102 | constructor(str: string, options?: MagicStringOptions);
|
|---|
| 103 | /**
|
|---|
| 104 | * Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
|
|---|
| 105 | */
|
|---|
| 106 | addSourcemapLocation(char: number): void;
|
|---|
| 107 | /**
|
|---|
| 108 | * Appends the specified content to the end of the string.
|
|---|
| 109 | */
|
|---|
| 110 | append(content: string): MagicString;
|
|---|
| 111 | /**
|
|---|
| 112 | * Appends the specified content at the index in the original string.
|
|---|
| 113 | * If a range *ending* with index is subsequently moved, the insert will be moved with it.
|
|---|
| 114 | * See also `s.prependLeft(...)`.
|
|---|
| 115 | */
|
|---|
| 116 | appendLeft(index: number, content: string): MagicString;
|
|---|
| 117 | /**
|
|---|
| 118 | * Appends the specified content at the index in the original string.
|
|---|
| 119 | * If a range *starting* with index is subsequently moved, the insert will be moved with it.
|
|---|
| 120 | * See also `s.prependRight(...)`.
|
|---|
| 121 | */
|
|---|
| 122 | appendRight(index: number, content: string): MagicString;
|
|---|
| 123 | /**
|
|---|
| 124 | * Does what you'd expect.
|
|---|
| 125 | */
|
|---|
| 126 | clone(): MagicString;
|
|---|
| 127 | /**
|
|---|
| 128 | * Generates a version 3 sourcemap.
|
|---|
| 129 | */
|
|---|
| 130 | generateMap(options?: SourceMapOptions): SourceMap;
|
|---|
| 131 | /**
|
|---|
| 132 | * Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
|
|---|
| 133 | * Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
|
|---|
| 134 | */
|
|---|
| 135 | generateDecodedMap(options?: SourceMapOptions): DecodedSourceMap;
|
|---|
| 136 | getIndentString(): string;
|
|---|
| 137 |
|
|---|
| 138 | /**
|
|---|
| 139 | * Prefixes each line of the string with prefix.
|
|---|
| 140 | * If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
|
|---|
| 141 | */
|
|---|
| 142 | indent(options?: IndentOptions): MagicString;
|
|---|
| 143 | /**
|
|---|
| 144 | * Prefixes each line of the string with prefix.
|
|---|
| 145 | * If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
|
|---|
| 146 | *
|
|---|
| 147 | * The options argument can have an exclude property, which is an array of [start, end] character ranges.
|
|---|
| 148 | * These ranges will be excluded from the indentation - useful for (e.g.) multiline strings.
|
|---|
| 149 | */
|
|---|
| 150 | indent(indentStr?: string, options?: IndentOptions): MagicString;
|
|---|
| 151 | indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
|
|---|
| 152 |
|
|---|
| 153 | /**
|
|---|
| 154 | * Moves the characters from `start and `end` to `index`.
|
|---|
| 155 | */
|
|---|
| 156 | move(start: number, end: number, index: number): MagicString;
|
|---|
| 157 | /**
|
|---|
| 158 | * Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
|
|---|
| 159 | *
|
|---|
| 160 | * The fourth argument is optional. It can have a storeName property — if true, the original name will be stored
|
|---|
| 161 | * for later inclusion in a sourcemap's names array — and a contentOnly property which determines whether only
|
|---|
| 162 | * the content is overwritten, or anything that was appended/prepended to the range as well.
|
|---|
| 163 | */
|
|---|
| 164 | overwrite(start: number, end: number, content: string, options?: boolean | OverwriteOptions): MagicString;
|
|---|
| 165 | /**
|
|---|
| 166 | * Prepends the string with the specified content.
|
|---|
| 167 | */
|
|---|
| 168 | prepend(content: string): MagicString;
|
|---|
| 169 | /**
|
|---|
| 170 | * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
|
|---|
| 171 | */
|
|---|
| 172 | prependLeft(index: number, content: string): MagicString;
|
|---|
| 173 | /**
|
|---|
| 174 | * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
|
|---|
| 175 | */
|
|---|
| 176 | prependRight(index: number, content: string): MagicString;
|
|---|
| 177 | /**
|
|---|
| 178 | * Removes the characters from `start` to `end` (of the original string, **not** the generated string).
|
|---|
| 179 | * Removing the same content twice, or making removals that partially overlap, will cause an error.
|
|---|
| 180 | */
|
|---|
| 181 | remove(start: number, end: number): MagicString;
|
|---|
| 182 | /**
|
|---|
| 183 | * Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
|
|---|
| 184 | * Throws error if the indices are for characters that were already removed.
|
|---|
| 185 | */
|
|---|
| 186 | slice(start: number, end: number): string;
|
|---|
| 187 | /**
|
|---|
| 188 | * Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
|
|---|
| 189 | */
|
|---|
| 190 | snip(start: number, end: number): MagicString;
|
|---|
| 191 | /**
|
|---|
| 192 | * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
|
|---|
| 193 | */
|
|---|
| 194 | trim(charType?: string): MagicString;
|
|---|
| 195 | /**
|
|---|
| 196 | * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
|
|---|
| 197 | */
|
|---|
| 198 | trimStart(charType?: string): MagicString;
|
|---|
| 199 | /**
|
|---|
| 200 | * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
|
|---|
| 201 | */
|
|---|
| 202 | trimEnd(charType?: string): MagicString;
|
|---|
| 203 | /**
|
|---|
| 204 | * Removes empty lines from the start and end.
|
|---|
| 205 | */
|
|---|
| 206 | trimLines(): MagicString;
|
|---|
| 207 |
|
|---|
| 208 | lastChar(): string;
|
|---|
| 209 | lastLine(): string;
|
|---|
| 210 | /**
|
|---|
| 211 | * Returns true if the resulting source is empty (disregarding white space).
|
|---|
| 212 | */
|
|---|
| 213 | isEmpty(): boolean;
|
|---|
| 214 | length(): number;
|
|---|
| 215 |
|
|---|
| 216 | original: string;
|
|---|
| 217 | /**
|
|---|
| 218 | * Returns the generated string.
|
|---|
| 219 | */
|
|---|
| 220 | toString(): string;
|
|---|
| 221 | }
|
|---|