[@babel/core] Add missing merge options (#42085)

This commit is contained in:
Anton Kudinov
2020-02-14 19:42:23 +02:00
committed by GitHub
parent fca28df8dd
commit 437443a7f7
2 changed files with 52 additions and 0 deletions

View File

@@ -58,6 +58,30 @@ checkOptions({ caller: { name: '', tomato: true } });
checkOptions({ rootMode: 'upward-optional' });
// $ExpectError
checkOptions({ rootMode: 'potato' });
checkOptions({ exclude: '../node_modules' });
// $ExpectError
checkOptions({ exclude: 256 });
checkOptions({ include: [/node_modules/, new RegExp('bower_components')] });
// $ExpectError
checkOptions({ include: [null] });
checkOptions({ test: (fileName) => fileName ? fileName.endsWith('mjs') : false });
// $ExpectError
checkOptions({ test: (fileName) => fileName && fileName.endsWith('mjs') });
checkOptions({
overrides: [
{
test: /^.*\.m?js$/,
compact: true,
}
]
});
checkOptions({
overrides: {
// $ExpectError
test: /^.*\.m?js$/,
compact: true,
}
});
// $ExpectError
checkConfigFunction(() => {});

View File

@@ -96,6 +96,11 @@ export interface TransformOptions {
*/
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
*
@@ -189,6 +194,11 @@ export interface TransformOptions {
*/
ignore?: string[] | null;
/**
* This option is a synonym for "test"
*/
include?: MatchPattern | MatchPattern[];
/**
* A source map object that the output source map will be based on
*
@@ -232,6 +242,12 @@ export interface TransformOptions {
*/
only?: string | RegExp | Array<string | RegExp> | 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
*
@@ -297,6 +313,11 @@ export interface TransformOptions {
*/
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)`.
@@ -314,6 +335,13 @@ export interface TransformCaller {
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.
*/