From 1620d4a0af1e6d492aeb96be3914050c8ffe10ef Mon Sep 17 00:00:00 2001 From: Izaak Schroeder Date: Thu, 21 Jun 2018 19:22:54 -0700 Subject: [PATCH] Return more data from `babel.transform`. 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. --- src/transform.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/transform.js b/src/transform.js index d1350321..dee2e3e0 100644 --- a/src/transform.js +++ b/src/transform.js @@ -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;