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, args?: unknown): 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 | interpreters?: string[] | undefined;
|
540 | }
|
541 |
|
542 | export interface SupportOptionRange {
|
543 | start: number;
|
544 | end: number;
|
545 | step: number;
|
546 | }
|
547 |
|
548 | export type SupportOptionType = 'int' | 'string' | 'boolean' | 'choice' | 'path';
|
549 |
|
550 | export type CoreCategoryType = 'Config' | 'Editor' | 'Format' | 'Other' | 'Output' | 'Global' | 'Special';
|
551 |
|
552 | export interface BaseSupportOption<Type extends SupportOptionType> {
|
553 | readonly name?: string | undefined;
|
554 | since: string;
|
555 | |
556 |
|
557 |
|
558 | category: string;
|
559 | |
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 | type: Type;
|
567 | |
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | deprecated?: true | string | undefined;
|
574 | |
575 |
|
576 |
|
577 |
|
578 | description?: string | undefined;
|
579 | }
|
580 |
|
581 | export interface IntSupportOption extends BaseSupportOption<'int'> {
|
582 | default?: number | undefined;
|
583 | array?: false | undefined;
|
584 | range?: SupportOptionRange | undefined;
|
585 | }
|
586 |
|
587 | export interface IntArraySupportOption extends BaseSupportOption<'int'> {
|
588 | default?: Array<{ value: number[] }> | undefined;
|
589 | array: true;
|
590 | }
|
591 |
|
592 | export interface StringSupportOption extends BaseSupportOption<'string'> {
|
593 | default?: string | undefined;
|
594 | array?: false | undefined;
|
595 | }
|
596 |
|
597 | export interface StringArraySupportOption extends BaseSupportOption<'string'> {
|
598 | default?: Array<{ value: string[] }> | undefined;
|
599 | array: true;
|
600 | }
|
601 |
|
602 | export interface BooleanSupportOption extends BaseSupportOption<'boolean'> {
|
603 | default?: boolean | undefined;
|
604 | array?: false | undefined;
|
605 | description: string;
|
606 | oppositeDescription?: string | undefined;
|
607 | }
|
608 |
|
609 | export interface BooleanArraySupportOption extends BaseSupportOption<'boolean'> {
|
610 | default?: Array<{ value: boolean[] }> | undefined;
|
611 | array: true;
|
612 | }
|
613 |
|
614 | export interface ChoiceSupportOption<Value = any> extends BaseSupportOption<'choice'> {
|
615 | default?: Value | Array<{ since: string; value: Value }> | undefined;
|
616 | description: string;
|
617 | choices: Array<{
|
618 | since?: string | undefined;
|
619 | value: Value;
|
620 | description: string;
|
621 | }>;
|
622 | }
|
623 |
|
624 | export interface PathSupportOption extends BaseSupportOption<'path'> {
|
625 | default?: string | undefined;
|
626 | array?: false | undefined;
|
627 | }
|
628 |
|
629 | export interface PathArraySupportOption extends BaseSupportOption<'path'> {
|
630 | default?: Array<{ value: string[] }> | undefined;
|
631 | array: true;
|
632 | }
|
633 |
|
634 | export type SupportOption =
|
635 | | IntSupportOption
|
636 | | IntArraySupportOption
|
637 | | StringSupportOption
|
638 | | StringArraySupportOption
|
639 | | BooleanSupportOption
|
640 | | BooleanArraySupportOption
|
641 | | ChoiceSupportOption
|
642 | | PathSupportOption
|
643 | | PathArraySupportOption;
|
644 |
|
645 | export interface SupportOptions extends Record<string, SupportOption> {}
|
646 |
|
647 | export interface SupportInfo {
|
648 | languages: SupportLanguage[];
|
649 | options: SupportOption[];
|
650 | }
|
651 |
|
652 | export interface FileInfoOptions {
|
653 | ignorePath?: string | undefined;
|
654 | withNodeModules?: boolean | undefined;
|
655 | plugins?: string[] | undefined;
|
656 | resolveConfig?: boolean | undefined;
|
657 | }
|
658 |
|
659 | export interface FileInfoResult {
|
660 | ignored: boolean;
|
661 | inferredParser: string | null;
|
662 | }
|
663 |
|
664 | export function getFileInfo(filePath: string, options?: FileInfoOptions): Promise<FileInfoResult>;
|
665 |
|
666 | export namespace getFileInfo {
|
667 | function sync(filePath: string, options?: FileInfoOptions): FileInfoResult;
|
668 | }
|
669 |
|
670 |
|
671 |
|
672 |
|
673 | export function getSupportInfo(): SupportInfo;
|
674 |
|
675 |
|
676 |
|
677 |
|
678 | export const version: string;
|
679 |
|
680 |
|
681 | export namespace util {
|
682 | interface SkipOptions {
|
683 | backwards?: boolean | undefined;
|
684 | }
|
685 |
|
686 | type Quote = "'" | '"';
|
687 |
|
688 | function addDanglingComment(node: any, comment: any, marker: any): void;
|
689 | function addLeadingComment(node: any, comment: any): void;
|
690 | function addTrailingComment(node: any, comment: any): void;
|
691 | function getAlignmentSize(value: string, tabWidth: number, startIndex?: number): number;
|
692 | function getIndentSize(value: string, tabWidth: number): number;
|
693 | function getMaxContinuousCount(str: string, target: string): number;
|
694 | function getNextNonSpaceNonCommentCharacterIndex<N>(
|
695 | text: string,
|
696 | node: N,
|
697 | locEnd: (node: N) => number,
|
698 | ): number | false;
|
699 | function getStringWidth(text: string): number;
|
700 | function hasNewline(text: string, index: number, opts?: SkipOptions): boolean;
|
701 | function hasNewlineInRange(text: string, start: number, end: number): boolean;
|
702 | function hasSpaces(text: string, index: number, opts?: SkipOptions): boolean;
|
703 | function isNextLineEmpty<N>(text: string, node: N, locEnd: (node: N) => number): boolean;
|
704 | function isNextLineEmptyAfterIndex(text: string, index: number): boolean;
|
705 | function isPreviousLineEmpty<N>(text: string, node: N, locStart: (node: N) => number): boolean;
|
706 | function makeString(rawContent: string, enclosingQuote: Quote, unescapeUnnecessaryEscapes?: boolean): string;
|
707 | function skip(chars: string | RegExp): (text: string, index: number | false, opts?: SkipOptions) => number | false;
|
708 | function skipEverythingButNewLine(text: string, index: number | false, opts?: SkipOptions): number | false;
|
709 | function skipInlineComment(text: string, index: number | false): number | false;
|
710 | function skipNewline(text: string, index: number | false, opts?: SkipOptions): number | false;
|
711 | function skipSpaces(text: string, index: number | false, opts?: SkipOptions): number | false;
|
712 | function skipToLineEnd(text: string, index: number | false, opts?: SkipOptions): number | false;
|
713 | function skipTrailingComment(text: string, index: number | false): number | false;
|
714 | function skipWhitespace(text: string, index: number | false, opts?: SkipOptions): number | false;
|
715 | }
|
716 |
|
717 |
|
718 | export namespace doc {
|
719 | namespace builders {
|
720 | type DocCommand =
|
721 | | Align
|
722 | | BreakParent
|
723 | | Concat
|
724 | | Cursor
|
725 | | Fill
|
726 | | Group
|
727 | | IfBreak
|
728 | | Indent
|
729 | | IndentIfBreak
|
730 | | Label
|
731 | | Line
|
732 | | LineSuffix
|
733 | | LineSuffixBoundary
|
734 | | Trim;
|
735 | type Doc = string | Doc[] | DocCommand;
|
736 |
|
737 | interface Align {
|
738 | type: 'align';
|
739 | contents: Doc;
|
740 | n: number | string | { type: 'root' };
|
741 | }
|
742 |
|
743 | interface BreakParent {
|
744 | type: 'break-parent';
|
745 | }
|
746 |
|
747 | interface Concat {
|
748 | type: 'concat';
|
749 | parts: Doc[];
|
750 | }
|
751 |
|
752 | interface Cursor {
|
753 | type: 'cursor';
|
754 | placeholder: symbol;
|
755 | }
|
756 |
|
757 | interface Fill {
|
758 | type: 'fill';
|
759 | parts: Doc[];
|
760 | }
|
761 |
|
762 | interface Group {
|
763 | type: 'group';
|
764 | contents: Doc;
|
765 | break: boolean;
|
766 | expandedStates: Doc[];
|
767 | }
|
768 |
|
769 | interface HardlineWithoutBreakParent extends Line {
|
770 | hard: true;
|
771 | }
|
772 |
|
773 | interface IfBreak {
|
774 | type: 'if-break';
|
775 | breakContents: Doc;
|
776 | flatContents: Doc;
|
777 | }
|
778 |
|
779 | interface Indent {
|
780 | type: 'indent';
|
781 | contents: Doc;
|
782 | }
|
783 |
|
784 | interface IndentIfBreak {
|
785 | type: 'indent-if-break';
|
786 | }
|
787 |
|
788 | interface Label {
|
789 | type: 'label';
|
790 | }
|
791 |
|
792 | interface Line {
|
793 | type: 'line';
|
794 | soft?: boolean | undefined;
|
795 | hard?: boolean | undefined;
|
796 | literal?: boolean | undefined;
|
797 | }
|
798 |
|
799 | interface LineSuffix {
|
800 | type: 'line-suffix';
|
801 | contents: Doc;
|
802 | }
|
803 |
|
804 | interface LineSuffixBoundary {
|
805 | type: 'line-suffix-boundary';
|
806 | }
|
807 |
|
808 | interface LiterallineWithoutBreakParent extends Line {
|
809 | hard: true;
|
810 | literal: true;
|
811 | }
|
812 |
|
813 | interface Softline extends Line {
|
814 | soft: true;
|
815 | }
|
816 |
|
817 | interface Trim {
|
818 | type: 'trim';
|
819 | }
|
820 |
|
821 | interface GroupOptions {
|
822 | shouldBreak?: boolean | undefined;
|
823 | id?: symbol | undefined;
|
824 | }
|
825 |
|
826 | function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
|
827 |
|
828 | function align(widthOrString: Align['n'], doc: Doc): Align;
|
829 |
|
830 | const breakParent: BreakParent;
|
831 | |
832 |
|
833 |
|
834 |
|
835 | function concat(docs: Doc[]): Concat;
|
836 |
|
837 | function conditionalGroup(alternatives: Doc[], options?: GroupOptions): Group;
|
838 |
|
839 | function dedent(doc: Doc): Align;
|
840 |
|
841 | function dedentToRoot(doc: Doc): Align;
|
842 |
|
843 | function fill(docs: Doc[]): Fill;
|
844 |
|
845 | function group(doc: Doc, opts?: GroupOptions): Group;
|
846 |
|
847 | const hardline: Concat;
|
848 |
|
849 | const hardlineWithoutBreakParent: HardlineWithoutBreakParent;
|
850 |
|
851 | function ifBreak(ifBreak: Doc, noBreak?: Doc, options?: { groupId?: symbol | undefined }): IfBreak;
|
852 |
|
853 | function indent(doc: Doc): Indent;
|
854 |
|
855 | function indentIfBreak(doc: Doc, opts: { groupId: symbol; negate?: boolean | undefined }): IndentIfBreak;
|
856 |
|
857 | function join(sep: Doc, docs: Doc[]): Concat;
|
858 |
|
859 | function label(label: string, doc: Doc): Label;
|
860 |
|
861 | const line: Line;
|
862 |
|
863 | function lineSuffix(suffix: Doc): LineSuffix;
|
864 |
|
865 | const lineSuffixBoundary: LineSuffixBoundary;
|
866 |
|
867 | const literalline: Concat;
|
868 |
|
869 | const literallineWithoutBreakParent: LiterallineWithoutBreakParent;
|
870 |
|
871 | function markAsRoot(doc: Doc): Align;
|
872 |
|
873 | const softline: Softline;
|
874 |
|
875 | const trim: Trim;
|
876 |
|
877 | const cursor: Cursor;
|
878 | }
|
879 | namespace debug {
|
880 | function printDocToDebug(doc: Doc): string;
|
881 | }
|
882 | namespace printer {
|
883 | function printDocToString(
|
884 | doc: Doc,
|
885 | options: Options,
|
886 | ): {
|
887 | formatted: string;
|
888 | cursorNodeStart?: number | undefined;
|
889 | cursorNodeText?: string | undefined;
|
890 | };
|
891 | interface Options {
|
892 | |
893 |
|
894 |
|
895 |
|
896 | printWidth: number;
|
897 | |
898 |
|
899 |
|
900 |
|
901 | tabWidth: number;
|
902 | |
903 |
|
904 |
|
905 |
|
906 | useTabs: boolean;
|
907 | parentParser?: string | undefined;
|
908 | __embeddedInHtml?: boolean | undefined;
|
909 | }
|
910 | }
|
911 | namespace utils {
|
912 | function cleanDoc(doc: Doc): Doc;
|
913 | function findInDoc<T = Doc>(doc: Doc, callback: (doc: Doc) => T, defaultValue: T): T;
|
914 | function getDocParts(doc: Doc): Doc;
|
915 | function isConcat(doc: Doc): boolean;
|
916 | function isEmpty(doc: Doc): boolean;
|
917 | function isLineNext(doc: Doc): boolean;
|
918 | function mapDoc<T = Doc>(doc: Doc, callback: (doc: Doc) => T): T;
|
919 | function normalizeDoc(doc: Doc): Doc;
|
920 | function normalizeParts(parts: Doc[]): Doc[];
|
921 | function propagateBreaks(doc: Doc): void;
|
922 | function removeLines(doc: Doc): Doc;
|
923 | function replaceNewlinesWithLiterallines(doc: Doc): Doc;
|
924 | function stripTrailingHardline(doc: Doc): Doc;
|
925 | function traverseDoc(
|
926 | doc: Doc,
|
927 | onEnter?: (doc: Doc) => void | boolean,
|
928 | onExit?: (doc: Doc) => void,
|
929 | shouldTraverseConditionalGroups?: boolean,
|
930 | ): void;
|
931 | function willBreak(doc: Doc): boolean;
|
932 | }
|
933 | }
|
934 |
|
\ | No newline at end of file |