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