Avoid confusion variable reassignments in transformer
Summary: While trying to find a simple fix for the broken source maps when unit testing (see previous diff), I noticed that control flow in the transformer was unnecessarily complicated. This doesn't fix the sourcemap issue btw Reviewed By: passy Differential Revision: D19158367 fbshipit-source-id: 7dfe4b28eabd4534a32dcb655e534d0f418f0db4
This commit is contained in:
committed by
Facebook Github Bot
parent
09184a999f
commit
4e76256d6d
@@ -19,7 +19,7 @@ function transform({filename, options, src}) {
|
||||
options.projectRoot && !__dirname.startsWith(options.projectRoot);
|
||||
const isTypeScript = filename.endsWith('.tsx');
|
||||
|
||||
let ast = babylon.parse(src, {
|
||||
const ast = babylon.parse(src, {
|
||||
filename,
|
||||
plugins: isTypeScript
|
||||
? [
|
||||
@@ -86,7 +86,7 @@ function transform({filename, options, src}) {
|
||||
} else {
|
||||
plugins.push(require('./import-react.js'));
|
||||
}
|
||||
ast = babel.transformFromAst(ast, src, {
|
||||
const transformed = babel.transformFromAst(ast, src, {
|
||||
ast: true,
|
||||
babelrc: !filename.includes('node_modules'),
|
||||
code: false,
|
||||
@@ -97,10 +97,10 @@ function transform({filename, options, src}) {
|
||||
plugins,
|
||||
presets,
|
||||
sourceMaps: true,
|
||||
}).ast;
|
||||
});
|
||||
|
||||
const result = generate(
|
||||
ast,
|
||||
transformed.ast,
|
||||
{
|
||||
filename,
|
||||
sourceFileName: filename,
|
||||
@@ -109,7 +109,7 @@ function transform({filename, options, src}) {
|
||||
src,
|
||||
);
|
||||
return {
|
||||
ast,
|
||||
ast: transformed.ast,
|
||||
code: result.code,
|
||||
filename,
|
||||
map: result.map,
|
||||
|
||||
Reference in New Issue
Block a user