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.
This commit is contained in:
Ben Newman
2018-10-04 10:40:50 -04:00
parent 9dae1a0337
commit bbdf28544f

View File

@@ -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) {