Skip to content

Commit

Permalink
Properly handle babel ignored files, returning only the contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Old committed Apr 27, 2017
1 parent 200df00 commit a6f8cb3
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions packager/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,31 @@ function transform(src, filename, options) {

try {
const babelConfig = buildBabelConfig(filename, options);
const {ast} = babel.transform(src, babelConfig);
const result = generate(ast, {
comments: false,
compact: false,
filename,
sourceFileName: filename,
sourceMaps: true,
}, src);

return {
ast,
code: result.code,
filename,
map: options.generateSourceMaps ? result.map : result.rawMappings.map(compactMapping),
};
const {ast, ignored} = babel.transform(src, babelConfig);

if (ignored) {
return {
ast: null,
code: src,
filename,
map: null
};
} else {
const result = generate(ast, {
comments: false,
compact: false,
filename,
sourceFileName: filename,
sourceMaps: true,
}, src);

return {
ast,
code: result.code,
filename,
map: options.generateSourceMaps ? result.map : result.rawMappings.map(compactMapping),
};
}
} finally {
process.env.BABEL_ENV = OLD_BABEL_ENV;
}
Expand Down

0 comments on commit a6f8cb3

Please sign in to comment.