Fix: Babel errors in the browser console for user code (#99)

These changes will print out babel errors to the console and will help to not crash the app when bad/unfinished code is in the editor.
This commit is contained in:
Stuart Taylor
2018-05-26 21:32:40 +01:00
committed by Mrugesh Mohapatra
parent d004171593
commit a62e459c2a
5 changed files with 48 additions and 43 deletions

View File

@@ -82,10 +82,12 @@ function tryTransform(wrap = identity) {
return function transformWrappedPoly(source) {
const result = attempt(wrap, source);
if (isError(result)) {
const friendlyError = `${result}`
.match(/[\w\W]+?\n/)[0]
.replace(' unknown:', '');
throw new Error(friendlyError);
console.error(result);
// note(Bouncey): Error thrown here to collapse the build pipeline
// At the minute, it will not bubble up
// We collapse the pipeline so the app doesn't fall over trying
// parse bad code (syntax/type errors etc...)
throw new Error();
}
return result;
};
@@ -110,12 +112,7 @@ export const sassTransformer = cond([
[stubTrue, identity]
]);
export const _transformers = [
// addLoopProtectHtmlJsJsx,
replaceNBSP,
babelTransformer,
sassTransformer
];
export const _transformers = [replaceNBSP, babelTransformer, sassTransformer];
export function applyTransformers(file, transformers = _transformers) {
return transformers.reduce((obs, transformer) => {