Skip to content

Commit 8f01348

Browse files
authored
Merge pull request #422 from ember-tooling/copilot/fix-export-default-issue
Fix `templateExportDefault: true` not adding `export default` to bare module-level templates
2 parents 33088a9 + 3cccc02 commit 8f01348

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/printers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function embed(path: AstPath<NodeType>, options: PluginOptions<NodeType>) {
4040
);
4141

4242
const printed = printTemplateTag(content);
43+
44+
if (options.templateExportDefault && path.parent?.type === 'Program') {
45+
printed.unshift('export ', 'default ');
46+
}
47+
4348
saveCurrentPrintOnSiblingNode(path, printed);
4449
return printed;
4550
} catch (error) {

tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ exports[`config > templateExportDefault: true > it formats ../cases/gjs/one-line
170170
171171
exports[`config > templateExportDefault: true > it formats ../cases/gjs/preceded-by-object.gjs 1`] = `
172172
"const foo = {};
173-
<template>hello</template>
173+
export default <template>hello</template>
174174
"
175175
`;
176176
@@ -276,12 +276,12 @@ export default Route(
276276
`;
277277
278278
exports[`config > templateExportDefault: true > it formats ../cases/gjs/simple.gjs 1`] = `
279-
"<template>what</template>
279+
"export default <template>what</template>
280280
"
281281
`;
282282
283283
exports[`config > templateExportDefault: true > it formats ../cases/gjs/simple-with-tag.gjs 1`] = `
284-
"<template>
284+
"export default <template>
285285
<h1>what</h1>
286286
</template>
287287
@@ -483,7 +483,7 @@ export default class PooComponent extends Component {
483483
`;
484484
485485
exports[`config > templateExportDefault: true > it formats ../cases/gts/issue-191-b.gts 1`] = `
486-
"<template>💩</template>
486+
"export default <template>💩</template>
487487
"
488488
`;
489489

0 commit comments

Comments
 (0)