-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
40 lines (33 loc) · 842 Bytes
/
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
// @flow
'use strict';
const babel = require('@babel/core');
/*::
export type File = {
ast: Object,
code: string,
opts: Object,
parserOpts: Object,
path: Object,
scope: Object,
metadata: Object,
addImport(source: string, imported: string, name?: string): Object,
buildCodeFrameError(node: Object, msg: string, Error?: typeof Error): Error,
mergeSourceMap(map: Object): Object,
parse(code: string): Object,
addAST(ast: Object): void,
transform(): any,
wrap<T>(code: string, cb: () => T): T,
addCode(code: string): void,
parseCode(code: string): void,
shouldIgnore(): boolean,
generate(): Object,
};
*/
function createFile(
code /*: string */,
opts /*: Object */
) /*: File */ {
let ast = babel.parseSync(code, opts);
return new babel.File(opts, { code, ast });
}
module.exports = createFile;