From 437443a7f7cbe7cc6f68ca044b5b3bf09ed6d23e Mon Sep 17 00:00:00 2001 From: Anton Kudinov Date: Fri, 14 Feb 2020 19:42:23 +0200 Subject: [PATCH] [@babel/core] Add missing merge options (#42085) --- types/babel__core/babel__core-tests.ts | 24 ++++++++++++++++++++++ types/babel__core/index.d.ts | 28 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/types/babel__core/babel__core-tests.ts b/types/babel__core/babel__core-tests.ts index 4a42906fc8..85af8a46a1 100644 --- a/types/babel__core/babel__core-tests.ts +++ b/types/babel__core/babel__core-tests.ts @@ -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(() => {}); diff --git a/types/babel__core/index.d.ts b/types/babel__core/index.d.ts index ef0b25d32a..57f2d3175f 100644 --- a/types/babel__core/index.d.ts +++ b/types/babel__core/index.d.ts @@ -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 | 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. */