Skip to content

Commit 8eb78cd

Browse files
authored
Merge pull request #773 from robinborst95/fix/co-located-template-with-re-exported-class-error-message
Adjust error message for re-exported class when it has a co-located template
2 parents 2479dec + d5889af commit 8eb78cd

3 files changed

Lines changed: 61 additions & 5 deletions

File tree

lib/colocated-broccoli-plugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
150150
}
151151
);
152152

153-
if (hasTemplate && !jsContents.includes('export default')) {
154-
let message = `\`${relativePath}\` does not contain a \`default export\`. Did you forget to export the component class?`;
153+
if (hasTemplate && jsContents.includes('export { default }')) {
154+
let message = `\`${backingClassPath}\` contains an \`export { default }\` re-export, but it has a co-located template. You must explicitly extend the component to assign it a different template.`;
155+
jsContents = `${jsContents}\nthrow new Error(${JSON.stringify(message)});`;
156+
prefix = '';
157+
} else if (hasTemplate && !jsContents.includes('export default')) {
158+
let message = `\`${backingClassPath}\` does not contain a \`default export\`. Did you forget to export the component class?`;
155159
jsContents = `${jsContents}\nthrow new Error(${JSON.stringify(message)});`;
156160
prefix = '';
157161
}

node-tests/colocated-broccoli-plugin-test.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,58 @@ describe('ColocatedTemplateCompiler', function () {
186186
);
187187
});
188188

189+
it('emits an error for re-exported components with a different template', async function () {
190+
input.write({
191+
'app-name-here': {
192+
'router.js': '// stuff here',
193+
components: {
194+
'foo.hbs': `{{yield}}`,
195+
'foo.js': `export { default } from 'some-place';`,
196+
},
197+
templates: {
198+
'application.hbs': `{{outlet}}`,
199+
},
200+
},
201+
});
202+
203+
let tree = new ColocatedTemplateCompiler(input.path());
204+
205+
output = createBuilder(tree);
206+
await output.build();
207+
208+
assert.deepStrictEqual(output.read(), {
209+
'app-name-here': {
210+
'router.js': '// stuff here',
211+
components: {
212+
'foo.js': stripIndent`
213+
export { default } from 'some-place';\nthrow new Error(\"\`app-name-here/components/foo.js\` contains an \`export { default }\` re-export, but it has a co-located template. You must explicitly extend the component to assign it a different template.\");
214+
`,
215+
},
216+
templates: {
217+
'application.hbs': '{{outlet}}',
218+
},
219+
},
220+
});
221+
222+
await output.build();
223+
224+
assert.deepStrictEqual(output.changes(), {}, 'NOOP update has no changes');
225+
226+
input.write({
227+
'app-name-here': {
228+
'router.js': '// other stuff here',
229+
},
230+
});
231+
232+
await output.build();
233+
234+
assert.deepStrictEqual(
235+
output.changes(),
236+
{ 'app-name-here/router.js': 'change' },
237+
'has only related changes'
238+
);
239+
});
240+
189241
it('works for typescript component class with template', async function () {
190242
input.write({
191243
'app-name-here': {
@@ -500,7 +552,7 @@ describe('ColocatedTemplateCompiler', function () {
500552
'app-name-here': {
501553
components: {
502554
'foo.js': stripIndent`
503-
export function whatever() {}\nthrow new Error("\`app-name-here/components/foo.hbs\` does not contain a \`default export\`. Did you forget to export the component class?");
555+
export function whatever() {}\nthrow new Error("\`app-name-here/components/foo.js\` does not contain a \`default export\`. Did you forget to export the component class?");
504556
`,
505557
},
506558
},

node-tests/colocated-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ describe('Colocation - Broccoli + Babel Integration (modules API: true)', functi
407407
'app-name-here': {
408408
components: {
409409
'foo.js': stripIndent`
410-
export function whatever() {}\nthrow new Error("\`app-name-here/components/foo.hbs\` does not contain a \`default export\`. Did you forget to export the component class?");
410+
export function whatever() {}\nthrow new Error("\`app-name-here/components/foo.js\` does not contain a \`default export\`. Did you forget to export the component class?");
411411
`,
412412
},
413413
},
@@ -797,7 +797,7 @@ describe('Colocation - Broccoli + Babel Integration (modules API: false)', funct
797797
'app-name-here': {
798798
components: {
799799
'foo.js': stripIndent`
800-
export function whatever() {}\nthrow new Error("\`app-name-here/components/foo.hbs\` does not contain a \`default export\`. Did you forget to export the component class?");
800+
export function whatever() {}\nthrow new Error("\`app-name-here/components/foo.js\` does not contain a \`default export\`. Did you forget to export the component class?");
801801
`,
802802
},
803803
},

0 commit comments

Comments
 (0)