Remove baseTransformer

Reviewed By: jeanlauliac

Differential Revision: D4506124

fbshipit-source-id: 642f06dffe4ea710113e8e8426915bf1b40d4611
This commit is contained in:
Christoph Pojer
2017-02-09 04:03:17 -08:00
committed by Facebook Github Bot
parent 57990b7970
commit a4d7a7835f
7 changed files with 143 additions and 161 deletions
@@ -21,8 +21,8 @@ const {basename} = require('path');
import type {
Callback,
TransformedFile,
TransformFn,
TransformFnResult,
Transformer,
TransformerResult,
TransformResult,
TransformVariants,
} from '../types.flow';
@@ -30,7 +30,7 @@ import type {
export type TransformOptions = {|
filename: string,
polyfill?: boolean,
transform: TransformFn,
transformer: Transformer,
variants?: TransformVariants,
|};
@@ -47,17 +47,23 @@ function transformModule(
return transformJSON(code, options, callback);
}
const {filename, transform, variants = defaultVariants} = options;
const {filename, transformer, variants = defaultVariants} = options;
const tasks = {};
Object.keys(variants).forEach(name => {
tasks[name] = cb => transform({
filename,
sourceCode: code,
options: variants[name],
}, cb);
tasks[name] = cb => {
try {
cb(null, transformer.transform(
code,
filename,
variants[name],
));
} catch (error) {
cb(error, null);
}
};
});
series(tasks, (error, results: {[key: string]: TransformFnResult}) => {
series(tasks, (error, results: {[key: string]: TransformerResult}) => {
if (error) {
callback(error);
return;