mirror of https://github.com/status-im/metro.git
Tweak default transformer to do some very minimal babel transformation
Reviewed By: jeanlauliac Differential Revision: D6711526 fbshipit-source-id: 03c6aea85fb6d13e92e458a46bf4a3db1268aa11
This commit is contained in:
parent
1cad201448
commit
81a500cd67
|
@ -11,10 +11,27 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const babylon = require('babylon');
|
||||
const babel = require('babel-core');
|
||||
|
||||
module.exports.transform = (file: {filename: string, src: string}) => {
|
||||
const ast = babylon.parse(file.src, {sourceType: 'module'});
|
||||
import type {TransformOptions} from './JSTransformer/worker';
|
||||
import type {Plugins as BabelPlugins} from 'babel-core';
|
||||
|
||||
return {ast};
|
||||
type Params = {
|
||||
filename: string,
|
||||
options: TransformOptions,
|
||||
plugins?: BabelPlugins,
|
||||
src: string,
|
||||
};
|
||||
|
||||
module.exports.transform = ({filename, options, plugins, src}: Params) => {
|
||||
const OLD_BABEL_ENV = process.env.BABEL_ENV;
|
||||
process.env.BABEL_ENV = options.dev ? 'development' : 'production';
|
||||
|
||||
try {
|
||||
const {ast} = babel.transform(src, {filename, code: false, plugins});
|
||||
|
||||
return {ast};
|
||||
} finally {
|
||||
process.env.BABEL_ENV = OLD_BABEL_ENV;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue