-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathindex.d.cts
More file actions
3762 lines (3516 loc) · 111 KB
/
Copy pathindex.d.cts
File metadata and controls
3762 lines (3516 loc) · 111 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
type BindingErrorsOr<T> = T | BindingErrors;
type FxHashSet<T> = Set<T>;
type FxHashMap<K, V> = Map<K, V>;
type MaybePromise<T> = T | Promise<T>;
type Nullable<T> = T | null | undefined;
type VoidNullable<T = void> = T | null | undefined | void;
export type BindingStringOrRegex = string | RegExp;
export type BindingResult<T> = { errors: BindingError[]; isBindingErrors: boolean } | T;
export interface CodegenOptions {
/**
* Remove whitespace.
*
* @default true
*/
removeWhitespace?: boolean;
/**
* How to handle legal comments (comments containing `@license`, `@preserve`, or starting with `//!`/`/*!`).
*
* * `"none"` - Do not preserve any legal comments.
* * `"inline"` - Preserve all legal comments inline.
* * `"eof"` - Move all legal comments to the end of the file.
* * `"external"` - Extract legal comments without linking.
* * `{ linked: "path/to/legal.txt" }` - Extract legal comments and add a link comment to the given path.
*
* @default "none" (when minifying)
*/
legalComments?: 'none' | 'inline' | 'eof' | 'external' | { linked: string };
}
export interface CompressOptions {
/**
* Set desired EcmaScript standard version for output.
*
* Set `esnext` to enable all target highering.
*
* Example:
*
* * `'es2015'`
* * `['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11']`
*
* @default 'esnext'
*
* @see [oxc#target](https://oxc.rs/docs/guide/usage/transformer/lowering#target)
*/
target?: string | Array<string>;
/**
* Pass true to discard calls to `console.*`.
*
* @default false
*/
dropConsole?: boolean;
/**
* Remove `debugger;` statements.
*
* @default true
*/
dropDebugger?: boolean;
/**
* Pass `true` to drop unreferenced functions and variables.
*
* Simple direct variable assignments do not count as references unless set to `keep_assign`.
* @default true
*/
unused?: boolean | 'keep_assign';
/** Keep function / class names. */
keepNames?: CompressOptionsKeepNames;
/**
* Join consecutive var, let and const statements.
*
* @default true
*/
joinVars?: boolean;
/**
* Join consecutive simple statements using the comma operator.
*
* `a; b` -> `a, b`
*
* @default true
*/
sequences?: boolean;
/**
* Set of label names to drop from the code.
*
* Labeled statements matching these names will be removed during minification.
*
* @default []
*/
dropLabels?: Array<string>;
/** Limit the maximum number of iterations for debugging purpose. */
maxIterations?: number;
/** Treeshake options. */
treeshake?: TreeShakeOptions;
}
export interface CompressOptionsKeepNames {
/**
* Keep function names so that `Function.prototype.name` is preserved.
*
* This does not guarantee that the `undefined` name is preserved.
*
* @default false
*/
function: boolean;
/**
* Keep class names so that `Class.prototype.name` is preserved.
*
* This does not guarantee that the `undefined` name is preserved.
*
* @default false
*/
class: boolean;
}
export interface LegalCommentsLinked {
/**
* Extract legal comments and write them to the given path, with a link
* comment appended to the generated code.
*/
linked: string;
}
export declare const enum LegalCommentsMode {
/** Do not preserve any legal comments. */
None = 'none',
/** Preserve all legal comments inline. */
Inline = 'inline',
/** Move all legal comments to the end of the file. */
Eof = 'eof',
/** Extract legal comments without linking. */
External = 'external',
}
export interface MangleOptions {
/**
* Pass `true` to mangle names declared in the top level scope.
*
* @default true for modules and commonjs, otherwise false
*/
toplevel?: boolean;
/**
* Preserve `name` property for functions and classes.
*
* @default false
*/
keepNames?: boolean | MangleOptionsKeepNames;
/** Debug mangled names. */
debug?: boolean;
}
export interface MangleOptionsKeepNames {
/**
* Preserve `name` property for functions.
*
* @default false
*/
function: boolean;
/**
* Preserve `name` property for classes.
*
* @default false
*/
class: boolean;
}
/**
* Minify asynchronously.
*
* Note: This function can be slower than `minifySync` due to the overhead of spawning a thread.
*/
export declare function minify(
filename: string,
sourceText: string,
options?: MinifyOptions | undefined | null,
): Promise<MinifyResult>;
export interface MinifyOptions {
/** Use when minifying an ES module. */
module?: boolean;
compress?: boolean | CompressOptions;
mangle?: boolean | MangleOptions;
codegen?: boolean | CodegenOptions;
sourcemap?: boolean;
}
export interface MinifyResult {
code: string;
map?: SourceMap;
errors: Array<OxcError>;
/**
* Legal comments extracted from the source code.
* Only populated when `codegen.legalComments` is `"linked"` or `"external"`.
*/
legalComments: Array<string>;
}
/** Minify synchronously. */
export declare function minifySync(
filename: string,
sourceText: string,
options?: MinifyOptions | undefined | null,
): MinifyResult;
export interface TreeShakeOptions {
/**
* Whether to respect the pure annotations.
*
* Pure annotations are comments that mark an expression as pure.
* For example: @__PURE__ or #__NO_SIDE_EFFECTS__.
*
* @default true
*/
annotations?: boolean;
/**
* Whether to treat this function call as pure.
*
* This function is called for normal function calls, new calls, and
* tagged template calls.
*/
manualPureFunctions?: Array<string>;
/**
* Whether property read accesses have side effects.
*
* @default 'always'
*/
propertyReadSideEffects?: boolean | 'always';
/**
* Whether property write accesses (assignments to member expressions) have side effects.
*
* When false, assignments like `obj.prop = value` are considered side-effect-free
* (assuming the object and value expressions themselves are side-effect-free).
*
* @default true
*/
propertyWriteSideEffects?: boolean;
/**
* Whether accessing a global variable has side effects.
*
* Accessing a non-existing global variable will throw an error.
* Global variable may be a getter that has side effects.
*
* @default true
*/
unknownGlobalSideEffects?: boolean;
/**
* Whether invalid import statements have side effects.
*
* Accessing a non-existing import name will throw an error.
* Also import statements that cannot be resolved will throw an error.
*
* @default true
*/
invalidImportSideEffects?: boolean;
}
export interface Comment {
type: 'Line' | 'Block';
value: string;
start: number;
end: number;
}
export interface ErrorLabel {
message: string | null;
start: number;
end: number;
}
export interface OxcError {
severity: Severity;
message: string;
labels: Array<ErrorLabel>;
helpMessage: string | null;
codeframe: string | null;
}
export declare const enum Severity {
Error = 'Error',
Warning = 'Warning',
Advice = 'Advice',
}
export declare class ParseResult {
get program(): import('@oxc-project/types').Program;
get module(): EcmaScriptModule;
get comments(): Array<Comment>;
get errors(): Array<OxcError>;
}
export interface DynamicImport {
start: number;
end: number;
moduleRequest: Span;
}
export interface EcmaScriptModule {
/**
* Has ESM syntax.
*
* i.e. `import` and `export` statements, and `import.meta`.
*
* Dynamic imports `import('foo')` are ignored since they can be used in non-ESM files.
*/
hasModuleSyntax: boolean;
/** Import statements. */
staticImports: Array<StaticImport>;
/** Export statements. */
staticExports: Array<StaticExport>;
/** Dynamic import expressions. */
dynamicImports: Array<DynamicImport>;
/** Span positions` of `import.meta` */
importMetas: Array<Span>;
}
export interface ExportExportName {
kind: ExportExportNameKind;
name: string | null;
start: number | null;
end: number | null;
}
export declare const enum ExportExportNameKind {
/** `export { name } */
Name = 'Name',
/** `export default expression` */
Default = 'Default',
/** `export * from "mod" */
None = 'None',
}
export interface ExportImportName {
kind: ExportImportNameKind;
name: string | null;
start: number | null;
end: number | null;
}
export declare const enum ExportImportNameKind {
/** `export { name } */
Name = 'Name',
/** `export * as ns from "mod"` */
All = 'All',
/** `export * from "mod"` */
AllButDefault = 'AllButDefault',
/** Does not have a specifier. */
None = 'None',
}
export interface ExportLocalName {
kind: ExportLocalNameKind;
name: string | null;
start: number | null;
end: number | null;
}
export declare const enum ExportLocalNameKind {
/** `export { name } */
Name = 'Name',
/** `export default expression` */
Default = 'Default',
/**
* If the exported value is not locally accessible from within the module.
* `export default function () {}`
*/
None = 'None',
}
export interface ImportName {
kind: ImportNameKind;
name: string | null;
start: number | null;
end: number | null;
}
export declare const enum ImportNameKind {
/** `import { x } from "mod"` */
Name = 'Name',
/** `import * as ns from "mod"` */
NamespaceObject = 'NamespaceObject',
/** `import defaultExport from "mod"` */
Default = 'Default',
}
/**
* Parse JS/TS source asynchronously on a separate thread.
*
* Note that not all of the workload can happen on a separate thread.
* Parsing on Rust side does happen in a separate thread, but deserialization of the AST to JS objects
* has to happen on current thread. This synchronous deserialization work typically outweighs
* the asynchronous parsing by a factor of between 3 and 20.
*
* i.e. the majority of the workload cannot be parallelized by using this method.
*
* Generally `parseSync` is preferable to use as it does not have the overhead of spawning a thread.
* If you need to parallelize parsing multiple files, it is recommended to use worker threads.
*/
export declare function parse(
filename: string,
sourceText: string,
options?: ParserOptions | undefined | null,
): Promise<ParseResult>;
export interface ParserOptions {
/** Treat the source text as `js`, `jsx`, `ts`, `tsx` or `dts`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts';
/** Treat the source text as `script` or `module` code. */
sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined;
/**
* Return an AST which includes TypeScript-related properties, or excludes them.
*
* `'js'` is default for JS / JSX files.
* `'ts'` is default for TS / TSX files.
* The type of the file is determined from `lang` option, or extension of provided `filename`.
*/
astType?: 'js' | 'ts';
/**
* Controls whether the `range` property is included on AST nodes.
* The `range` property is a `[number, number]` which indicates the start/end offsets
* of the node in the file contents.
*
* @default false
*/
range?: boolean;
/**
* Emit `ParenthesizedExpression` and `TSParenthesizedType` in AST.
*
* If this option is true, parenthesized expressions are represented by
* (non-standard) `ParenthesizedExpression` and `TSParenthesizedType` nodes that
* have a single `expression` property containing the expression inside parentheses.
*
* @default true
*/
preserveParens?: boolean;
/**
* Produce semantic errors with an additional AST pass.
* Semantic errors depend on symbols and scopes, where the parser does not construct.
* This adds a small performance overhead.
*
* @default false
*/
showSemanticErrors?: boolean;
}
/**
* Parse JS/TS source synchronously on current thread.
*
* This is generally preferable over `parse` (async) as it does not have the overhead
* of spawning a thread, and the majority of the workload cannot be parallelized anyway
* (see `parse` documentation for details).
*
* If you need to parallelize parsing multiple files, it is recommended to use worker threads
* with `parseSync` rather than using `parse`.
*/
export declare function parseSync(
filename: string,
sourceText: string,
options?: ParserOptions | undefined | null,
): ParseResult;
/** Returns `true` if raw transfer is supported on this platform. */
export declare function rawTransferSupported(): boolean;
export interface Span {
start: number;
end: number;
}
export interface StaticExport {
start: number;
end: number;
entries: Array<StaticExportEntry>;
}
export interface StaticExportEntry {
start: number;
end: number;
moduleRequest: ValueSpan | null;
/** The name under which the desired binding is exported by the module`. */
importName: ExportImportName;
/** The name used to export this binding by this module. */
exportName: ExportExportName;
/** The name that is used to locally access the exported value from within the importing module. */
localName: ExportLocalName;
/**
* Whether the export is a TypeScript `export type`.
*
* Examples:
*
* ```ts
* export type * from 'mod';
* export type * as ns from 'mod';
* export type { foo };
* export { type foo }:
* export type { foo } from 'mod';
* ```
*/
isType: boolean;
}
export interface StaticImport {
/** Start of import statement. */
start: number;
/** End of import statement. */
end: number;
/**
* Import source.
*
* ```js
* import { foo } from "mod";
* // ^^^
* ```
*/
moduleRequest: ValueSpan;
/**
* Import specifiers.
*
* Empty for `import "mod"`.
*/
entries: Array<StaticImportEntry>;
}
export interface StaticImportEntry {
/**
* The name under which the desired binding is exported by the module.
*
* ```js
* import { foo } from "mod";
* // ^^^
* import { foo as bar } from "mod";
* // ^^^
* ```
*/
importName: ImportName;
/**
* The name that is used to locally access the imported value from within the importing module.
* ```js
* import { foo } from "mod";
* // ^^^
* import { foo as bar } from "mod";
* // ^^^
* ```
*/
localName: ValueSpan;
/**
* Whether this binding is for a TypeScript type-only import.
*
* `true` for the following imports:
* ```ts
* import type { foo } from "mod";
* import { type foo } from "mod";
* ```
*/
isType: boolean;
}
export interface ValueSpan {
value: string;
start: number;
end: number;
}
export declare class ResolverFactory {
constructor(options?: NapiResolveOptions | undefined | null);
static default(): ResolverFactory;
/** Clone the resolver using the same underlying cache. */
cloneWithOptions(options: NapiResolveOptions): ResolverFactory;
/**
* Clear the underlying cache.
*
* Warning: The caller must ensure that there're no ongoing resolution operations when calling this method. Otherwise, it may cause those operations to return an incorrect result.
*/
clearCache(): void;
/** Synchronously resolve `specifier` at an absolute path to a `directory`. */
sync(directory: string, request: string): ResolveResult;
/** Asynchronously resolve `specifier` at an absolute path to a `directory`. */
async(directory: string, request: string): Promise<ResolveResult>;
/**
* Synchronously resolve `specifier` at an absolute path to a `file`.
*
* This method automatically discovers tsconfig.json by traversing parent directories.
*/
resolveFileSync(file: string, request: string): ResolveResult;
/**
* Asynchronously resolve `specifier` at an absolute path to a `file`.
*
* This method automatically discovers tsconfig.json by traversing parent directories.
*/
resolveFileAsync(file: string, request: string): Promise<ResolveResult>;
/**
* Synchronously resolve `specifier` for TypeScript declaration files.
*
* `file` is the absolute path to the containing file.
* Uses TypeScript's `moduleResolution: "bundler"` algorithm.
*/
resolveDtsSync(file: string, request: string): ResolveResult;
/**
* Asynchronously resolve `specifier` for TypeScript declaration files.
*
* `file` is the absolute path to the containing file.
* Uses TypeScript's `moduleResolution: "bundler"` algorithm.
*/
resolveDtsAsync(file: string, request: string): Promise<ResolveResult>;
}
/** Node.js builtin module when `Options::builtin_modules` is enabled. */
export interface Builtin {
/**
* Resolved module.
*
* Always prefixed with "node:" in compliance with the ESM specification.
*/
resolved: string;
/**
* Whether the request was prefixed with `node:` or not.
* `fs` -> `false`.
* `node:fs` returns `true`.
*/
isRuntimeModule: boolean;
}
export declare const enum EnforceExtension {
Auto = 0,
Enabled = 1,
Disabled = 2,
}
export declare const enum ModuleType {
Module = 'module',
CommonJs = 'commonjs',
Json = 'json',
Wasm = 'wasm',
Addon = 'addon',
}
/**
* Module Resolution Options
*
* Options are directly ported from [enhanced-resolve](https://github.com/webpack/enhanced-resolve#resolver-options).
*
* See [webpack resolve](https://webpack.js.org/configuration/resolve/) for information and examples
*/
export interface NapiResolveOptions {
/**
* Discover tsconfig automatically or use the specified tsconfig.json path.
*
* Default `None`
*/
tsconfig?: 'auto' | TsconfigOptions;
/**
* Alias for [ResolveOptions::alias] and [ResolveOptions::fallback].
*
* For the second value of the tuple, `None -> AliasValue::Ignore`, Some(String) ->
* AliasValue::Path(String)`
* Create aliases to import or require certain modules more easily.
* A trailing $ can also be added to the given object's keys to signify an exact match.
* Default `{}`
*/
alias?: Record<string, Array<string | undefined | null>>;
/**
* A list of alias fields in description files.
* Specify a field, such as `browser`, to be parsed according to [this specification](https://github.com/defunctzombie/package-browser-field-spec).
* Can be a path to json object such as `["path", "to", "exports"]`.
*
* Default `[]`
*/
aliasFields?: (string | string[])[];
/**
* Condition names for exports field which defines entry points of a package.
* The key order in the exports field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.
*
* Default `[]`
*/
conditionNames?: Array<string>;
/**
* If true, it will not allow extension-less files.
* So by default `require('./foo')` works if `./foo` has a `.js` extension,
* but with this enabled only `require('./foo.js')` will work.
*
* Default to `true` when [ResolveOptions::extensions] contains an empty string.
* Use `Some(false)` to disable the behavior.
* See <https://github.com/webpack/enhanced-resolve/pull/285>
*
* Default None, which is the same as `Some(false)` when the above empty rule is not applied.
*/
enforceExtension?: EnforceExtension;
/**
* A list of exports fields in description files.
* Can be a path to json object such as `["path", "to", "exports"]`.
*
* Default `[["exports"]]`.
*/
exportsFields?: (string | string[])[];
/**
* Fields from `package.json` which are used to provide the internal requests of a package
* (requests starting with # are considered internal).
*
* Can be a path to a JSON object such as `["path", "to", "imports"]`.
*
* Default `[["imports"]]`.
*/
importsFields?: (string | string[])[];
/**
* An object which maps extension to extension aliases.
*
* Default `{}`
*/
extensionAlias?: Record<string, Array<string>>;
/**
* Attempt to resolve these extensions in order.
* If multiple files share the same name but have different extensions,
* will resolve the one with the extension listed first in the array and skip the rest.
*
* Default `[".js", ".json", ".node"]`
*/
extensions?: Array<string>;
/**
* Redirect module requests when normal resolving fails.
*
* Default `{}`
*/
fallback?: Record<string, Array<string | undefined | null>>;
/**
* Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests).
*
* See also webpack configuration [resolve.fullySpecified](https://webpack.js.org/configuration/module/#resolvefullyspecified)
*
* Default `false`
*/
fullySpecified?: boolean;
/**
* A list of main fields in description files
*
* Default `["main"]`.
*/
mainFields?: string | string[];
/**
* The filename to be used while resolving directories.
*
* Default `["index"]`
*/
mainFiles?: Array<string>;
/**
* A list of directories to resolve modules from, can be absolute path or folder name.
*
* Default `["node_modules"]`
*/
modules?: string | string[];
/**
* Resolve to a context instead of a file.
*
* Default `false`
*/
resolveToContext?: boolean;
/**
* Prefer to resolve module requests as relative requests instead of using modules from node_modules directories.
*
* Default `false`
*/
preferRelative?: boolean;
/**
* Prefer to resolve server-relative urls as absolute paths before falling back to resolve in ResolveOptions::roots.
*
* Default `false`
*/
preferAbsolute?: boolean;
/**
* A list of resolve restrictions to restrict the paths that a request can be resolved on.
*
* Default `[]`
*/
restrictions?: Array<Restriction>;
/**
* A list of directories where requests of server-relative URLs (starting with '/') are resolved.
* On non-Windows systems these requests are resolved as an absolute path first.
*
* Default `[]`
*/
roots?: Array<string>;
/**
* Whether to resolve symlinks to their symlinked location.
* When enabled, symlinked resources are resolved to their real path, not their symlinked location.
* Note that this may cause module resolution to fail when using tools that symlink packages (like npm link).
*
* Default `true`
*/
symlinks?: boolean;
/**
* Whether to read the `NODE_PATH` environment variable and append its entries to `modules`.
*
* `NODE_PATH` is a deprecated Node.js feature that is not part of ESM resolution.
* Set this to `false` to disable the behavior.
*
* Default `true`
*/
nodePath?: boolean;
/**
* Whether to parse [module.builtinModules](https://nodejs.org/api/module.html#modulebuiltinmodules) or not.
* For example, "zlib" will throw [crate::ResolveError::Builtin] when set to true.
*
* Default `false`
*/
builtinModules?: boolean;
/**
* Resolve [ResolveResult::moduleType].
*
* Default `false`
*/
moduleType?: boolean;
/**
* Allow `exports` field in `require('../directory')`.
*
* This is not part of the spec but some vite projects rely on this behavior.
* See
* * <https://github.com/vitejs/vite/pull/20252>
* * <https://github.com/nodejs/node/issues/58827>
*
* Default: `false`
*/
allowPackageExportsInDirectoryResolve?: boolean;
}
export interface ResolveResult {
path?: string;
error?: string;
builtin?: Builtin;
/**
* Module type for this path.
*
* Enable with `ResolveOptions#moduleType`.
*
* The module type is computed `ESM_FILE_FORMAT` from the [ESM resolution algorithm specification](https://nodejs.org/docs/latest/api/esm.html#resolution-algorithm-specification).
*
* The algorithm uses the file extension or finds the closest `package.json` with the `type` field.
*/
moduleType?: ModuleType;
/** `package.json` path for the given module. */
packageJsonPath?: string;
}
/**
* Alias Value for [ResolveOptions::alias] and [ResolveOptions::fallback].
* Use struct because napi don't support structured union now
*/
export interface Restriction {
path?: string;
regex?: string;
}
export declare function sync(path: string, request: string): ResolveResult;
/**
* Tsconfig Options
*
* Derived from [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin#options)
*/
export interface TsconfigOptions {
/**
* Allows you to specify where to find the TypeScript configuration file.
* You may provide
* * a relative path to the configuration file. It will be resolved relative to cwd.
* * an absolute path to the configuration file.
*/
configFile: string;
/**
* Support for Typescript Project References.
*
* * `'auto'`: use the `references` field from tsconfig of `config_file`.
*/
references?: 'auto';
}
export interface SourceMap {
file?: string;
mappings: string;
names: Array<string>;
sourceRoot?: string;
sources: Array<string>;
sourcesContent?: Array<string>;
version: number;
x_google_ignoreList?: Array<number>;
}
export interface ArrowFunctionsOptions {
/**
* This option enables the following:
* * Wrap the generated function in .bind(this) and keeps uses of this inside the function as-is, instead of using a renamed this.
* * Add a runtime check to ensure the functions are not instantiated.
* * Add names to arrow functions.
*
* @default false
*/
spec?: boolean;
}
export interface CompilerAssumptions {
ignoreFunctionLength?: boolean;
noDocumentAll?: boolean;
objectRestNoSymbols?: boolean;
pureGetters?: boolean;
/**
* When using public class fields, assume that they don't shadow any getter in the current class,
* in its subclasses or in its superclass. Thus, it's safe to assign them rather than using
* `Object.defineProperty`.
*
* For example:
*
* Input:
* ```js
* class Test {
* field = 2;
*
* static staticField = 3;
* }
* ```
*
* When `set_public_class_fields` is `true`, the output will be:
* ```js
* class Test {
* constructor() {
* this.field = 2;
* }
* }
* Test.staticField = 3;
* ```
*
* Otherwise, the output will be:
* ```js
* import _defineProperty from "@oxc-project/runtime/helpers/defineProperty";
* class Test {
* constructor() {
* _defineProperty(this, "field", 2);
* }
* }
* _defineProperty(Test, "staticField", 3);
* ```
*
* NOTE: For TypeScript, if you wanted behavior is equivalent to `useDefineForClassFields: false`, you should
* set both `set_public_class_fields` and [`crate::TypeScriptOptions::remove_class_fields_without_initializer`]
* to `true`.
*/
setPublicClassFields?: boolean;
}
export interface DecoratorOptions {
/**
* Enables experimental support for decorators, which is a version of decorators that predates the TC39 standardization process.
*
* Decorators are a language feature which hasn’t yet been fully ratified into the JavaScript specification.
* This means that the implementation version in TypeScript may differ from the implementation in JavaScript when it it decided by TC39.
*
* @see https://www.typescriptlang.org/tsconfig/#experimentalDecorators
* @default false
*/
legacy?: boolean;
/**
* Enables emitting decorator metadata.
*
* This option the same as [emitDecoratorMetadata](https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata)
* in TypeScript, and it only works when `legacy` is true.
*
* @see https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata
* @default false
*/
emitDecoratorMetadata?: boolean;
/**
* Aligns nullable-union `design:type` emission with `--strictNullChecks`.
*
* When `true` (default), `T | null` and `T | undefined` emit `Object`, matching tsc strict.
* When `false`, `null` and `undefined` are elided from the union so the underlying
* primitive constructor is emitted, matching tsc with `--strictNullChecks=false`
* and `babel-plugin-transform-typescript-metadata`.
*
* @see https://www.typescriptlang.org/tsconfig/#strictNullChecks
* @default true
*/
strictNullChecks?: boolean;
}
export interface Es2015Options {
/** Transform arrow functions into function expressions. */
arrowFunction?: ArrowFunctionsOptions;
}
export declare const enum HelperMode {
/**
* Runtime mode (default): Helper functions are imported from a runtime package.
*
* Example:
*
* ```js
* import helperName from "@oxc-project/runtime/helpers/helperName";
* helperName(...arguments);
* ```
*/
Runtime = 'Runtime',
/**
* External mode: Helper functions are accessed from a global `babelHelpers` object.
*
* Example:
*
* ```js
* babelHelpers.helperName(...arguments);
* ```
*/
External = 'External',