Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: allow users to set additional babylon plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
muzea authored and KnisterPeter committed Sep 26, 2018
1 parent 2732904 commit 9798c08
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export interface Options {
* @memberOf Options
*/
eol?: string;

/**
* babylon plugins. Allow users to set additional plugins.
*
* @type {string[]}
* @memberOf Options
*/
babylonPlugins?: string[];
}

export function cli(options: any): void {
Expand Down Expand Up @@ -89,6 +97,7 @@ export function generateFromFile(moduleName: string|null, path: string, options:

export function generateFromSource(moduleName: string|null, code: string, options: IOptions = {},
reactImport = 'react'): string {
const additionalBabylonPlugins = Array.isArray(options.babylonPlugins) ? options.babylonPlugins : [];
const ast = babylon.parse(code, {
sourceType: 'module',
allowReturnOutsideFunction: true,
Expand All @@ -108,7 +117,8 @@ export function generateFromSource(moduleName: string|null, code: string, option
'exponentiationOperator',
'asyncGenerators',
'functionBind',
'functionSent'
'functionSent',
...additionalBabylonPlugins
]
});
if (!options.source) {
Expand Down

0 comments on commit 9798c08

Please sign in to comment.