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 constantFolding = require('./constant-folding');
|
||||||
const extractDependencies = require('./extract-dependencies');
|
const extractDependencies = require('./extract-dependencies');
|
||||||
|
const generate = require('babel-generator').default;
|
||||||
const inline = require('./inline');
|
const inline = require('./inline');
|
||||||
const minify = require('./minify');
|
const minify = require('./minify');
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ function transformCode(
|
||||||
? []
|
? []
|
||||||
: [[inline.plugin, options], [constantFolding.plugin, options]];
|
: [[inline.plugin, options], [constantFolding.plugin, options]];
|
||||||
|
|
||||||
const transformed = transformer.transform({
|
const result = transformer.transform({
|
||||||
filename,
|
filename,
|
||||||
localPath,
|
localPath,
|
||||||
options: options.transform,
|
options: options.transform,
|
||||||
|
@ -125,6 +126,23 @@ function transformCode(
|
||||||
src: sourceCode,
|
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
|
// If the transformer returns standard sourcemaps, we need to transform them
|
||||||
// to rawMappings so we can process them correctly.
|
// to rawMappings so we can process them correctly.
|
||||||
const rawMappings =
|
const rawMappings =
|
||||||
|
|
Loading…
Reference in New Issue