From 4e76256d6dddb2e354f0e07515590b04bfffd419 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 19 Dec 2019 02:36:22 -0800 Subject: [PATCH] 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 --- static/transforms/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/static/transforms/index.js b/static/transforms/index.js index 956b99ed7..ccee3d9ab 100644 --- a/static/transforms/index.js +++ b/static/transforms/index.js @@ -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,