Amjad Masad 12ee11a0a4 Revert "Remove Flow annotations and pragmas"
This reverts commit 4252244d06b225ab26a02d52c04f9940a3e4d6a2.
2016-03-03 15:03:55 -08:00

54 lines
1.4 KiB
JavaScript

/* @flow */
/* global BabelFileResult */
/* global BabelFileMetadata */
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 {
let file = new File(opts, this);
return file.wrap(code, function () {
file.addCode(code);
file.parseCode(code);
return file;
});
}
transform(code: string, opts?: Object): BabelFileResult {
let 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);
let file = new File(opts, this);
return file.wrap(code, function () {
file.addCode(code);
file.addAst(ast);
return file.transform();
});
}
}