1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | import { GeneratorOptions } from '@babel/generator';
|
12 | import { ParserOptions } from '@babel/parser';
|
13 | import template from '@babel/template';
|
14 | import traverse, { Hub, NodePath, Scope, Visitor } from '@babel/traverse';
|
15 | import * as t from '@babel/types';
|
16 |
|
17 | export { ParserOptions, GeneratorOptions, t as types, template, traverse, NodePath, Visitor };
|
18 |
|
19 | export type Node = t.Node;
|
20 | export type ParseResult = t.File | t.Program;
|
21 | export const version: string;
|
22 | export const DEFAULT_EXTENSIONS: ['.js', '.jsx', '.es6', '.es', '.mjs'];
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | interface InputSourceMap {
|
30 | version: number;
|
31 | sources: string[];
|
32 | names: string[];
|
33 | sourceRoot?: string;
|
34 | sourcesContent?: string[];
|
35 | mappings: string;
|
36 | file: string;
|
37 | }
|
38 |
|
39 | export interface TransformOptions {
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | ast?: boolean | null;
|
46 |
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 | auxiliaryCommentAfter?: string | null;
|
53 |
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | auxiliaryCommentBefore?: string | null;
|
60 |
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 | root?: string | null;
|
67 |
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | rootMode?: 'root' | 'upward' | 'upward-optional';
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 | configFile?: string | boolean | null;
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | babelrc?: boolean | null;
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | babelrcRoots?: boolean | MatchPattern | MatchPattern[] | null;
|
99 |
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 | envName?: string;
|
106 |
|
107 | |
108 |
|
109 |
|
110 | exclude?: MatchPattern | MatchPattern[];
|
111 |
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | code?: boolean | null;
|
118 |
|
119 | |
120 |
|
121 |
|
122 |
|
123 |
|
124 | comments?: boolean | null;
|
125 |
|
126 | |
127 |
|
128 |
|
129 |
|
130 |
|
131 | compact?: boolean | 'auto' | null;
|
132 |
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 | cwd?: string | null;
|
139 |
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | caller?: TransformCaller;
|
147 |
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | env?: { [index: string]: TransformOptions | null | undefined } | null;
|
155 |
|
156 | |
157 |
|
158 |
|
159 |
|
160 |
|
161 | extends?: string | null;
|
162 |
|
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 | filename?: string | null;
|
169 |
|
170 | |
171 |
|
172 |
|
173 |
|
174 |
|
175 | filenameRelative?: string | null;
|
176 |
|
177 | |
178 |
|
179 |
|
180 |
|
181 |
|
182 | generatorOpts?: GeneratorOptions | null;
|
183 |
|
184 | |
185 |
|
186 |
|
187 |
|
188 |
|
189 | getModuleId?: ((moduleName: string) => string | null | undefined) | null;
|
190 |
|
191 | /**
|
192 | * ANSI highlight syntax error code frames
|
193 | *
|
194 | * Default: `true`
|
195 | */
|
196 | highlightCode?: boolean | null;
|
197 |
|
198 | /**
|
199 | * Opposite to the `only` option. `ignore` is disregarded if `only` is specified
|
200 | *
|
201 | * Default: `null`
|
202 | */
|
203 | ignore?: MatchPattern[] | null;
|
204 |
|
205 | /**
|
206 | * This option is a synonym for "test"
|
207 | */
|
208 | include?: MatchPattern | MatchPattern[];
|
209 |
|
210 | /**
|
211 | * A source map object that the output source map will be based on
|
212 | *
|
213 | * Default: `null`
|
214 | */
|
215 | inputSourceMap?: InputSourceMap | null;
|
216 |
|
217 | /**
|
218 | * Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe)
|
219 | *
|
220 | * Default: `false`
|
221 | */
|
222 | minified?: boolean | null;
|
223 |
|
224 | /**
|
225 | * Specify a custom name for module ids
|
226 | *
|
227 | * Default: `null`
|
228 | */
|
229 | moduleId?: string | null;
|
230 |
|
231 | /**
|
232 | * If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules)
|
233 | *
|
234 | * Default: `false`
|
235 | */
|
236 | moduleIds?: boolean | null;
|
237 |
|
238 | /**
|
239 | * Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions
|
240 | *
|
241 | * Default: `(sourceRoot)`
|
242 | */
|
243 | moduleRoot?: string | null;
|
244 |
|
245 | /**
|
246 | * 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
|
247 | * a non-matching file it's returned verbatim
|
248 | *
|
249 | * Default: `null`
|
250 | */
|
251 | only?: MatchPattern[] | null;
|
252 |
|
253 | /**
|
254 | * Allows users to provide an array of options that will be merged into the current configuration one at a time.
|
255 | * This feature is best used alongside the "test"/"include"/"exclude" options to provide conditions for which an override should apply
|
256 | */
|
257 | overrides?: TransformOptions[];
|
258 |
|
259 | /**
|
260 | * An object containing the options to be passed down to the babel parser, @babel/parser
|
261 | *
|
262 | * Default: `{}`
|
263 | */
|
264 | parserOpts?: ParserOptions | null;
|
265 |
|
266 | /**
|
267 | * List of plugins to load and use
|
268 | *
|
269 | * Default: `[]`
|
270 | */
|
271 | plugins?: PluginItem[] | null;
|
272 |
|
273 | /**
|
274 | * List of presets (a set of plugins) to load and use
|
275 | *
|
276 | * Default: `[]`
|
277 | */
|
278 | presets?: PluginItem[] | null;
|
279 |
|
280 | /**
|
281 | * 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)
|
282 | *
|
283 | * Default: `false`
|
284 | */
|
285 | retainLines?: boolean | null;
|
286 |
|
287 | /**
|
288 | * 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
|
289 | *
|
290 | * Default: `null`
|
291 | */
|
292 | shouldPrintComment?: ((commentContents: string) => boolean) | null;
|
293 |
|
294 | /**
|
295 | * Set `sources[0]` on returned source map
|
296 | *
|
297 | * Default: `(filenameRelative)`
|
298 | */
|
299 | sourceFileName?: string | null;
|
300 |
|
301 | /**
|
302 | * 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"`
|
303 | * then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!**
|
304 | *
|
305 | * Default: `false`
|
306 | */
|
307 | sourceMaps?: boolean | 'inline' | 'both' | null;
|
308 |
|
309 | /**
|
310 | * The root from which all sources are relative
|
311 | *
|
312 | * Default: `(moduleRoot)`
|
313 | */
|
314 | sourceRoot?: string | null;
|
315 |
|
316 | /**
|
317 | * 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
|
318 | * `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`.
|
319 | *
|
320 | * Default: `("module")`
|
321 | */
|
322 | sourceType?: 'script' | 'module' | 'unambiguous' | null;
|
323 |
|
324 | /**
|
325 | * If all patterns fail to match, the current configuration object is considered inactive and is ignored during config processing.
|
326 | */
|
327 | test?: MatchPattern | MatchPattern[];
|
328 |
|
329 | /**
|
330 | * 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
|
331 | * `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.
|
332 | */
|
333 | wrapPluginVisitorMethod?:
|
334 | | ((
|
335 | pluginAlias: string,
|
336 | visitorType: 'enter' | 'exit',
|
337 | callback: (path: NodePath, state: any) => void,
|
338 | ) => (path: NodePath, state: any) => void)
|
339 | | null;
|
340 | }
|
341 |
|
342 | export interface TransformCaller {
|
343 | // the only required property
|
344 | name: string;
|
345 | // e.g. set to true by `babel-loader` and false by `babel-jest`
|
346 | supportsStaticESM?: boolean;
|
347 | supportsDynamicImport?: boolean;
|
348 | supportsExportNamespaceFrom?: boolean;
|
349 | supportsTopLevelAwait?: boolean;
|
350 | // augment this with a "declare module '@babel/core' { ... }" if you need more keys
|
351 | }
|
352 |
|
353 | export type FileResultCallback = (err: Error | null, result: BabelFileResult | null) => any;
|
354 |
|
355 | export interface MatchPatternContext {
|
356 | envName: string;
|
357 | dirname: string;
|
358 | caller: TransformCaller | undefined;
|
359 | }
|
360 | export type MatchPattern = string | RegExp | ((filename: string | undefined, context: MatchPatternContext) => boolean);
|
361 |
|
362 | /**
|
363 | * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
|
364 | */
|
365 | export function transform(code: string, callback: FileResultCallback): void;
|
366 |
|
367 | /**
|
368 | * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
|
369 | */
|
370 | export function transform(code: string, opts: TransformOptions | undefined, callback: FileResultCallback): void;
|
371 |
|
372 | /**
|
373 | * Here for backward-compatibility. Ideally use `transformSync` if you want a synchronous API.
|
374 | */
|
375 | export function transform(code: string, opts?: TransformOptions): BabelFileResult | null;
|
376 |
|
377 | /**
|
378 | * Transforms the passed in code. Returning an object with the generated code, source map, and AST.
|
379 | */
|
380 | export function transformSync(code: string, opts?: TransformOptions): BabelFileResult | null;
|
381 |
|
382 | /**
|
383 | * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
|
384 | */
|
385 | export function transformAsync(code: string, opts?: TransformOptions): Promise<BabelFileResult | null>;
|
386 |
|
387 | /**
|
388 | * Asynchronously transforms the entire contents of a file.
|
389 | */
|
390 | export function transformFile(filename: string, callback: FileResultCallback): void;
|
391 |
|
392 | /**
|
393 | * Asynchronously transforms the entire contents of a file.
|
394 | */
|
395 | export function transformFile(filename: string, opts: TransformOptions | undefined, callback: FileResultCallback): void;
|
396 |
|
397 | /**
|
398 | * Synchronous version of `babel.transformFile`. Returns the transformed contents of the `filename`.
|
399 | */
|
400 | export function transformFileSync(filename: string, opts?: TransformOptions): BabelFileResult | null;
|
401 |
|
402 | /**
|
403 | * Asynchronously transforms the entire contents of a file.
|
404 | */
|
405 | export function transformFileAsync(filename: string, opts?: TransformOptions): Promise<BabelFileResult | null>;
|
406 |
|
407 | /**
|
408 | * Given an AST, transform it.
|
409 | */
|
410 | export function transformFromAst(ast: Node, code: string | undefined, callback: FileResultCallback): void;
|
411 |
|
412 | /**
|
413 | * Given an AST, transform it.
|
414 | */
|
415 | export function transformFromAst(
|
416 | ast: Node,
|
417 | code: string | undefined,
|
418 | opts: TransformOptions | undefined,
|
419 | callback: FileResultCallback,
|
420 | ): void;
|
421 |
|
422 | /**
|
423 | * Here for backward-compatibility. Ideally use ".transformSync" if you want a synchronous API.
|
424 | */
|
425 | export function transformFromAstSync(ast: Node, code?: string, opts?: TransformOptions): BabelFileResult | null;
|
426 |
|
427 | /**
|
428 | * Given an AST, transform it.
|
429 | */
|
430 | export function transformFromAstAsync(
|
431 | ast: Node,
|
432 | code?: string,
|
433 | opts?: TransformOptions,
|
434 | ): Promise<BabelFileResult | null>;
|
435 |
|
436 | // A babel plugin is a simple function which must return an object matching
|
437 | // the following interface. Babel will throw if it finds unknown properties.
|
438 | // The list of allowed plugin keys is here:
|
439 | // https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-core/src/config/option-manager.js#L71
|
440 | export interface PluginObj<S = PluginPass> {
|
441 | name?: string;
|
442 | manipulateOptions?(opts: any, parserOpts: any): void;
|
443 | pre?(this: S, file: BabelFile): void;
|
444 | visitor: Visitor<S>;
|
445 | post?(this: S, file: BabelFile): void;
|
446 | inherits?: any;
|
447 | }
|
448 |
|
449 | export interface BabelFile {
|
450 | ast: t.File;
|
451 | opts: TransformOptions;
|
452 | hub: Hub;
|
453 | metadata: object;
|
454 | path: NodePath<t.Program>;
|
455 | scope: Scope;
|
456 | inputMap: object | null;
|
457 | code: string;
|
458 | }
|
459 |
|
460 | export interface PluginPass {
|
461 | file: BabelFile;
|
462 | key: string;
|
463 | opts: PluginOptions;
|
464 | cwd: string;
|
465 | filename: string;
|
466 | [key: string]: unknown;
|
467 | }
|
468 |
|
469 | export interface BabelFileResult {
|
470 | ast?: t.File | null;
|
471 | code?: string | null;
|
472 | ignored?: boolean;
|
473 | map?: {
|
474 | version: number;
|
475 | sources: string[];
|
476 | names: string[];
|
477 | sourceRoot?: string;
|
478 | sourcesContent?: string[];
|
479 | mappings: string;
|
480 | file: string;
|
481 | } | null;
|
482 | metadata?: BabelFileMetadata;
|
483 | }
|
484 |
|
485 | export interface BabelFileMetadata {
|
486 | usedHelpers: string[];
|
487 | marked: Array<{
|
488 | type: string;
|
489 | message: string;
|
490 | loc: object;
|
491 | }>;
|
492 | modules: BabelFileModulesMetadata;
|
493 | }
|
494 |
|
495 | export interface BabelFileModulesMetadata {
|
496 | imports: object[];
|
497 | exports: {
|
498 | exported: object[];
|
499 | specifiers: object[];
|
500 | };
|
501 | }
|
502 |
|
503 | export type FileParseCallback = (err: Error | null, result: ParseResult | null) => any;
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 | export function parse(code: string, callback: FileParseCallback): void;
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 | export function parse(code: string, options: TransformOptions | undefined, callback: FileParseCallback): void;
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 | export function parse(code: string, options?: TransformOptions): ParseResult | null;
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 | export function parseSync(code: string, options?: TransformOptions): ParseResult | null;
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 | export function parseAsync(code: string, options?: TransformOptions): Promise<ParseResult | null>;
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 | export function loadOptions(options?: TransformOptions): object | null;
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | export function loadPartialConfig(options?: TransformOptions): Readonly<PartialConfig> | null;
|
569 | export function loadPartialConfigAsync(options?: TransformOptions): Promise<Readonly<PartialConfig> | null>;
|
570 |
|
571 | export interface PartialConfig {
|
572 | options: TransformOptions;
|
573 | babelrc?: string;
|
574 | babelignore?: string;
|
575 | config?: string;
|
576 | hasFilesystemConfig: () => boolean;
|
577 | }
|
578 |
|
579 | export interface ConfigItem {
|
580 | |
581 |
|
582 |
|
583 | name?: string;
|
584 |
|
585 | |
586 |
|
587 |
|
588 | value: object | ((...args: any[]) => any);
|
589 |
|
590 | /**
|
591 | * The options object passed to the plugin.
|
592 | */
|
593 | options?: object | false;
|
594 |
|
595 | /**
|
596 | * The path that the options are relative to.
|
597 | */
|
598 | dirname: string;
|
599 |
|
600 | /**
|
601 | * Information about the plugin's file, if Babel knows it.
|
602 | * *
|
603 | */
|
604 | file?: {
|
605 | /**
|
606 | * The file that the user requested, e.g. `"@babel/env"`
|
607 | */
|
608 | request: string;
|
609 |
|
610 | /**
|
611 | * The full path of the resolved file, e.g. `"/tmp/node_modules/@babel/preset-env/lib/index.js"`
|
612 | */
|
613 | resolved: string;
|
614 | } | null;
|
615 | }
|
616 |
|
617 | export type PluginOptions = object | undefined | false;
|
618 |
|
619 | export type PluginTarget = string | object | ((...args: any[]) => any);
|
620 |
|
621 | export type PluginItem =
|
622 | | ConfigItem
|
623 | | PluginObj<any>
|
624 | | PluginTarget
|
625 | | [PluginTarget, PluginOptions]
|
626 | | [PluginTarget, PluginOptions, string | undefined];
|
627 |
|
628 | export function resolvePlugin(name: string, dirname: string): string | null;
|
629 | export function resolvePreset(name: string, dirname: string): string | null;
|
630 |
|
631 | export interface CreateConfigItemOptions {
|
632 | dirname?: string;
|
633 | type?: 'preset' | 'plugin';
|
634 | }
|
635 |
|
636 | /**
|
637 | * Allows build tooling to create and cache config items up front. If this function is called multiple times for a
|
638 | * given plugin, Babel will call the plugin's function itself multiple times. If you have a clear set of expected
|
639 | * plugins and presets to inject, pre-constructing the config items would be recommended.
|
640 | */
|
641 | export function createConfigItem(
|
642 | value: PluginTarget | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined],
|
643 | options?: CreateConfigItemOptions,
|
644 | ): ConfigItem;
|
645 |
|
646 | // NOTE: the documentation says the ConfigAPI also exposes @babel/core's exports, but it actually doesn't
|
647 | /**
|
648 | * @see https://babeljs.io/docs/en/next/config-files#config-function-api
|
649 | */
|
650 | export interface ConfigAPI {
|
651 | /**
|
652 | * The version string for the Babel version that is loading the config file.
|
653 | *
|
654 | * @see https://babeljs.io/docs/en/next/config-files#apiversion
|
655 | */
|
656 | version: string;
|
657 | /**
|
658 | * @see https://babeljs.io/docs/en/next/config-files#apicache
|
659 | */
|
660 | cache: SimpleCacheConfigurator;
|
661 | /**
|
662 | * @see https://babeljs.io/docs/en/next/config-files#apienv
|
663 | */
|
664 | env: EnvFunction;
|
665 | // undocumented; currently hardcoded to return 'false'
|
666 | // async(): boolean
|
667 | /**
|
668 | * This API is used as a way to access the `caller` data that has been passed to Babel.
|
669 | * Since many instances of Babel may be running in the same process with different `caller` values,
|
670 | * this API is designed to automatically configure `api.cache`, the same way `api.env()` does.
|
671 | *
|
672 | * The `caller` value is available as the first parameter of the callback function.
|
673 | * It is best used with something like this to toggle configuration behavior
|
674 | * based on a specific environment:
|
675 | *
|
676 | * @example
|
677 | * function isBabelRegister(caller?: { name: string }) {
|
678 | * return !!(caller && caller.name === "@babel/register")
|
679 | * }
|
680 | * api.caller(isBabelRegister)
|
681 | *
|
682 | * @see https://babeljs.io/docs/en/next/config-files#apicallercb
|
683 | */
|
684 | caller<T extends SimpleCacheKey>(callerCallback: (caller: TransformOptions['caller']) => T): T;
|
685 | /**
|
686 | * While `api.version` can be useful in general, it's sometimes nice to just declare your version.
|
687 | * This API exposes a simple way to do that with:
|
688 | *
|
689 | * @example
|
690 | * api.assertVersion(7) // major version only
|
691 | * api.assertVersion("^7.2")
|
692 | *
|
693 | * @see https://babeljs.io/docs/en/next/config-files#apiassertversionrange
|
694 | */
|
695 | assertVersion(versionRange: number | string): boolean;
|
696 | // NOTE: this is an undocumented reexport from "@babel/parser" but it's missing from its types
|
697 | // tokTypes: typeof tokTypes
|
698 | }
|
699 |
|
700 | /**
|
701 | * JS configs are great because they can compute a config on the fly,
|
702 | * but the downside there is that it makes caching harder.
|
703 | * Babel wants to avoid re-executing the config function every time a file is compiled,
|
704 | * because then it would also need to re-execute any plugin and preset functions
|
705 | * referenced in that config.
|
706 | *
|
707 | * To avoid this, Babel expects users of config functions to tell it how to manage caching
|
708 | * within a config file.
|
709 | *
|
710 | * @see https://babeljs.io/docs/en/next/config-files#apicache
|
711 | */
|
712 | export interface SimpleCacheConfigurator {
|
713 | // there is an undocumented call signature that is a shorthand for forever()/never()/using().
|
714 | // (ever: boolean): void
|
715 | // <T extends SimpleCacheKey>(callback: CacheCallback<T>): T
|
716 | /**
|
717 | * Permacache the computed config and never call the function again.
|
718 | */
|
719 | forever(): void;
|
720 | /**
|
721 | * Do not cache this config, and re-execute the function every time.
|
722 | */
|
723 | never(): void;
|
724 | /**
|
725 | * Any time the using callback returns a value other than the one that was expected,
|
726 | * the overall config function will be called again and a new entry will be added to the cache.
|
727 | *
|
728 | * @example
|
729 | * api.cache.using(() => process.env.NODE_ENV)
|
730 | */
|
731 | using<T extends SimpleCacheKey>(callback: SimpleCacheCallback<T>): T;
|
732 | /**
|
733 | * Any time the using callback returns a value other than the one that was expected,
|
734 | * the overall config function will be called again and all entries in the cache will
|
735 | * be replaced with the result.
|
736 | *
|
737 | * @example
|
738 | * api.cache.invalidate(() => process.env.NODE_ENV)
|
739 | */
|
740 | invalidate<T extends SimpleCacheKey>(callback: SimpleCacheCallback<T>): T;
|
741 | }
|
742 |
|
743 | // https://github.com/babel/babel/blob/v7.3.3/packages/babel-core/src/config/caching.js#L231
|
744 | export type SimpleCacheKey = string | boolean | number | null | undefined;
|
745 | export type SimpleCacheCallback<T extends SimpleCacheKey> = () => T;
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | export interface EnvFunction {
|
755 | |
756 |
|
757 |
|
758 | (): string;
|
759 | |
760 |
|
761 |
|
762 | (envName: string | ReadonlyArray<string>): boolean;
|
763 |
|
764 |
|
765 |
|
766 | <T extends SimpleCacheKey>(envCallback: (envName: NonNullable<TransformOptions['envName']>) => T): T;
|
767 | }
|
768 |
|
769 | export type ConfigFunction = (api: ConfigAPI) => TransformOptions;
|
770 |
|
771 | export as namespace babel;
|