Skip to content

Commit

Permalink
Merge pull request #5376 from loganfsmyth/no-pipeline
Browse files Browse the repository at this point in the history
[7.0] Remove the unneeded Pipeline class.
  • Loading branch information
loganfsmyth committed Feb 27, 2017
2 parents 696e63c + f3e9201 commit 9acae54
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 53 deletions.
9 changes: 2 additions & 7 deletions packages/babel-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
8 changes: 2 additions & 6 deletions packages/babel-core/src/transformation/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -105,7 +102,6 @@ export default class File extends Store {

pluginVisitors: Array<Object>;
pluginPasses: Array<PluginPass>;
pipeline: Pipeline;
parserOpts: BabelParserOptions;
log: Logger;
opts: Object;
Expand Down Expand Up @@ -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;
Expand Down
63 changes: 23 additions & 40 deletions packages/babel-core/src/transformation/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
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;
}

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;
}
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();
});
}

transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult {
ast = normalizeAst(ast);
export function 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();
});
}
const file = new File(opts);
return file.wrap(code, function () {
file.addCode(code);
file.addAst(ast);
return file.transform();
});
}

0 comments on commit 9acae54

Please sign in to comment.