Metro reads AST from transformers if available

Reviewed By: BYK

Differential Revision: D6396330

fbshipit-source-id: 10539a1cce81b090a781df7d75515d52ece9ef9c
This commit is contained in:
Rafael Oleza 2017-11-22 13:29:40 -08:00 committed by Facebook Github Bot
parent c9e0589171
commit 5f58ae0e84
1 changed files with 19 additions and 1 deletions

View File

@ -14,6 +14,7 @@
const constantFolding = require('./constant-folding');
const extractDependencies = require('./extract-dependencies');
const generate = require('babel-generator').default;
const inline = require('./inline');
const minify = require('./minify');
@ -117,7 +118,7 @@ function transformCode(
? []
: [[inline.plugin, options], [constantFolding.plugin, options]];
const transformed = transformer.transform({
const result = transformer.transform({
filename,
localPath,
options: options.transform,
@ -125,6 +126,23 @@ function transformCode(
src: sourceCode,
});
// If we receive AST from the transformer, serialize it into code/map.
const transformed = result.ast
? generate(
result.ast,
{
code: false,
comments: false,
compact: false,
filename: localPath,
retainLines: false,
sourceFileName: filename,
sourceMaps: true,
},
sourceCode,
)
: {code: result.code, map: result.map};
// If the transformer returns standard sourcemaps, we need to transform them
// to rawMappings so we can process them correctly.
const rawMappings =