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

Commit 9798c08

Browse files
muzeaKnisterPeter
authored andcommitted
feat: allow users to set additional babylon plugins
1 parent 2732904 commit 9798c08

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ export interface Options {
5555
* @memberOf Options
5656
*/
5757
eol?: string;
58+
59+
/**
60+
* babylon plugins. Allow users to set additional plugins.
61+
*
62+
* @type {string[]}
63+
* @memberOf Options
64+
*/
65+
babylonPlugins?: string[];
5866
}
5967

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

9098
export function generateFromSource(moduleName: string|null, code: string, options: IOptions = {},
9199
reactImport = 'react'): string {
100+
const additionalBabylonPlugins = Array.isArray(options.babylonPlugins) ? options.babylonPlugins : [];
92101
const ast = babylon.parse(code, {
93102
sourceType: 'module',
94103
allowReturnOutsideFunction: true,
@@ -108,7 +117,8 @@ export function generateFromSource(moduleName: string|null, code: string, option
108117
'exponentiationOperator',
109118
'asyncGenerators',
110119
'functionBind',
111-
'functionSent'
120+
'functionSent',
121+
...additionalBabylonPlugins
112122
]
113123
});
114124
if (!options.source) {

0 commit comments

Comments
 (0)