mirror of https://github.com/status-im/metro.git
Metro reads AST from transformers if available
Reviewed By: BYK Differential Revision: D6396330 fbshipit-source-id: 10539a1cce81b090a781df7d75515d52ece9ef9c
This commit is contained in:
parent
c9e0589171
commit
5f58ae0e84
|
@ -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 =
|
||||
|
|
Loading…
Reference in New Issue