prettier 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -33,7 +33,7 @@ type ArrayElement<T> = T extends Array<infer E> ? E : never;
33
33
 
34
34
  // A union of the properties of the given object that are arrays.
35
35
  type ArrayProperties<T> = {
36
- [K in keyof T]: NonNullable<T[K]> extends any[] ? K : never;
36
+ [K in keyof T]: NonNullable<T[K]> extends readonly any[] ? K : never;
37
37
  }[keyof T];
38
38
 
39
39
  // A union of the properties of the given array T that can be used to index it.
@@ -72,12 +72,12 @@ type CallCallback<T, U> = (path: AstPath<T>, index: number, value: any) => U;
72
72
  type EachCallback<T> = (
73
73
  path: AstPath<ArrayElement<T>>,
74
74
  index: number,
75
- value: any
75
+ value: any,
76
76
  ) => void;
77
77
  type MapCallback<T, U> = (
78
78
  path: AstPath<ArrayElement<T>>,
79
79
  index: number,
80
- value: any
80
+ value: any,
81
81
  ) => U;
82
82
 
83
83
  // https://github.com/prettier/prettier/blob/next/src/common/ast-path.js
@@ -136,18 +136,18 @@ export class AstPath<T = any> {
136
136
  call<U>(callback: CallCallback<T, U>): U;
137
137
  call<U, P1 extends CallProperties<T>>(
138
138
  callback: CallCallback<IndexValue<T, P1>, U>,
139
- prop1: P1
139
+ prop1: P1,
140
140
  ): U;
141
141
  call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>>(
142
142
  callback: CallCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
143
143
  prop1: P1,
144
- prop2: P2
144
+ prop2: P2,
145
145
  ): U;
146
146
  call<
147
147
  U,
148
148
  P1 extends keyof T,
149
149
  P2 extends CallProperties<T[P1]>,
150
- P3 extends CallProperties<IndexValue<T[P1], P2>>
150
+ P3 extends CallProperties<IndexValue<T[P1], P2>>,
151
151
  >(
152
152
  callback: CallCallback<
153
153
  IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>,
@@ -155,14 +155,14 @@ export class AstPath<T = any> {
155
155
  >,
156
156
  prop1: P1,
157
157
  prop2: P2,
158
- prop3: P3
158
+ prop3: P3,
159
159
  ): U;
160
160
  call<
161
161
  U,
162
162
  P1 extends keyof T,
163
163
  P2 extends CallProperties<T[P1]>,
164
164
  P3 extends CallProperties<IndexValue<T[P1], P2>>,
165
- P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
165
+ P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>,
166
166
  >(
167
167
  callback: CallCallback<
168
168
  IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>,
@@ -171,7 +171,7 @@ export class AstPath<T = any> {
171
171
  prop1: P1,
172
172
  prop2: P2,
173
173
  prop3: P3,
174
- prop4: P4
174
+ prop4: P4,
175
175
  ): U;
176
176
  call<U, P extends PropertyKey>(
177
177
  callback: CallCallback<any, U>,
@@ -185,28 +185,28 @@ export class AstPath<T = any> {
185
185
  each(callback: EachCallback<T>): void;
186
186
  each<P1 extends IterProperties<T>>(
187
187
  callback: EachCallback<IndexValue<T, P1>>,
188
- prop1: P1
188
+ prop1: P1,
189
189
  ): void;
190
190
  each<P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
191
191
  callback: EachCallback<IndexValue<IndexValue<T, P1>, P2>>,
192
192
  prop1: P1,
193
- prop2: P2
193
+ prop2: P2,
194
194
  ): void;
195
195
  each<
196
196
  P1 extends keyof T,
197
197
  P2 extends IterProperties<T[P1]>,
198
- P3 extends IterProperties<IndexValue<T[P1], P2>>
198
+ P3 extends IterProperties<IndexValue<T[P1], P2>>,
199
199
  >(
200
200
  callback: EachCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>>,
201
201
  prop1: P1,
202
202
  prop2: P2,
203
- prop3: P3
203
+ prop3: P3,
204
204
  ): void;
205
205
  each<
206
206
  P1 extends keyof T,
207
207
  P2 extends IterProperties<T[P1]>,
208
208
  P3 extends IterProperties<IndexValue<T[P1], P2>>,
209
- P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
209
+ P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>,
210
210
  >(
211
211
  callback: EachCallback<
212
212
  IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>
@@ -214,7 +214,7 @@ export class AstPath<T = any> {
214
214
  prop1: P1,
215
215
  prop2: P2,
216
216
  prop3: P3,
217
- prop4: P4
217
+ prop4: P4,
218
218
  ): void;
219
219
  each(
220
220
  callback: EachCallback<any[]>,
@@ -228,30 +228,30 @@ export class AstPath<T = any> {
228
228
  map<U>(callback: MapCallback<T, U>): U[];
229
229
  map<U, P1 extends IterProperties<T>>(
230
230
  callback: MapCallback<IndexValue<T, P1>, U>,
231
- prop1: P1
231
+ prop1: P1,
232
232
  ): U[];
233
233
  map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
234
234
  callback: MapCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
235
235
  prop1: P1,
236
- prop2: P2
236
+ prop2: P2,
237
237
  ): U[];
238
238
  map<
239
239
  U,
240
240
  P1 extends keyof T,
241
241
  P2 extends IterProperties<T[P1]>,
242
- P3 extends IterProperties<IndexValue<T[P1], P2>>
242
+ P3 extends IterProperties<IndexValue<T[P1], P2>>,
243
243
  >(
244
244
  callback: MapCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
245
245
  prop1: P1,
246
246
  prop2: P2,
247
- prop3: P3
247
+ prop3: P3,
248
248
  ): U[];
249
249
  map<
250
250
  U,
251
251
  P1 extends keyof T,
252
252
  P2 extends IterProperties<T[P1]>,
253
253
  P3 extends IterProperties<IndexValue<T[P1], P2>>,
254
- P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
254
+ P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>,
255
255
  >(
256
256
  callback: MapCallback<
257
257
  IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>,
@@ -260,7 +260,7 @@ export class AstPath<T = any> {
260
260
  prop1: P1,
261
261
  prop2: P2,
262
262
  prop3: P3,
263
- prop4: P4
263
+ prop4: P4,
264
264
  ): U[];
265
265
  map<U>(
266
266
  callback: MapCallback<any[], U>,
@@ -304,7 +304,7 @@ export type BuiltInParsers = Record<BuiltInParserName, BuiltInParser>;
304
304
 
305
305
  export type CustomParser = (
306
306
  text: string,
307
- options: Options
307
+ options: Options,
308
308
  ) => AST | Promise<AST>;
309
309
 
310
310
  /**
@@ -467,24 +467,27 @@ export interface Printer<T = any> {
467
467
  path: AstPath<T>,
468
468
  options: ParserOptions<T>,
469
469
  print: (path: AstPath<T>) => Doc,
470
- args?: unknown
470
+ args?: unknown,
471
471
  ): Doc;
472
472
  embed?:
473
473
  | ((
474
474
  path: AstPath,
475
- options: Options
475
+ options: Options,
476
476
  ) =>
477
477
  | ((
478
478
  textToDoc: (text: string, options: Options) => Promise<Doc>,
479
479
  print: (
480
- selector?: string | number | Array<string | number> | AstPath
480
+ selector?: string | number | Array<string | number> | AstPath,
481
481
  ) => Doc,
482
482
  path: AstPath,
483
- options: Options
483
+ options: Options,
484
484
  ) => Promise<Doc | undefined> | Doc | undefined)
485
485
  | Doc
486
486
  | null)
487
487
  | undefined;
488
+ preprocess?:
489
+ | ((ast: T, options: ParserOptions<T>) => T | Promise<T>)
490
+ | undefined;
488
491
  insertPragma?: (text: string) => string;
489
492
  /**
490
493
  * @returns `null` if you want to remove this node
@@ -517,7 +520,7 @@ export interface Printer<T = any> {
517
520
  text: string,
518
521
  options: ParserOptions<T>,
519
522
  ast: T,
520
- isLastComment: boolean
523
+ isLastComment: boolean,
521
524
  ) => boolean)
522
525
  | undefined;
523
526
  endOfLine?:
@@ -526,7 +529,7 @@ export interface Printer<T = any> {
526
529
  text: string,
527
530
  options: ParserOptions<T>,
528
531
  ast: T,
529
- isLastComment: boolean
532
+ isLastComment: boolean,
530
533
  ) => boolean)
531
534
  | undefined;
532
535
  remaining?:
@@ -535,11 +538,14 @@ export interface Printer<T = any> {
535
538
  text: string,
536
539
  options: ParserOptions<T>,
537
540
  ast: T,
538
- isLastComment: boolean
541
+ isLastComment: boolean,
539
542
  ) => boolean)
540
543
  | undefined;
541
544
  }
542
545
  | undefined;
546
+ getVisitorKeys?:
547
+ | ((node: T, nonTraversableKeys: Set<string>) => string[])
548
+ | undefined;
543
549
  }
544
550
 
545
551
  export interface CursorOptions extends Options {
@@ -575,7 +581,7 @@ export function check(source: string, options?: Options): Promise<boolean>;
575
581
  */
576
582
  export function formatWithCursor(
577
583
  source: string,
578
- options: CursorOptions
584
+ options: CursorOptions,
579
585
  ): Promise<CursorResult>;
580
586
 
581
587
  export function formatAST(ast: any, options?: Options): Promise<string>;
@@ -616,7 +622,7 @@ export interface ResolveConfigOptions {
616
622
  */
617
623
  export function resolveConfig(
618
624
  filePath: string,
619
- options?: ResolveConfigOptions
625
+ options?: ResolveConfigOptions,
620
626
  ): Promise<Options | null>;
621
627
 
622
628
  /**
@@ -792,7 +798,7 @@ export interface FileInfoResult {
792
798
 
793
799
  export function getFileInfo(
794
800
  filePath: string,
795
- options?: FileInfoOptions
801
+ options?: FileInfoOptions,
796
802
  ): Promise<FileInfoResult>;
797
803
 
798
804
  /**
@@ -820,7 +826,7 @@ export namespace util {
820
826
  function getAlignmentSize(
821
827
  text: string,
822
828
  tabWidth: number,
823
- startIndex?: number | undefined
829
+ startIndex?: number | undefined,
824
830
  ): number;
825
831
 
826
832
  function getIndentSize(value: string, tabWidth: number): number;
@@ -828,83 +834,83 @@ export namespace util {
828
834
  function skipNewline(
829
835
  text: string,
830
836
  startIndex: number | false,
831
- options?: SkipOptions | undefined
837
+ options?: SkipOptions | undefined,
832
838
  ): number | false;
833
839
 
834
840
  function skipInlineComment(
835
841
  text: string,
836
- startIndex: number | false
842
+ startIndex: number | false,
837
843
  ): number | false;
838
844
 
839
845
  function skipTrailingComment(
840
846
  text: string,
841
- startIndex: number | false
847
+ startIndex: number | false,
842
848
  ): number | false;
843
849
 
844
850
  function skipTrailingComment(
845
851
  text: string,
846
- startIndex: number | false
852
+ startIndex: number | false,
847
853
  ): number | false;
848
854
 
849
855
  function hasNewline(
850
856
  text: string,
851
857
  startIndex: number,
852
- options?: SkipOptions | undefined
858
+ options?: SkipOptions | undefined,
853
859
  ): boolean;
854
860
 
855
861
  function hasNewlineInRange(
856
862
  text: string,
857
863
  startIndex: number,
858
- endIndex: number
864
+ endIndex: number,
859
865
  ): boolean;
860
866
 
861
867
  function hasSpaces(
862
868
  text: string,
863
869
  startIndex: number,
864
- options?: SkipOptions | undefined
870
+ options?: SkipOptions | undefined,
865
871
  ): boolean;
866
872
 
867
873
  function getNextNonSpaceNonCommentCharacter(
868
874
  text: string,
869
- startIndex: number
875
+ startIndex: number,
870
876
  ): string;
871
877
 
872
878
  function makeString(
873
879
  rawText: string,
874
880
  enclosingQuote: Quote,
875
- unescapeUnnecessaryEscapes?: boolean | undefined
881
+ unescapeUnnecessaryEscapes?: boolean | undefined,
876
882
  ): string;
877
883
 
878
884
  function skip(
879
- characters: string | RegExp
885
+ characters: string | RegExp,
880
886
  ): (
881
887
  text: string,
882
888
  startIndex: number | false,
883
- options?: SkipOptions
889
+ options?: SkipOptions,
884
890
  ) => number | false;
885
891
 
886
892
  const skipWhitespace: (
887
893
  text: string,
888
894
  startIndex: number | false,
889
- options?: SkipOptions
895
+ options?: SkipOptions,
890
896
  ) => number | false;
891
897
 
892
898
  const skipSpaces: (
893
899
  text: string,
894
900
  startIndex: number | false,
895
- options?: SkipOptions
901
+ options?: SkipOptions,
896
902
  ) => number | false;
897
903
 
898
904
  const skipToLineEnd: (
899
905
  text: string,
900
906
  startIndex: number | false,
901
- options?: SkipOptions
907
+ options?: SkipOptions,
902
908
  ) => number | false;
903
909
 
904
910
  const skipEverythingButNewLine: (
905
911
  text: string,
906
912
  startIndex: number | false,
907
- options?: SkipOptions
913
+ options?: SkipOptions,
908
914
  ) => number | false;
909
915
 
910
916
  function addLeadingComment(node: any, comment: any): void;