Skip to content

Commit

Permalink
Better error for missing default export
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Aug 13, 2019
1 parent a640658 commit 4c6017b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ class ColocatedTemplateProcessor extends Plugin {
// add the template, call setComponentTemplate

jsContents = fs.readFileSync(path.join(this.inputPaths[0], possibleJSPath), { encoding: 'utf8' });
jsContents = `${jsContents.replace('export default', 'const CLASS =')}\n;

if (jsContents.includes('export default')) {
jsContents = jsContents.replace('export default', 'const CLASS =');
} else {
let message = `${filePath}\` does not contain a \`default export\`. Did you forget to export the component class?`;
jsContents = `${jsContents}\nthrow new Error(${JSON.stringify(message)})`;
}

jsContents = `${jsContents}
const setComponentTemplate = Ember._setComponentTemplate;
const TEMPLATE = ${this.options.precompile(templateContents)};
export default setComponentTemplate(TEMPLATE, CLASS);`;
Expand Down

0 comments on commit 4c6017b

Please sign in to comment.