Skip to content

Commit 072188f

Browse files
authored
fix(types): improve chainable types (#278)
1 parent 084a785 commit 072188f

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

src/index.d.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ export class Bundle {
7777
* mechanism for tools to signal to debuggers that certain sources should be ignored by default
7878
* (depending on user preferences).
7979
*/
80-
addSource(source: MagicString | { filename?: string, content: MagicString, ignoreList?: boolean }): Bundle;
81-
append(str: string, options?: BundleOptions): Bundle;
82-
clone(): Bundle;
80+
addSource(source: MagicString | { filename?: string, content: MagicString, ignoreList?: boolean }): this;
81+
append(str: string, options?: BundleOptions): this;
82+
clone(): this;
8383
generateMap(options?: SourceMapOptions): Omit<SourceMap, 'sourcesContent'> & { sourcesContent: Array<string | null> };
8484
generateDecodedMap(options?: SourceMapOptions): Omit<DecodedSourceMap, 'sourcesContent'> & { sourcesContent: Array<string | null> };
8585
getIndentString(): string;
86-
indent(indentStr?: string): Bundle;
86+
indent(indentStr?: string): this;
8787
indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
88-
prepend(str: string): Bundle;
88+
prepend(str: string): this;
8989
toString(): string;
90-
trimLines(): Bundle;
91-
trim(charType?: string): Bundle;
92-
trimStart(charType?: string): Bundle;
93-
trimEnd(charType?: string): Bundle;
90+
trimLines(): this;
91+
trim(charType?: string): this;
92+
trimStart(charType?: string): this;
93+
trimEnd(charType?: string): this;
9494
isEmpty(): boolean;
9595
length(): number;
9696
}
@@ -126,23 +126,23 @@ export default class MagicString {
126126
/**
127127
* Appends the specified content to the end of the string.
128128
*/
129-
append(content: string): MagicString;
129+
append(content: string): this;
130130
/**
131131
* Appends the specified content at the index in the original string.
132132
* If a range *ending* with index is subsequently moved, the insert will be moved with it.
133133
* See also `s.prependLeft(...)`.
134134
*/
135-
appendLeft(index: number, content: string): MagicString;
135+
appendLeft(index: number, content: string): this;
136136
/**
137137
* Appends the specified content at the index in the original string.
138138
* If a range *starting* with index is subsequently moved, the insert will be moved with it.
139139
* See also `s.prependRight(...)`.
140140
*/
141-
appendRight(index: number, content: string): MagicString;
141+
appendRight(index: number, content: string): this;
142142
/**
143143
* Does what you'd expect.
144144
*/
145-
clone(): MagicString;
145+
clone(): this;
146146
/**
147147
* Generates a version 3 sourcemap.
148148
*/
@@ -158,21 +158,21 @@ export default class MagicString {
158158
* Prefixes each line of the string with prefix.
159159
* If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
160160
*/
161-
indent(options?: IndentOptions): MagicString;
161+
indent(options?: IndentOptions): this;
162162
/**
163163
* Prefixes each line of the string with prefix.
164164
* If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
165165
*
166166
* The options argument can have an exclude property, which is an array of [start, end] character ranges.
167167
* These ranges will be excluded from the indentation - useful for (e.g.) multiline strings.
168168
*/
169-
indent(indentStr?: string, options?: IndentOptions): MagicString;
169+
indent(indentStr?: string, options?: IndentOptions): this;
170170
indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
171171

172172
/**
173173
* Moves the characters from `start and `end` to `index`.
174174
*/
175-
move(start: number, end: number, index: number): MagicString;
175+
move(start: number, end: number, index: number): this;
176176
/**
177177
* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in
178178
* that range. The same restrictions as `s.remove()` apply.
@@ -183,36 +183,36 @@ export default class MagicString {
183183
*
184184
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
185185
*/
186-
overwrite(start: number, end: number, content: string, options?: boolean | OverwriteOptions): MagicString;
186+
overwrite(start: number, end: number, content: string, options?: boolean | OverwriteOptions): this;
187187
/**
188188
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
189189
*
190190
* The fourth argument is optional. It can have a storeName property — if true, the original name will be stored
191191
* for later inclusion in a sourcemap's names array — and an overwrite property which determines whether only
192192
* the content is overwritten, or anything that was appended/prepended to the range as well.
193193
*/
194-
update(start: number, end: number, content: string, options?: boolean | UpdateOptions): MagicString;
194+
update(start: number, end: number, content: string, options?: boolean | UpdateOptions): this;
195195
/**
196196
* Prepends the string with the specified content.
197197
*/
198-
prepend(content: string): MagicString;
198+
prepend(content: string): this;
199199
/**
200200
* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
201201
*/
202-
prependLeft(index: number, content: string): MagicString;
202+
prependLeft(index: number, content: string): this;
203203
/**
204204
* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
205205
*/
206-
prependRight(index: number, content: string): MagicString;
206+
prependRight(index: number, content: string): this;
207207
/**
208208
* Removes the characters from `start` to `end` (of the original string, **not** the generated string).
209209
* Removing the same content twice, or making removals that partially overlap, will cause an error.
210210
*/
211-
remove(start: number, end: number): MagicString;
211+
remove(start: number, end: number): this;
212212
/**
213213
* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
214214
*/
215-
reset(start: number, end: number): MagicString;
215+
reset(start: number, end: number): this;
216216
/**
217217
* Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
218218
* Throws error if the indices are for characters that were already removed.
@@ -221,31 +221,31 @@ export default class MagicString {
221221
/**
222222
* Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
223223
*/
224-
snip(start: number, end: number): MagicString;
224+
snip(start: number, end: number): this;
225225
/**
226226
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
227227
*/
228-
trim(charType?: string): MagicString;
228+
trim(charType?: string): this;
229229
/**
230230
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
231231
*/
232-
trimStart(charType?: string): MagicString;
232+
trimStart(charType?: string): this;
233233
/**
234234
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
235235
*/
236-
trimEnd(charType?: string): MagicString;
236+
trimEnd(charType?: string): this;
237237
/**
238238
* Removes empty lines from the start and end.
239239
*/
240-
trimLines(): MagicString;
240+
trimLines(): this;
241241
/**
242242
* String replacement with RegExp or string.
243243
*/
244-
replace(regex: RegExp | string, replacement: string | ((substring: string, ...args: any[]) => string)): MagicString;
244+
replace(regex: RegExp | string, replacement: string | ((substring: string, ...args: any[]) => string)): this;
245245
/**
246246
* Same as `s.replace`, but replace all matched strings instead of just one.
247247
*/
248-
replaceAll(regex: RegExp | string, replacement: string | ((substring: string, ...args: any[]) => string)): MagicString;
248+
replaceAll(regex: RegExp | string, replacement: string | ((substring: string, ...args: any[]) => string)): this;
249249

250250
lastChar(): string;
251251
lastLine(): string;

0 commit comments

Comments
 (0)