Skip to content

Commit d2f57be

Browse files
committed
Ensure co-located templates with re-exported class do not throw an error
1 parent 2479dec commit d2f57be

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/colocated-broccoli-plugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
150150
}
151151
);
152152

153-
if (hasTemplate && !jsContents.includes('export default')) {
153+
if (hasTemplate && jsContents.includes('export { default }')) {
154+
jsContents = jsContents.replace('export { default }', "import Component");
155+
jsContents += '\n\nexport default class extends Component {}';
156+
} else if (hasTemplate && !jsContents.includes('export default')) {
154157
let message = `\`${relativePath}\` does not contain a \`default export\`. Did you forget to export the component class?`;
155158
jsContents = `${jsContents}\nthrow new Error(${JSON.stringify(message)});`;
156159
prefix = '';

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,62 @@ describe('ColocatedTemplateCompiler', function () {
186186
);
187187
});
188188

189+
it('works for re-exported component with a 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+
import { hbs } from 'ember-cli-htmlbars';
214+
const __COLOCATED_TEMPLATE__ = hbs("{{yield}}", {"contents":"{{yield}}","moduleName":"app-name-here/components/foo.hbs","parseOptions":{"srcName":"app-name-here/components/foo.hbs"}});
215+
import Component from 'some-place';
216+
217+
export default class extends Component {}
218+
`,
219+
},
220+
templates: {
221+
'application.hbs': '{{outlet}}',
222+
},
223+
},
224+
});
225+
226+
await output.build();
227+
228+
assert.deepStrictEqual(output.changes(), {}, 'NOOP update has no changes');
229+
230+
input.write({
231+
'app-name-here': {
232+
'router.js': '// other stuff here',
233+
},
234+
});
235+
236+
await output.build();
237+
238+
assert.deepStrictEqual(
239+
output.changes(),
240+
{ 'app-name-here/router.js': 'change' },
241+
'has only related changes'
242+
);
243+
});
244+
189245
it('works for typescript component class with template', async function () {
190246
input.write({
191247
'app-name-here': {

0 commit comments

Comments
 (0)