Remove the unneeded Pipeline class.
This commit is contained in:
parent
87ca6150ae
commit
f3e92010c5
@ -27,13 +27,8 @@ export function Plugin(alias) {
|
||||
throw new Error(`The (${alias}) Babel 5 plugin is being run with Babel 6.`);
|
||||
}
|
||||
|
||||
import Pipeline from "./transformation/pipeline";
|
||||
export { Pipeline };
|
||||
|
||||
const pipeline = new Pipeline;
|
||||
export const analyse = pipeline.analyse.bind(pipeline);
|
||||
export const transform = pipeline.transform.bind(pipeline);
|
||||
export const transformFromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
import { transform, analyse, transformFromAst } from "./transformation/pipeline";
|
||||
export { transform, analyse, transformFromAst };
|
||||
|
||||
export function transformFile(filename: string, opts?: Object, callback: Function) {
|
||||
if (typeof opts === "function") {
|
||||
|
||||
@ -4,7 +4,6 @@ import getHelper from "babel-helpers";
|
||||
import * as metadataVisitor from "./metadata";
|
||||
import convertSourceMap from "convert-source-map";
|
||||
import OptionManager from "./options/option-manager";
|
||||
import type Pipeline from "../pipeline";
|
||||
import PluginPass from "../plugin-pass";
|
||||
import { NodePath, Hub, Scope } from "babel-traverse";
|
||||
import sourceMap from "source-map";
|
||||
@ -42,11 +41,9 @@ const errorVisitor = {
|
||||
};
|
||||
|
||||
export default class File extends Store {
|
||||
constructor(opts: Object = {}, pipeline: Pipeline) {
|
||||
constructor(opts: Object = {}) {
|
||||
super();
|
||||
|
||||
this.pipeline = pipeline;
|
||||
|
||||
this.log = new Logger(this, opts.filename || "unknown");
|
||||
this.opts = this.initOptions(opts);
|
||||
|
||||
@ -105,7 +102,6 @@ export default class File extends Store {
|
||||
|
||||
pluginVisitors: Array<Object>;
|
||||
pluginPasses: Array<PluginPass>;
|
||||
pipeline: Pipeline;
|
||||
parserOpts: BabelParserOptions;
|
||||
log: Logger;
|
||||
opts: Object;
|
||||
@ -136,7 +132,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
initOptions(opts) {
|
||||
opts = new OptionManager(this.log, this.pipeline).init(opts);
|
||||
opts = new OptionManager(this.log).init(opts);
|
||||
|
||||
if (opts.inputSourceMap) {
|
||||
opts.sourceMaps = true;
|
||||
|
||||
@ -3,48 +3,31 @@ import normalizeAst from "../helpers/normalize-ast";
|
||||
import Plugin from "./plugin";
|
||||
import File from "./file";
|
||||
|
||||
export default class Pipeline {
|
||||
lint(code: string, opts?: Object = {}): BabelFileResult {
|
||||
opts.code = false;
|
||||
opts.mode = "lint";
|
||||
return this.transform(code, opts);
|
||||
}
|
||||
|
||||
pretransform(code: string, opts?: Object): BabelFileResult {
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
return file;
|
||||
});
|
||||
}
|
||||
|
||||
transform(code: string, opts?: Object): BabelFileResult {
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
return file.transform();
|
||||
});
|
||||
}
|
||||
|
||||
analyse(code: string, opts: Object = {}, visitor?: Object): ?BabelFileMetadata {
|
||||
opts.code = false;
|
||||
if (visitor) {
|
||||
opts.plugins = opts.plugins || [];
|
||||
opts.plugins.push(new Plugin({ visitor }));
|
||||
}
|
||||
return this.transform(code, opts).metadata;
|
||||
}
|
||||
|
||||
transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.addAst(ast);
|
||||
return file.transform();
|
||||
});
|
||||
export function analyse(code: string, opts: Object = {}, visitor?: Object): ?BabelFileMetadata {
|
||||
opts.code = false;
|
||||
if (visitor) {
|
||||
opts.plugins = opts.plugins || [];
|
||||
opts.plugins.push(new Plugin({ visitor }));
|
||||
}
|
||||
return transform(code, opts).metadata;
|
||||
}
|
||||
|
||||
export function transform(code: string, opts?: Object): BabelFileResult {
|
||||
const file = new File(opts);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
return file.transform();
|
||||
});
|
||||
}
|
||||
|
||||
export function transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
const file = new File(opts);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.addAst(ast);
|
||||
return file.transform();
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user