-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (54 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// @flow
'use strict';
const babel = require('babel-core');
/*::
type BabelOptions = {
ast?: boolean,
auxiliaryCommentAfter?: string,
auxiliaryCommentBefore?: string,
babelrc?: boolean,
code?: boolean,
comments?: boolean,
compact?: "auto" | boolean,
env?: { [environment: string]: BabelOptions },
extends?: string,
filename?: string,
filenameRelative?: string,
generatorOpts?: Object,
getModuleId?: (moduleName: string) => string | false | null | void,
highlightCode?: boolean,
ignore?: Array<string | RegExp>,
inputSourceMap?: string,
minified?: boolean,
moduleId?: string,
moduleIds?: boolean,
moduleRoot?: string,
only?: Array<string | RegExp>,
parserOpts?: Object,
plugins?: Array<string | Function | [string | Function, Object]>,
presets?: Array<string | Function | [string | Function, Object]>,
retainLines?: boolean,
resolveModuleSource?: (source: string, filename: string) => string,
shouldPrintComment?: (commentContents: string) => boolean,
sourceFileName?: string,
sourceMaps?: boolean,
sourceMapTarget?: string,
sourceRoot?: string,
sourceType?: "module" | "script",
wrapPluginVisitorMethod?: (
pluginAlias: string,
visitorType: string,
callback: Function,
) => Function,
};
type Options = {
code: string,
options?: BabelOptions,
};
*/
exports.transform = (opts /*: Options */) => {
return new Promise(resolve => {
let { code, ast } = babel.transform(opts.code, opts.options);
resolve({ code, ast });
});
};