rejigger around parse mechanics

This commit is contained in:
Sebastian McKenzie
2015-05-04 03:57:28 +01:00
parent a8a3f6d34d
commit b8b70f2f4a
5 changed files with 20 additions and 22 deletions

View File

@@ -14,7 +14,6 @@ export { default as TransformerPipeline } from "../transformation/transformer-pi
export { default as traverse } from "../traversal";
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
export { version } from "../../../package";
export { all as parse } from "../helpers/parse";
import * as t from "../types";
export { t as types };
@@ -56,3 +55,20 @@ export function transformFileSync(filename: string, opts?: Object = {}) {
opts.filename = filename;
return transform(fs.readFileSync(filename), opts);
}
export function parse(code, opts = {}) {
opts.allowHashBang = true;
opts.sourceType = "module";
opts.ecmaVersion = Infinity;
opts.plugins = {
flow: true,
jsx: true
};
opts.features = {};
for (var key in transform.pipeline.transformers) {
opts.features[key] = true;
}
return acorn.parse(code, opts);
}

View File

@@ -1,5 +1,4 @@
import normalizeAst from "./normalize-ast";
import transform from "../transformation";
import estraverse from "estraverse";
import * as acorn from "../../acorn";
@@ -33,20 +32,3 @@ export default function (code, opts = {}) {
ast = normalizeAst(ast, comments, tokens);
return ast;
}
export function all(code, opts = {}) {
opts.allowHashBang = true;
opts.sourceType = "module";
opts.ecmaVersion = Infinity;
opts.plugins = {
flow: true,
jsx: true
};
opts.features = {};
for (var key in transform.pipeline.transformers) {
opts.features[key] = true;
}
return acorn.parse(code, opts);
}

View File

@@ -4,7 +4,7 @@ import isNumber from "lodash/lang/isNumber";
import isRegExp from "lodash/lang/isRegExp";
import isString from "lodash/lang/isString";
import codeFrame from "../../helpers/code-frame";
import { all as parse } from "../../helpers/parse";
import parse from "../../helpers/parse";
import traverse from "../index";
import includes from "lodash/collection/includes";
import assign from "lodash/object/assign";