Skip to content

Commit

Permalink
feat(injector): allow providing babel options
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Mar 28, 2020
1 parent 8e51dcc commit 2ab6f43
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export type InjectOptions = {
* @default includeUnusedProps ? true : data.usedProps.includes(data.prop.name)
*/
shouldInclude?(data: { prop: t.PropTypeNode; usedProps: string[] }): boolean | undefined;

/**
* Options passed to babel.transformSync
*/
babelOptions?: babel.TransformOptions;
} & Pick<GenerateOptions, 'sortProptypes' | 'includeJSDoc' | 'comment'>;

/**
Expand All @@ -41,15 +46,19 @@ export function inject(

const propTypesToInject = new Map<string, string>();

const { plugins: babelPlugins = [], ...babelOptions } = options.babelOptions || {};

const result = babel.transformSync(target, {
plugins: [
require.resolve('@babel/plugin-syntax-class-properties'),
require.resolve('@babel/plugin-syntax-jsx'),
plugin(propTypes, options, propTypesToInject),
...(babelPlugins || []),
],
configFile: false,
babelrc: false,
retainLines: true,
...babelOptions,
});

let code = result && result.code;
Expand Down

0 comments on commit 2ab6f43

Please sign in to comment.