remove babel.parse and encourage use of babylon directly
This commit is contained in:
parent
64d5ec090b
commit
d108d799bf
@ -57,26 +57,3 @@ export function transformFileSync(filename: string, opts?: Object = {}): string
|
|||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
return transform(fs.readFileSync(filename, "utf8"), opts);
|
return transform(fs.readFileSync(filename, "utf8"), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parse(code, opts = {}) {
|
|
||||||
opts.allowHashBang = true;
|
|
||||||
opts.sourceType = "module";
|
|
||||||
opts.ecmaVersion = Infinity;
|
|
||||||
opts.plugins = {
|
|
||||||
jsx: true,
|
|
||||||
flow: true
|
|
||||||
};
|
|
||||||
opts.features = {};
|
|
||||||
|
|
||||||
let ast = babylon.parse(code, opts);
|
|
||||||
|
|
||||||
if (opts.onToken) {
|
|
||||||
opts.onToken.push(...ast.tokens);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.onComment) {
|
|
||||||
opts.onComment.push(...ast.comments);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ast.program;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
|
|
||||||
import * as babylon from "babylon";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse `code` with normalized options, collecting tokens and comments.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export default function (code: string, opts: BabelParserOptions = {}) {
|
|
||||||
let parseOpts = {
|
|
||||||
allowImportExportEverywhere: opts.looseModules,
|
|
||||||
allowReturnOutsideFunction: opts.looseModules,
|
|
||||||
strictMode: opts.strictMode,
|
|
||||||
sourceType: opts.sourceType,
|
|
||||||
features: opts.features || {},
|
|
||||||
plugins: opts.plugins || {}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (opts.nonStandard) {
|
|
||||||
parseOpts.plugins.jsx = true;
|
|
||||||
parseOpts.plugins.flow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return babylon.parse(code, parseOpts);
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user