From 3bf433d0c4ec2555abdee98d5641451fed62bb42 Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Fri, 10 Jan 2020 12:12:43 +0100 Subject: [PATCH] fix: raise error when a component/prefab doesn't return anything (#90) --- src/bb-components-build.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bb-components-build.ts b/src/bb-components-build.ts index 0b61779a..d667cfa9 100644 --- a/src/bb-components-build.ts +++ b/src/bb-components-build.ts @@ -49,7 +49,9 @@ const readComponents: () => Promise< try { const code: string = await readFile(`${srcDir}/${file}`, 'utf-8'); // eslint-disable-next-line no-new-func - return Function(`return ${transpile(code)}`)(); + const transpiledFunction = Function(`return ${transpile(code)}`)() + if (!transpiledFunction) throw(new Error('Component doesn\'t return anything')); + return transpiledFunction } catch (error) { error.file = file; throw error; @@ -75,7 +77,9 @@ const readPrefabs: () => Promise = async (): Promise => { try { const code: string = await readFile(`${srcDir}/${file}`, 'utf-8'); // eslint-disable-next-line no-new-func - return Function(`return ${code}`)(); + const transpiledFunction = Function(`return ${code}`)() + if (!transpiledFunction) throw(new Error('Prefab doesn\'t return anything')); + return transpiledFunction } catch (error) { error.file = file; throw error;