Skip to content

Commit

Permalink
Handle the case where transformSync returns null (#264)
Browse files Browse the repository at this point in the history
Summary:
**Summary**

Fixes a bug when ignoring a file in the babel config: #255 (comment)

**Test plan**

Couldn't find any obvious tests that test this part of the code. Happy to add some tests if someone can point me in the right direction.
Pull Request resolved: #264

Differential Revision: D10063236

Pulled By: rafeca

fbshipit-source-id: 04205b856c513fd90c0ae022c2cbb4deeef0c993
  • Loading branch information
jkimbo authored and facebook-github-bot committed Sep 27, 2018
1 parent 9e440d8 commit 66aa795
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/metro/src/reactNativeTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,19 @@ function transform({filename, options, src, plugins}: BabelTransformerArgs) {

try {
const babelConfig = buildBabelConfig(filename, options, plugins);
const {ast} = transformSync(src, {
const result = transformSync(src, {
// ES modules require sourceType='module' but OSS may not always want that
sourceType: 'unambiguous',
...babelConfig,
ast: true,
});

return {ast};
// The result from `transformSync` can be null (if the file is ignored)
if (!result) {
return {ast: null};
}

return {ast: result.ast};
} finally {
process.env.BABEL_ENV = OLD_BABEL_ENV;
}
Expand Down

0 comments on commit 66aa795

Please sign in to comment.