From bbdf28544f3bae08bfdd01e58ebb37ff04c4b521 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 4 Oct 2018 10:40:50 -0400 Subject: [PATCH] Report Babel transform errors without crashing the build process. As reported by @mariusrak here: https://github.com/meteor/meteor/issues/10220#issuecomment-425244894 Only errors thrown by @babel/parser have the e.loc property. Other errors thrown by Babel transforms do not have e.loc, but do (usually) have line number information embedded in e.message. Either way, it's better to use inputFile.error than to throw the error, since throwing here crashes the build process. --- packages/babel-compiler/babel-compiler.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/babel-compiler/babel-compiler.js b/packages/babel-compiler/babel-compiler.js index 1ed3115914..6ae5146c4e 100644 --- a/packages/babel-compiler/babel-compiler.js +++ b/packages/babel-compiler/babel-compiler.js @@ -125,16 +125,19 @@ BCp.processOneFileForTarget = function (inputFile, source) { }); } catch (e) { if (e.loc) { + // Error is from @babel/parser. inputFile.error({ message: e.message, line: e.loc.line, column: e.loc.column, }); - - return null; + } else { + // Error is from a Babel transform, with line/column information + // embedded in e.message. + inputFile.error(e); } - throw e; + return null; } if (isMeteorPre144) {