Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure co-located templates with re-exported class do not throw an error #772

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/colocated-broccoli-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
}
);

if (hasTemplate && !jsContents.includes('export default')) {
if (hasTemplate && jsContents.includes('export { default }')) {
jsContents = jsContents.replace('export { default }', 'import __Component');
jsContents += '\n\nexport default class extends __Component {}';
} else if (hasTemplate && !jsContents.includes('export default')) {
let message = `\`${relativePath}\` does not contain a \`default export\`. Did you forget to export the component class?`;
jsContents = `${jsContents}\nthrow new Error(${JSON.stringify(message)});`;
prefix = '';
Expand Down
56 changes: 56 additions & 0 deletions node-tests/colocated-broccoli-plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,62 @@ describe('ColocatedTemplateCompiler', function () {
);
});

it('works for re-exported component with a template', async function () {
input.write({
'app-name-here': {
'router.js': '// stuff here',
components: {
'foo.hbs': `{{yield}}`,
'foo.js': `export { default } from 'some-place';`,
},
templates: {
'application.hbs': `{{outlet}}`,
},
},
});

let tree = new ColocatedTemplateCompiler(input.path());

output = createBuilder(tree);
await output.build();

assert.deepStrictEqual(output.read(), {
'app-name-here': {
'router.js': '// stuff here',
components: {
'foo.js': stripIndent`
import { hbs } from 'ember-cli-htmlbars';
const __COLOCATED_TEMPLATE__ = hbs("{{yield}}", {"contents":"{{yield}}","moduleName":"app-name-here/components/foo.hbs","parseOptions":{"srcName":"app-name-here/components/foo.hbs"}});
import __Component from 'some-place';

export default class extends __Component {}
`,
},
templates: {
'application.hbs': '{{outlet}}',
},
},
});

await output.build();

assert.deepStrictEqual(output.changes(), {}, 'NOOP update has no changes');

input.write({
'app-name-here': {
'router.js': '// other stuff here',
},
});

await output.build();

assert.deepStrictEqual(
output.changes(),
{ 'app-name-here/router.js': 'change' },
'has only related changes'
);
});

it('works for typescript component class with template', async function () {
input.write({
'app-name-here': {
Expand Down