1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export {};
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export type LiteralUnion<T extends U, U = string> = T | (Pick<U, never> & { _?: never | undefined });
|
28 |
|
29 | export type AST = any;
|
30 | export type Doc = doc.builders.Doc;
|
31 |
|
32 |
|
33 | type ArrayElement<T> = T extends Array<infer E> ? E : never;
|
34 |
|
35 |
|
36 | type ArrayProperties<T> = { [K in keyof T]: NonNullable<T[K]> extends any[] ? K : never }[keyof T];
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | type IndexProperties<T extends { length: number }> = IsTuple<T> extends true
|
42 | ? Exclude<Partial<T>['length'], T['length']>
|
43 | : number;
|
44 |
|
45 |
|
46 |
|
47 | type IndexValue<T, P> = T extends any[] ? (P extends number ? T[P] : never) : P extends keyof T ? T[P] : never;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | type IsTuple<T> = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple<Remain> : false;
|
54 |
|
55 | type CallProperties<T> = T extends any[] ? IndexProperties<T> : keyof T;
|
56 | type IterProperties<T> = T extends any[] ? IndexProperties<T> : ArrayProperties<T>;
|
57 |
|
58 | type CallCallback<T, U> = (path: AstPath<T>, index: number, value: any) => U;
|
59 | type EachCallback<T> = (path: AstPath<ArrayElement<T>>, index: number, value: any) => void;
|
60 | type MapCallback<T, U> = (path: AstPath<ArrayElement<T>>, index: number, value: any) => U;
|
61 |
|
62 |
|
63 | export class AstPath<T = any> {
|
64 | constructor(value: T);
|
65 | stack: T[];
|
66 | callParent<U>(callback: (path: this) => U, count?: number): U;
|
67 | getName(): PropertyKey | null;
|
68 | getValue(): T;
|
69 | getNode(count?: number): T | null;
|
70 | getParentNode(count?: number): T | null;
|
71 | match(...predicates: Array<(node: any, name: string | null, number: number | null) => boolean>): boolean;
|
72 |
|
73 | // For each of the tree walk functions (call, each, and map) this provides 5
|
74 | // strict type signatures, along with a fallback at the end if you end up
|
75 | // calling more than 5 properties deep. This helps a lot with typing because
|
76 | // for the majority of cases you're calling fewer than 5 properties, so the
|
77 | // tree walk functions have a clearer understanding of what you're doing.
|
78 | //
|
79 | // Note that resolving these types is somewhat complicated, and it wasn't
|
80 | // even supported until TypeScript 4.2 (before it would just say that the
|
81 |
|
82 |
|
83 | call<U>(callback: CallCallback<T, U>): U;
|
84 | call<U, P1 extends CallProperties<T>>(callback: CallCallback<IndexValue<T, P1>, U>, prop1: P1): U;
|
85 | call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>>(
|
86 | callback: CallCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
|
87 | prop1: P1,
|
88 | prop2: P2,
|
89 | ): U;
|
90 | call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>, P3 extends CallProperties<IndexValue<T[P1], P2>>>(
|
91 | callback: CallCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
|
92 | prop1: P1,
|
93 | prop2: P2,
|
94 | prop3: P3,
|
95 | ): U;
|
96 | call<
|
97 | U,
|
98 | P1 extends keyof T,
|
99 | P2 extends CallProperties<T[P1]>,
|
100 | P3 extends CallProperties<IndexValue<T[P1], P2>>,
|
101 | P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
|
102 | >(
|
103 | callback: CallCallback<IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>, U>,
|
104 | prop1: P1,
|
105 | prop2: P2,
|
106 | prop3: P3,
|
107 | prop4: P4,
|
108 | ): U;
|
109 | call<U, P extends PropertyKey>(
|
110 | callback: CallCallback<any, U>,
|
111 | prop1: P,
|
112 | prop2: P,
|
113 | prop3: P,
|
114 | prop4: P,
|
115 | ...props: P[]
|
116 | ): U;
|
117 |
|
118 | each(callback: EachCallback<T>): void;
|
119 | each<P1 extends IterProperties<T>>(callback: EachCallback<IndexValue<T, P1>>, prop1: P1): void;
|
120 | each<P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
|
121 | callback: EachCallback<IndexValue<IndexValue<T, P1>, P2>>,
|
122 | prop1: P1,
|
123 | prop2: P2,
|
124 | ): void;
|
125 | each<P1 extends keyof T, P2 extends IterProperties<T[P1]>, P3 extends IterProperties<IndexValue<T[P1], P2>>>(
|
126 | callback: EachCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>>,
|
127 | prop1: P1,
|
128 | prop2: P2,
|
129 | prop3: P3,
|
130 | ): void;
|
131 | each<
|
132 | P1 extends keyof T,
|
133 | P2 extends IterProperties<T[P1]>,
|
134 | P3 extends IterProperties<IndexValue<T[P1], P2>>,
|
135 | P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
|
136 | >(
|
137 | callback: EachCallback<IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>>,
|
138 | prop1: P1,
|
139 | prop2: P2,
|
140 | prop3: P3,
|
141 | prop4: P4,
|
142 | ): void;
|
143 | each(
|
144 | callback: EachCallback<any[]>,
|
145 | prop1: PropertyKey,
|
146 | prop2: PropertyKey,
|
147 | prop3: PropertyKey,
|
148 | prop4: PropertyKey,
|
149 | ...props: PropertyKey[]
|
150 | ): void;
|
151 |
|
152 | map<U>(callback: MapCallback<T, U>): U[];
|
153 | map<U, P1 extends IterProperties<T>>(callback: MapCallback<IndexValue<T, P1>, U>, prop1: P1): U[];
|
154 | map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
|
155 | callback: MapCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
|
156 | prop1: P1,
|
157 | prop2: P2,
|
158 | ): U[];
|
159 | map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>, P3 extends IterProperties<IndexValue<T[P1], P2>>>(
|
160 | callback: MapCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
|
161 | prop1: P1,
|
162 | prop2: P2,
|
163 | prop3: P3,
|
164 | ): U[];
|
165 | map<
|
166 | U,
|
167 | P1 extends keyof T,
|
168 | P2 extends IterProperties<T[P1]>,
|
169 | P3 extends IterProperties<IndexValue<T[P1], P2>>,
|
170 | P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
|
171 | >(
|
172 | callback: MapCallback<IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>, U>,
|
173 | prop1: P1,
|
174 | prop2: P2,
|
175 | prop3: P3,
|
176 | prop4: P4,
|
177 | ): U[];
|
178 | map<U>(
|
179 | callback: MapCallback<any[], U>,
|
180 | prop1: PropertyKey,
|
181 | prop2: PropertyKey,
|
182 | prop3: PropertyKey,
|
183 | prop4: PropertyKey,
|
184 | ...props: PropertyKey[]
|
185 | ): U[];
|
186 | }
|
187 |
|
188 |
|
189 | export type FastPath<T = any> = AstPath<T>;
|
190 |
|
191 | export type BuiltInParser = (text: string, options?: any) => AST;
|
192 | export type BuiltInParserName =
|
193 | | 'angular'
|
194 | | 'babel-flow'
|
195 | | 'babel-ts'
|
196 | | 'babel'
|
197 | | 'css'
|
198 | | 'espree'
|
199 | | 'flow'
|
200 | | 'glimmer'
|
201 | | 'graphql'
|
202 | | 'html'
|
203 | | 'json-stringify'
|
204 | | 'json'
|
205 | | 'json5'
|
206 | | 'less'
|
207 | | 'lwc'
|
208 | | 'markdown'
|
209 | | 'mdx'
|
210 | | 'meriyah'
|
211 | | 'scss'
|
212 | | 'typescript'
|
213 | | 'vue'
|
214 | | 'yaml';
|
215 | export type BuiltInParsers = Record<BuiltInParserName, BuiltInParser>;
|
216 |
|
217 | export type CustomParser = (text: string, parsers: BuiltInParsers, options: Options) => AST;
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | export interface Config extends Options {
|
223 | overrides?: Array<{
|
224 | files: string | string[];
|
225 | excludeFiles?: string | string[];
|
226 | options?: Options;
|
227 | }>;
|
228 | }
|
229 |
|
230 | export interface Options extends Partial<RequiredOptions> {}
|
231 |
|
232 | export interface RequiredOptions extends doc.printer.Options {
|
233 | |
234 |
|
235 |
|
236 |
|
237 | semi: boolean;
|
238 | |
239 |
|
240 |
|
241 |
|
242 | singleQuote: boolean;
|
243 | |
244 |
|
245 |
|
246 |
|
247 | jsxSingleQuote: boolean;
|
248 | |
249 |
|
250 |
|
251 |
|
252 | trailingComma: 'none' | 'es5' | 'all';
|
253 | |
254 |
|
255 |
|
256 |
|
257 | bracketSpacing: boolean;
|
258 | |
259 |
|
260 |
|
261 |
|
262 |
|
263 | bracketSameLine: boolean;
|
264 | |
265 |
|
266 |
|
267 |
|
268 |
|
269 | jsxBracketSameLine: boolean;
|
270 | |
271 |
|
272 |
|
273 |
|
274 | rangeStart: number;
|
275 | |
276 |
|
277 |
|
278 |
|
279 | rangeEnd: number;
|
280 | |
281 |
|
282 |
|
283 | parser: LiteralUnion<BuiltInParserName> | CustomParser;
|
284 | |
285 |
|
286 |
|
287 | filepath: string;
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 | requirePragma: boolean;
|
294 | |
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | insertPragma: boolean;
|
302 | |
303 |
|
304 |
|
305 |
|
306 |
|
307 | proseWrap: 'always' | 'never' | 'preserve';
|
308 | |
309 |
|
310 |
|
311 |
|
312 | arrowParens: 'avoid' | 'always';
|
313 | |
314 |
|
315 |
|
316 | plugins: Array<string | Plugin>;
|
317 | |
318 |
|
319 |
|
320 | pluginSearchDirs: string[] | false;
|
321 | |
322 |
|
323 |
|
324 |
|
325 | htmlWhitespaceSensitivity: 'css' | 'strict' | 'ignore';
|
326 | |
327 |
|
328 |
|
329 |
|
330 | endOfLine: 'auto' | 'lf' | 'crlf' | 'cr';
|
331 | |
332 |
|
333 |
|
334 |
|
335 | quoteProps: 'as-needed' | 'consistent' | 'preserve';
|
336 | |
337 |
|
338 |
|
339 |
|
340 | vueIndentScriptAndStyle: boolean;
|
341 | |
342 |
|
343 |
|
344 |
|
345 | embeddedLanguageFormatting: 'auto' | 'off';
|
346 | |
347 |
|
348 |
|
349 |
|
350 | singleAttributePerLine: boolean;
|
351 | }
|
352 |
|
353 | export interface ParserOptions<T = any> extends RequiredOptions {
|
354 | locStart: (node: T) => number;
|
355 | locEnd: (node: T) => number;
|
356 | originalText: string;
|
357 | }
|
358 |
|
359 | export interface Plugin<T = any> {
|
360 | languages?: SupportLanguage[] | undefined;
|
361 | parsers?: { [parserName: string]: Parser<T> } | undefined;
|
362 | printers?: { [astFormat: string]: Printer<T> } | undefined;
|
363 | options?: SupportOptions | undefined;
|
364 | defaultOptions?: Partial<RequiredOptions> | undefined;
|
365 | }
|
366 |
|
367 | export interface Parser<T = any> {
|
368 | parse: (text: string, parsers: { [parserName: string]: Parser }, options: ParserOptions<T>) => T;
|
369 | astFormat: string;
|
370 | hasPragma?: ((text: string) => boolean) | undefined;
|
371 | locStart: (node: T) => number;
|
372 | locEnd: (node: T) => number;
|
373 | preprocess?: ((text: string, options: ParserOptions<T>) => string) | undefined;
|
374 | }
|
375 |
|
376 | export interface Printer<T = any> {
|
377 | print(path: AstPath<T>, options: ParserOptions<T>, print: (path: AstPath<T>) => Doc): Doc;
|
378 | embed?:
|
379 | | ((
|
380 | path: AstPath<T>,
|
381 | print: (path: AstPath<T>) => Doc,
|
382 | textToDoc: (text: string, options: Options) => Doc,
|
383 | options: ParserOptions<T>,
|
384 | ) => Doc | null)
|
385 | | undefined;
|
386 | insertPragma?: ((text: string) => string) | undefined;
|
387 | |
388 |
|
389 |
|
390 |
|
391 |
|
392 | massageAstNode?: ((node: any, newNode: any, parent: any) => any) | undefined;
|
393 | hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
|
394 | canAttachComment?: ((node: T) => boolean) | undefined;
|
395 | isBlockComment?: ((node: T) => boolean) | undefined;
|
396 | willPrintOwnComments?: ((path: AstPath<T>) => boolean) | undefined;
|
397 | printComment?: ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc) | undefined;
|
398 | handleComments?:
|
399 | | {
|
400 | ownLine?:
|
401 | | ((
|
402 | commentNode: any,
|
403 | text: string,
|
404 | options: ParserOptions<T>,
|
405 | ast: T,
|
406 | isLastComment: boolean,
|
407 | ) => boolean)
|
408 | | undefined;
|
409 | endOfLine?:
|
410 | | ((
|
411 | commentNode: any,
|
412 | text: string,
|
413 | options: ParserOptions<T>,
|
414 | ast: T,
|
415 | isLastComment: boolean,
|
416 | ) => boolean)
|
417 | | undefined;
|
418 | remaining?:
|
419 | | ((
|
420 | commentNode: any,
|
421 | text: string,
|
422 | options: ParserOptions<T>,
|
423 | ast: T,
|
424 | isLastComment: boolean,
|
425 | ) => boolean)
|
426 | | undefined;
|
427 | }
|
428 | | undefined;
|
429 | }
|
430 |
|
431 | export interface CursorOptions extends Options {
|
432 | |
433 |
|
434 |
|
435 | cursorOffset: number;
|
436 | rangeStart?: never;
|
437 | rangeEnd?: never;
|
438 | }
|
439 |
|
440 | export interface CursorResult {
|
441 | formatted: string;
|
442 | cursorOffset: number;
|
443 | }
|
444 |
|
445 |
|
446 |
|
447 |
|
448 | export function format(source: string, options?: Options): string;
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 | export function check(source: string, options?: Options): boolean;
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | export function formatWithCursor(source: string, options: CursorOptions): CursorResult;
|
463 |
|
464 | export interface ResolveConfigOptions {
|
465 | |
466 |
|
467 |
|
468 | useCache?: boolean | undefined;
|
469 | |
470 |
|
471 |
|
472 | config?: string | undefined;
|
473 | |
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | editorconfig?: boolean | undefined;
|
483 | }
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 | export function resolveConfig(filePath: string, options?: ResolveConfigOptions): Promise<Options | null>;
|
499 | export namespace resolveConfig {
|
500 | function sync(filePath: string, options?: ResolveConfigOptions): Options | null;
|
501 | }
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 | export function resolveConfigFile(filePath?: string): Promise<string | null>;
|
515 | export namespace resolveConfigFile {
|
516 | function sync(filePath?: string): string | null;
|
517 | }
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 | export function clearConfigCache(): void;
|
524 |
|
525 | export interface SupportLanguage {
|
526 | name: string;
|
527 | since?: string | undefined;
|
528 | parsers: BuiltInParserName[] | string[];
|
529 | group?: string | undefined;
|
530 | tmScope?: string | undefined;
|
531 | aceMode?: string | undefined;
|
532 | codemirrorMode?: string | undefined;
|
533 | codemirrorMimeType?: string | undefined;
|
534 | aliases?: string[] | undefined;
|
535 | extensions?: string[] | undefined;
|
536 | filenames?: string[] | undefined;
|
537 | linguistLanguageId?: number | undefined;
|
538 | vscodeLanguageIds?: string[] | undefined;
|
539 | }
|
540 |
|
541 | export interface SupportOptionRange {
|
542 | start: number;
|
543 | end: number;
|
544 | step: number;
|
545 | }
|
546 |
|
547 | export type SupportOptionType = 'int' | 'boolean' | 'choice' | 'path';
|
548 |
|
549 | export type CoreCategoryType = 'Config' | 'Editor' | 'Format' | 'Other' | 'Output' | 'Global' | 'Special';
|
550 |
|
551 | export interface BaseSupportOption<Type extends SupportOptionType> {
|
552 | readonly name?: string | undefined;
|
553 | since: string;
|
554 | |
555 |
|
556 |
|
557 | category: string;
|
558 | |
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 | type: Type;
|
566 | |
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 | deprecated?: true | string | undefined;
|
573 | |
574 |
|
575 |
|
576 |
|
577 | description?: string | undefined;
|
578 | }
|
579 |
|
580 | export interface IntSupportOption extends BaseSupportOption<'int'> {
|
581 | default?: number | undefined;
|
582 | array?: false | undefined;
|
583 | range?: SupportOptionRange | undefined;
|
584 | }
|
585 |
|
586 | export interface IntArraySupportOption extends BaseSupportOption<'int'> {
|
587 | default?: Array<{ value: number[] }> | undefined;
|
588 | array: true;
|
589 | }
|
590 |
|
591 | export interface BooleanSupportOption extends BaseSupportOption<'boolean'> {
|
592 | default?: boolean | undefined;
|
593 | array?: false | undefined;
|
594 | description: string;
|
595 | oppositeDescription?: string | undefined;
|
596 | }
|
597 |
|
598 | export interface BooleanArraySupportOption extends BaseSupportOption<'boolean'> {
|
599 | default?: Array<{ value: boolean[] }> | undefined;
|
600 | array: true;
|
601 | }
|
602 |
|
603 | export interface ChoiceSupportOption<Value = any> extends BaseSupportOption<'choice'> {
|
604 | default?: Value | Array<{ since: string; value: Value }> | undefined;
|
605 | description: string;
|
606 | choices: Array<{
|
607 | since?: string | undefined;
|
608 | value: Value;
|
609 | description: string;
|
610 | }>;
|
611 | }
|
612 |
|
613 | export interface PathSupportOption extends BaseSupportOption<'path'> {
|
614 | default?: string | undefined;
|
615 | array?: false | undefined;
|
616 | }
|
617 |
|
618 | export interface PathArraySupportOption extends BaseSupportOption<'path'> {
|
619 | default?: Array<{ value: string[] }> | undefined;
|
620 | array: true;
|
621 | }
|
622 |
|
623 | export type SupportOption =
|
624 | | IntSupportOption
|
625 | | IntArraySupportOption
|
626 | | BooleanSupportOption
|
627 | | BooleanArraySupportOption
|
628 | | ChoiceSupportOption
|
629 | | PathSupportOption
|
630 | | PathArraySupportOption;
|
631 |
|
632 | export interface SupportOptions extends Record<string, SupportOption> {}
|
633 |
|
634 | export interface SupportInfo {
|
635 | languages: SupportLanguage[];
|
636 | options: SupportOption[];
|
637 | }
|
638 |
|
639 | export interface FileInfoOptions {
|
640 | ignorePath?: string | undefined;
|
641 | withNodeModules?: boolean | undefined;
|
642 | plugins?: string[] | undefined;
|
643 | resolveConfig?: boolean | undefined;
|
644 | }
|
645 |
|
646 | export interface FileInfoResult {
|
647 | ignored: boolean;
|
648 | inferredParser: string | null;
|
649 | }
|
650 |
|
651 | export function getFileInfo(filePath: string, options?: FileInfoOptions): Promise<FileInfoResult>;
|
652 |
|
653 | export namespace getFileInfo {
|
654 | function sync(filePath: string, options?: FileInfoOptions): FileInfoResult;
|
655 | }
|
656 |
|
657 |
|
658 |
|
659 |
|
660 | export function getSupportInfo(): SupportInfo;
|
661 |
|
662 |
|
663 |
|
664 |
|
665 | export const version: string;
|
666 |
|
667 |
|
668 | export namespace util {
|
669 | interface SkipOptions {
|
670 | backwards?: boolean | undefined;
|
671 | }
|
672 |
|
673 | type Quote = "'" | '"';
|
674 |
|
675 | function addDanglingComment(node: any, comment: any, marker: any): void;
|
676 | function addLeadingComment(node: any, comment: any): void;
|
677 | function addTrailingComment(node: any, comment: any): void;
|
678 | function getAlignmentSize(value: string, tabWidth: number, startIndex?: number): number;
|
679 | function getIndentSize(value: string, tabWidth: number): number;
|
680 | function getMaxContinuousCount(str: string, target: string): number;
|
681 | function getNextNonSpaceNonCommentCharacterIndex<N>(
|
682 | text: string,
|
683 | node: N,
|
684 | locEnd: (node: N) => number,
|
685 | ): number | false;
|
686 | function getStringWidth(text: string): number;
|
687 | function hasNewline(text: string, index: number, opts?: SkipOptions): boolean;
|
688 | function hasNewlineInRange(text: string, start: number, end: number): boolean;
|
689 | function hasSpaces(text: string, index: number, opts?: SkipOptions): boolean;
|
690 | function isNextLineEmpty<N>(text: string, node: N, locEnd: (node: N) => number): boolean;
|
691 | function isNextLineEmptyAfterIndex(text: string, index: number): boolean;
|
692 | function isPreviousLineEmpty<N>(text: string, node: N, locStart: (node: N) => number): boolean;
|
693 | function makeString(rawContent: string, enclosingQuote: Quote, unescapeUnnecessaryEscapes?: boolean): string;
|
694 | function skip(chars: string | RegExp): (text: string, index: number | false, opts?: SkipOptions) => number | false;
|
695 | function skipEverythingButNewLine(text: string, index: number | false, opts?: SkipOptions): number | false;
|
696 | function skipInlineComment(text: string, index: number | false): number | false;
|
697 | function skipNewline(text: string, index: number | false, opts?: SkipOptions): number | false;
|
698 | function skipSpaces(text: string, index: number | false, opts?: SkipOptions): number | false;
|
699 | function skipToLineEnd(text: string, index: number | false, opts?: SkipOptions): number | false;
|
700 | function skipTrailingComment(text: string, index: number | false): number | false;
|
701 | function skipWhitespace(text: string, index: number | false, opts?: SkipOptions): number | false;
|
702 | }
|
703 |
|
704 |
|
705 | export namespace doc {
|
706 | namespace builders {
|
707 | type DocCommand =
|
708 | | Align
|
709 | | BreakParent
|
710 | | Concat
|
711 | | Cursor
|
712 | | Fill
|
713 | | Group
|
714 | | IfBreak
|
715 | | Indent
|
716 | | IndentIfBreak
|
717 | | Label
|
718 | | Line
|
719 | | LineSuffix
|
720 | | LineSuffixBoundary
|
721 | | Trim;
|
722 | type Doc = string | Doc[] | DocCommand;
|
723 |
|
724 | interface Align {
|
725 | type: 'align';
|
726 | contents: Doc;
|
727 | n: number | string | { type: 'root' };
|
728 | }
|
729 |
|
730 | interface BreakParent {
|
731 | type: 'break-parent';
|
732 | }
|
733 |
|
734 | interface Concat {
|
735 | type: 'concat';
|
736 | parts: Doc[];
|
737 | }
|
738 |
|
739 | interface Cursor {
|
740 | type: 'cursor';
|
741 | placeholder: symbol;
|
742 | }
|
743 |
|
744 | interface Fill {
|
745 | type: 'fill';
|
746 | parts: Doc[];
|
747 | }
|
748 |
|
749 | interface Group {
|
750 | type: 'group';
|
751 | contents: Doc;
|
752 | break: boolean;
|
753 | expandedStates: Doc[];
|
754 | }
|
755 |
|
756 | interface HardlineWithoutBreakParent extends Line {
|
757 | hard: true;
|
758 | }
|
759 |
|
760 | interface IfBreak {
|
761 | type: 'if-break';
|
762 | breakContents: Doc;
|
763 | flatContents: Doc;
|
764 | }
|
765 |
|
766 | interface Indent {
|
767 | type: 'indent';
|
768 | contents: Doc;
|
769 | }
|
770 |
|
771 | interface IndentIfBreak {
|
772 | type: 'indent-if-break';
|
773 | }
|
774 |
|
775 | interface Label {
|
776 | type: 'label';
|
777 | }
|
778 |
|
779 | interface Line {
|
780 | type: 'line';
|
781 | soft?: boolean | undefined;
|
782 | hard?: boolean | undefined;
|
783 | literal?: boolean | undefined;
|
784 | }
|
785 |
|
786 | interface LineSuffix {
|
787 | type: 'line-suffix';
|
788 | contents: Doc;
|
789 | }
|
790 |
|
791 | interface LineSuffixBoundary {
|
792 | type: 'line-suffix-boundary';
|
793 | }
|
794 |
|
795 | interface LiterallineWithoutBreakParent extends Line {
|
796 | hard: true;
|
797 | literal: true;
|
798 | }
|
799 |
|
800 | interface Softline extends Line {
|
801 | soft: true;
|
802 | }
|
803 |
|
804 | interface Trim {
|
805 | type: 'trim';
|
806 | }
|
807 |
|
808 | interface GroupOptions {
|
809 | shouldBreak?: boolean | undefined;
|
810 | id?: symbol | undefined;
|
811 | }
|
812 |
|
813 | function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
|
814 |
|
815 | function align(widthOrString: Align['n'], doc: Doc): Align;
|
816 |
|
817 | const breakParent: BreakParent;
|
818 | |
819 |
|
820 |
|
821 |
|
822 | function concat(docs: Doc[]): Concat;
|
823 |
|
824 | function conditionalGroup(alternatives: Doc[], options?: GroupOptions): Group;
|
825 |
|
826 | function dedent(doc: Doc): Align;
|
827 |
|
828 | function dedentToRoot(doc: Doc): Align;
|
829 |
|
830 | function fill(docs: Doc[]): Fill;
|
831 |
|
832 | function group(doc: Doc, opts?: GroupOptions): Group;
|
833 |
|
834 | const hardline: Concat;
|
835 |
|
836 | const hardlineWithoutBreakParent: HardlineWithoutBreakParent;
|
837 |
|
838 | function ifBreak(ifBreak: Doc, noBreak?: Doc, options?: { groupId?: symbol | undefined }): IfBreak;
|
839 |
|
840 | function indent(doc: Doc): Indent;
|
841 |
|
842 | function indentIfBreak(doc: Doc, opts: { groupId: symbol; negate?: boolean | undefined }): IndentIfBreak;
|
843 |
|
844 | function join(sep: Doc, docs: Doc[]): Concat;
|
845 |
|
846 | function label(label: string, doc: Doc): Label;
|
847 |
|
848 | const line: Line;
|
849 |
|
850 | function lineSuffix(suffix: Doc): LineSuffix;
|
851 |
|
852 | const lineSuffixBoundary: LineSuffixBoundary;
|
853 |
|
854 | const literalline: Concat;
|
855 |
|
856 | const literallineWithoutBreakParent: LiterallineWithoutBreakParent;
|
857 |
|
858 | function markAsRoot(doc: Doc): Align;
|
859 |
|
860 | const softline: Softline;
|
861 |
|
862 | const trim: Trim;
|
863 |
|
864 | const cursor: Cursor;
|
865 | }
|
866 | namespace debug {
|
867 | function printDocToDebug(doc: Doc): string;
|
868 | }
|
869 | namespace printer {
|
870 | function printDocToString(
|
871 | doc: Doc,
|
872 | options: Options,
|
873 | ): {
|
874 | formatted: string;
|
875 | cursorNodeStart?: number | undefined;
|
876 | cursorNodeText?: string | undefined;
|
877 | };
|
878 | interface Options {
|
879 | |
880 |
|
881 |
|
882 |
|
883 | printWidth: number;
|
884 | |
885 |
|
886 |
|
887 |
|
888 | tabWidth: number;
|
889 | |
890 |
|
891 |
|
892 |
|
893 | useTabs: boolean;
|
894 | parentParser?: string | undefined;
|
895 | __embeddedInHtml?: boolean | undefined;
|
896 | }
|
897 | }
|
898 | namespace utils {
|
899 | function cleanDoc(doc: Doc): Doc;
|
900 | function findInDoc<T = Doc>(doc: Doc, callback: (doc: Doc) => T, defaultValue: T): T;
|
901 | function getDocParts(doc: Doc): Doc;
|
902 | function isConcat(doc: Doc): boolean;
|
903 | function isEmpty(doc: Doc): boolean;
|
904 | function isLineNext(doc: Doc): boolean;
|
905 | function mapDoc<T = Doc>(doc: Doc, callback: (doc: Doc) => T): T;
|
906 | function normalizeDoc(doc: Doc): Doc;
|
907 | function normalizeParts(parts: Doc[]): Doc[];
|
908 | function propagateBreaks(doc: Doc): void;
|
909 | function removeLines(doc: Doc): Doc;
|
910 | function replaceNewlinesWithLiterallines(doc: Doc): Doc;
|
911 | function stripTrailingHardline(doc: Doc): Doc;
|
912 | function traverseDoc(
|
913 | doc: Doc,
|
914 | onEnter?: (doc: Doc) => void | boolean,
|
915 | onExit?: (doc: Doc) => void,
|
916 | shouldTraverseConditionalGroups?: boolean,
|
917 | ): void;
|
918 | function willBreak(doc: Doc): boolean;
|
919 | }
|
920 | }
|
921 |
|
\ | No newline at end of file |