index.d.ts
25.3 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
// Type definitions for @babel/core 7.1
// Project: https://github.com/babel/babel/tree/master/packages/babel-core, https://babeljs.io
// Definitions by: Troy Gerwien <https://github.com/yortus>
// Marvin Hagemeister <https://github.com/marvinhagemeister>
// Melvin Groenhoff <https://github.com/mgroenhoff>
// Jessica Franco <https://github.com/Jessidhia>
// Ifiok Jr. <https://github.com/ifiokjr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.4
import { GeneratorOptions } from '@babel/generator';
import traverse, { Visitor, NodePath, Hub, Scope } from '@babel/traverse';
import template from '@babel/template';
import * as t from '@babel/types';
import { ParserOptions } from '@babel/parser';
export { ParserOptions, GeneratorOptions, t as types, template, traverse, NodePath, Visitor };
export type Node = t.Node;
export type ParseResult = t.File | t.Program;
export const version: string;
export const DEFAULT_EXTENSIONS: ['.js', '.jsx', '.es6', '.es', '.mjs'];
export interface TransformOptions {
/**
* Include the AST in the returned object
*
* Default: `false`
*/
ast?: boolean | null;
/**
* Attach a comment after all non-user injected code
*
* Default: `null`
*/
auxiliaryCommentAfter?: string | null;
/**
* Attach a comment before all non-user injected code
*
* Default: `null`
*/
auxiliaryCommentBefore?: string | null;
/**
* Specify the "root" folder that defines the location to search for "babel.config.js", and the default folder to allow `.babelrc` files inside of.
*
* Default: `"."`
*/
root?: string | null;
/**
* This option, combined with the "root" value, defines how Babel chooses its project root.
* The different modes define different ways that Babel can process the "root" value to get
* the final project root.
*
* @see https://babeljs.io/docs/en/next/options#rootmode
*/
rootMode?: 'root' | 'upward' | 'upward-optional';
/**
* The config file to load Babel's config from. Defaults to searching for "babel.config.js" inside the "root" folder. `false` will disable searching for config files.
*
* Default: `undefined`
*/
configFile?: string | boolean | null;
/**
* Specify whether or not to use .babelrc and
* .babelignore files.
*
* Default: `true`
*/
babelrc?: boolean | null;
/**
* Specify which packages should be search for .babelrc files when they are being compiled. `true` to always search, or a path string or an array of paths to packages to search
* inside of. Defaults to only searching the "root" package.
*
* Default: `(root)`
*/
babelrcRoots?: boolean | MatchPattern | MatchPattern[] | null;
/**
* Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"`
*
* Default: env vars
*/
envName?: string;
/**
* If any of patterns match, the current configuration object is considered inactive and is ignored during config processing.
*/
exclude?: MatchPattern | MatchPattern[];
/**
* Enable code generation
*
* Default: `true`
*/
code?: boolean | null;
/**
* Output comments in generated output
*
* Default: `true`
*/
comments?: boolean | null;
/**
* Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB
*
* Default: `"auto"`
*/
compact?: boolean | 'auto' | null;
/**
* The working directory that Babel's programmatic options are loaded relative to.
*
* Default: `"."`
*/
cwd?: string | null;
/**
* Utilities may pass a caller object to identify themselves to Babel and
* pass capability-related flags for use by configs, presets and plugins.
*
* @see https://babeljs.io/docs/en/next/options#caller
*/
caller?: TransformCaller;
/**
* This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { \/* specific options *\/ } } }`
* which will use those options when the `envName` is `production`
*
* Default: `{}`
*/
env?: { [index: string]: TransformOptions | null | undefined } | null;
/**
* A path to a `.babelrc` file to extend
*
* Default: `null`
*/
extends?: string | null;
/**
* Filename for use in errors etc
*
* Default: `"unknown"`
*/
filename?: string | null;
/**
* Filename relative to `sourceRoot`
*
* Default: `(filename)`
*/
filenameRelative?: string | null;
/**
* An object containing the options to be passed down to the babel code generator, @babel/generator
*
* Default: `{}`
*/
generatorOpts?: GeneratorOptions | null;
/**
* Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used
*
* Default: `null`
*/
getModuleId?: ((moduleName: string) => string | null | undefined) | null;
/**
* ANSI highlight syntax error code frames
*
* Default: `true`
*/
highlightCode?: boolean | null;
/**
* Opposite to the `only` option. `ignore` is disregarded if `only` is specified
*
* Default: `null`
*/
ignore?: MatchPattern[] | null;
/**
* This option is a synonym for "test"
*/
include?: MatchPattern | MatchPattern[];
/**
* A source map object that the output source map will be based on
*
* Default: `null`
*/
inputSourceMap?: object | null;
/**
* Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe)
*
* Default: `false`
*/
minified?: boolean | null;
/**
* Specify a custom name for module ids
*
* Default: `null`
*/
moduleId?: string | null;
/**
* If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules)
*
* Default: `false`
*/
moduleIds?: boolean | null;
/**
* Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions
*
* Default: `(sourceRoot)`
*/
moduleRoot?: string | null;
/**
* A glob, regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile
* a non-matching file it's returned verbatim
*
* Default: `null`
*/
only?: MatchPattern[] | null;
/**
* Allows users to provide an array of options that will be merged into the current configuration one at a time.
* This feature is best used alongside the "test"/"include"/"exclude" options to provide conditions for which an override should apply
*/
overrides?: TransformOptions[];
/**
* An object containing the options to be passed down to the babel parser, @babel/parser
*
* Default: `{}`
*/
parserOpts?: ParserOptions | null;
/**
* List of plugins to load and use
*
* Default: `[]`
*/
plugins?: PluginItem[] | null;
/**
* List of presets (a set of plugins) to load and use
*
* Default: `[]`
*/
presets?: PluginItem[] | null;
/**
* Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE**: This will not retain the columns)
*
* Default: `false`
*/
retainLines?: boolean | null;
/**
* An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE**: This overrides the `comment` option when used
*
* Default: `null`
*/
shouldPrintComment?: ((commentContents: string) => boolean) | null;
/**
* Set `sources[0]` on returned source map
*
* Default: `(filenameRelative)`
*/
sourceFileName?: string | null;
/**
* If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"`
* then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!**
*
* Default: `false`
*/
sourceMaps?: boolean | 'inline' | 'both' | null;
/**
* The root from which all sources are relative
*
* Default: `(moduleRoot)`
*/
sourceRoot?: string | null;
/**
* Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to guess, based on the presence of ES6
* `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`.
*
* Default: `("module")`
*/
sourceType?: 'script' | 'module' | 'unambiguous' | null;
/**
* If all patterns fail to match, the current configuration object is considered inactive and is ignored during config processing.
*/
test?: MatchPattern | MatchPattern[];
/**
* An optional callback that can be used to wrap visitor methods. **NOTE**: This is useful for things like introspection, and not really needed for implementing anything. Called as
* `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.
*/
wrapPluginVisitorMethod?:
| ((
pluginAlias: string,
visitorType: 'enter' | 'exit',
callback: (path: NodePath, state: any) => void,
) => (path: NodePath, state: any) => void)
| null;
}
export interface TransformCaller {
// the only required property
name: string;
// e.g. set to true by `babel-loader` and false by `babel-jest`
supportsStaticESM?: boolean;
supportsDynamicImport?: boolean;
supportsExportNamespaceFrom?: boolean;
supportsTopLevelAwait?: boolean;
// augment this with a "declare module '@babel/core' { ... }" if you need more keys
}
export type FileResultCallback = (err: Error | null, result: BabelFileResult | null) => any;
export interface MatchPatternContext {
envName: string;
dirname: string;
caller: TransformCaller | undefined;
}
export type MatchPattern = string | RegExp | ((filename: string | undefined, context: MatchPatternContext) => boolean);
/**
* Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
*/
export function transform(code: string, callback: FileResultCallback): void;
/**
* Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
*/
export function transform(code: string, opts: TransformOptions | undefined, callback: FileResultCallback): void;
/**
* Here for backward-compatibility. Ideally use `transformSync` if you want a synchronous API.
*/
export function transform(code: string, opts?: TransformOptions): BabelFileResult | null;
/**
* Transforms the passed in code. Returning an object with the generated code, source map, and AST.
*/
export function transformSync(code: string, opts?: TransformOptions): BabelFileResult | null;
/**
* Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
*/
export function transformAsync(code: string, opts?: TransformOptions): Promise<BabelFileResult | null>;
/**
* Asynchronously transforms the entire contents of a file.
*/
export function transformFile(filename: string, callback: FileResultCallback): void;
/**
* Asynchronously transforms the entire contents of a file.
*/
export function transformFile(filename: string, opts: TransformOptions | undefined, callback: FileResultCallback): void;
/**
* Synchronous version of `babel.transformFile`. Returns the transformed contents of the `filename`.
*/
export function transformFileSync(filename: string, opts?: TransformOptions): BabelFileResult | null;
/**
* Asynchronously transforms the entire contents of a file.
*/
export function transformFileAsync(filename: string, opts?: TransformOptions): Promise<BabelFileResult | null>;
/**
* Given an AST, transform it.
*/
export function transformFromAst(ast: Node, code: string | undefined, callback: FileResultCallback): void;
/**
* Given an AST, transform it.
*/
export function transformFromAst(
ast: Node,
code: string | undefined,
opts: TransformOptions | undefined,
callback: FileResultCallback,
): void;
/**
* Here for backward-compatibility. Ideally use ".transformSync" if you want a synchronous API.
*/
export function transformFromAstSync(ast: Node, code?: string, opts?: TransformOptions): BabelFileResult | null;
/**
* Given an AST, transform it.
*/
export function transformFromAstAsync(
ast: Node,
code?: string,
opts?: TransformOptions,
): Promise<BabelFileResult | null>;
// A babel plugin is a simple function which must return an object matching
// the following interface. Babel will throw if it finds unknown properties.
// The list of allowed plugin keys is here:
// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-core/src/config/option-manager.js#L71
export interface PluginObj<S = PluginPass> {
name?: string;
manipulateOptions?(opts: any, parserOpts: any): void;
pre?(this: S, file: BabelFile): void;
visitor: Visitor<S>;
post?(this: S, file: BabelFile): void;
inherits?: any;
}
export interface BabelFile {
ast: t.File;
opts: TransformOptions;
hub: Hub;
metadata: object;
path: NodePath<t.Program>;
scope: Scope;
inputMap: object | null;
code: string;
}
export interface PluginPass {
file: BabelFile;
key: string;
opts: PluginOptions;
cwd: string;
filename: string;
[key: string]: unknown;
}
export interface BabelFileResult {
ast?: t.File | null;
code?: string | null;
ignored?: boolean;
map?: {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
} | null;
metadata?: BabelFileMetadata;
}
export interface BabelFileMetadata {
usedHelpers: string[];
marked: Array<{
type: string;
message: string;
loc: object;
}>;
modules: BabelFileModulesMetadata;
}
export interface BabelFileModulesMetadata {
imports: object[];
exports: {
exported: object[];
specifiers: object[];
};
}
export type FileParseCallback = (err: Error | null, result: ParseResult | null) => any;
/**
* Given some code, parse it using Babel's standard behavior.
* Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
*/
export function parse(code: string, callback: FileParseCallback): void;
/**
* Given some code, parse it using Babel's standard behavior.
* Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
*/
export function parse(code: string, options: TransformOptions | undefined, callback: FileParseCallback): void;
/**
* Given some code, parse it using Babel's standard behavior.
* Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
*/
export function parse(code: string, options?: TransformOptions): ParseResult | null;
/**
* Given some code, parse it using Babel's standard behavior.
* Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
*/
export function parseSync(code: string, options?: TransformOptions): ParseResult | null;
/**
* Given some code, parse it using Babel's standard behavior.
* Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
*/
export function parseAsync(code: string, options?: TransformOptions): Promise<ParseResult | null>;
/**
* Resolve Babel's options fully, resulting in an options object where:
*
* * opts.plugins is a full list of Plugin instances.
* * opts.presets is empty and all presets are flattened into opts.
* * It can be safely passed back to Babel. Fields like babelrc have been set to false so that later calls to Babel
* will not make a second attempt to load config files.
*
* Plugin instances aren't meant to be manipulated directly, but often callers will serialize this opts to JSON to
* use it as a cache key representing the options Babel has received. Caching on this isn't 100% guaranteed to
* invalidate properly, but it is the best we have at the moment.
*/
export function loadOptions(options?: TransformOptions): object | null;
/**
* To allow systems to easily manipulate and validate a user's config, this function resolves the plugins and
* presets and proceeds no further. The expectation is that callers will take the config's .options, manipulate it
* as then see fit and pass it back to Babel again.
*
* * `babelrc: string | void` - The path of the `.babelrc` file, if there was one.
* * `babelignore: string | void` - The path of the `.babelignore` file, if there was one.
* * `options: ValidatedOptions` - The partially resolved options, which can be manipulated and passed back
* to Babel again.
* * `plugins: Array<ConfigItem>` - See below.
* * `presets: Array<ConfigItem>` - See below.
* * It can be safely passed back to Babel. Fields like `babelrc` have been set to false so that later calls to
* Babel will not make a second attempt to load config files.
*
* `ConfigItem` instances expose properties to introspect the values, but each item should be treated as
* immutable. If changes are desired, the item should be removed from the list and replaced with either a normal
* Babel config value, or with a replacement item created by `babel.createConfigItem`. See that function for
* information about `ConfigItem` fields.
*/
export function loadPartialConfig(options?: TransformOptions): Readonly<PartialConfig> | null;
export interface PartialConfig {
options: TransformOptions;
babelrc?: string;
babelignore?: string;
config?: string;
hasFilesystemConfig: () => boolean;
}
export interface ConfigItem {
/**
* The name that the user gave the plugin instance, e.g. `plugins: [ ['env', {}, 'my-env'] ]`
*/
name?: string;
/**
* The resolved value of the plugin.
*/
value: object | ((...args: any[]) => any);
/**
* The options object passed to the plugin.
*/
options?: object | false;
/**
* The path that the options are relative to.
*/
dirname: string;
/**
* Information about the plugin's file, if Babel knows it.
* *
*/
file?: {
/**
* The file that the user requested, e.g. `"@babel/env"`
*/
request: string;
/**
* The full path of the resolved file, e.g. `"/tmp/node_modules/@babel/preset-env/lib/index.js"`
*/
resolved: string;
} | null;
}
export type PluginOptions = object | undefined | false;
export type PluginTarget = string | object | ((...args: any[]) => any);
export type PluginItem =
| ConfigItem
| PluginObj<any>
| PluginTarget
| [PluginTarget, PluginOptions]
| [PluginTarget, PluginOptions, string | undefined];
export function resolvePlugin(name: string, dirname: string): string | null;
export function resolvePreset(name: string, dirname: string): string | null;
export interface CreateConfigItemOptions {
dirname?: string;
type?: 'preset' | 'plugin';
}
/**
* Allows build tooling to create and cache config items up front. If this function is called multiple times for a
* given plugin, Babel will call the plugin's function itself multiple times. If you have a clear set of expected
* plugins and presets to inject, pre-constructing the config items would be recommended.
*/
export function createConfigItem(
value: PluginTarget | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined],
options?: CreateConfigItemOptions,
): ConfigItem;
// NOTE: the documentation says the ConfigAPI also exposes @babel/core's exports, but it actually doesn't
/**
* @see https://babeljs.io/docs/en/next/config-files#config-function-api
*/
export interface ConfigAPI {
/**
* The version string for the Babel version that is loading the config file.
*
* @see https://babeljs.io/docs/en/next/config-files#apiversion
*/
version: string;
/**
* @see https://babeljs.io/docs/en/next/config-files#apicache
*/
cache: SimpleCacheConfigurator;
/**
* @see https://babeljs.io/docs/en/next/config-files#apienv
*/
env: EnvFunction;
// undocumented; currently hardcoded to return 'false'
// async(): boolean
/**
* This API is used as a way to access the `caller` data that has been passed to Babel.
* Since many instances of Babel may be running in the same process with different `caller` values,
* this API is designed to automatically configure `api.cache`, the same way `api.env()` does.
*
* The `caller` value is available as the first parameter of the callback function.
* It is best used with something like this to toggle configuration behavior
* based on a specific environment:
*
* @example
* function isBabelRegister(caller?: { name: string }) {
* return !!(caller && caller.name === "@babel/register")
* }
* api.caller(isBabelRegister)
*
* @see https://babeljs.io/docs/en/next/config-files#apicallercb
*/
caller<T extends SimpleCacheKey>(callerCallback: (caller: TransformOptions['caller']) => T): T;
/**
* While `api.version` can be useful in general, it's sometimes nice to just declare your version.
* This API exposes a simple way to do that with:
*
* @example
* api.assertVersion(7) // major version only
* api.assertVersion("^7.2")
*
* @see https://babeljs.io/docs/en/next/config-files#apiassertversionrange
*/
assertVersion(versionRange: number | string): boolean;
// NOTE: this is an undocumented reexport from "@babel/parser" but it's missing from its types
// tokTypes: typeof tokTypes
}
/**
* JS configs are great because they can compute a config on the fly,
* but the downside there is that it makes caching harder.
* Babel wants to avoid re-executing the config function every time a file is compiled,
* because then it would also need to re-execute any plugin and preset functions
* referenced in that config.
*
* To avoid this, Babel expects users of config functions to tell it how to manage caching
* within a config file.
*
* @see https://babeljs.io/docs/en/next/config-files#apicache
*/
export interface SimpleCacheConfigurator {
// there is an undocumented call signature that is a shorthand for forever()/never()/using().
// (ever: boolean): void
// <T extends SimpleCacheKey>(callback: CacheCallback<T>): T
/**
* Permacache the computed config and never call the function again.
*/
forever(): void;
/**
* Do not cache this config, and re-execute the function every time.
*/
never(): void;
/**
* Any time the using callback returns a value other than the one that was expected,
* the overall config function will be called again and a new entry will be added to the cache.
*
* @example
* api.cache.using(() => process.env.NODE_ENV)
*/
using<T extends SimpleCacheKey>(callback: SimpleCacheCallback<T>): T;
/**
* Any time the using callback returns a value other than the one that was expected,
* the overall config function will be called again and all entries in the cache will
* be replaced with the result.
*
* @example
* api.cache.invalidate(() => process.env.NODE_ENV)
*/
invalidate<T extends SimpleCacheKey>(callback: SimpleCacheCallback<T>): T;
}
// https://github.com/babel/babel/blob/v7.3.3/packages/babel-core/src/config/caching.js#L231
export type SimpleCacheKey = string | boolean | number | null | undefined;
export type SimpleCacheCallback<T extends SimpleCacheKey> = () => T;
/**
* Since `NODE_ENV` is a fairly common way to toggle behavior, Babel also includes an API function
* meant specifically for that. This API is used as a quick way to check the `"envName"` that Babel
* was loaded with, which takes `NODE_ENV` into account if no other overriding environment is set.
*
* @see https://babeljs.io/docs/en/next/config-files#apienv
*/
export interface EnvFunction {
/**
* @returns the current `envName` string
*/
(): string;
/**
* @returns `true` if the `envName` is `===` any of the given strings
*/
(envName: string | ReadonlyArray<string>): boolean;
// the official documentation is misleading for this one...
// this just passes the callback to `cache.using` but with an additional argument.
// it returns its result instead of necessarily returning a boolean.
<T extends SimpleCacheKey>(envCallback: (envName: NonNullable<TransformOptions['envName']>) => T): T;
}
export type ConfigFunction = (api: ConfigAPI) => TransformOptions;
export as namespace babel;