Skip to content

Commit

Permalink
Return more data from babel.transform. (#629)
Browse files Browse the repository at this point in the history
Previous code only returns an object of the shape `{ code, map, metadata }` which prevents accessing things like the AST when `babel` is configured to output it. This change allows access to more things that `babel` spits out.
  • Loading branch information
izaakschroeder authored and loganfsmyth committed Jun 22, 2018
1 parent 1a7a440 commit a2d86d9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/transform.js
Expand Up @@ -14,13 +14,18 @@ module.exports = async function(source, options) {

if (!result) return null;

const { code, map, metadata } = result;
// We don't return the full result here because some entries are not
// really serializable. For a full list of properties see here:
// https://github.com/babel/babel/blob/master/packages/babel-core/src/transformation/index.js
// For discussion on this topic see here:
// https://github.com/babel/babel-loader/pull/629
const { ast, code, map, metadata, sourceType } = result;

if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
map.sourcesContent = [source];
}

return { code, map, metadata };
return { ast, code, map, metadata, sourceType };
};

module.exports.version = babel.version;

0 comments on commit a2d86d9

Please sign in to comment.