Skip to content

Commit 3cccc02

Browse files
CopilotgitKrystan
andcommitted
Fix templateExportDefault: true not adding export default to bare module-level templates
Co-authored-by: gitKrystan <14152574+gitKrystan@users.noreply.github.com>
1 parent c2ce1c2 commit 3cccc02

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
@@ -475,7 +475,7 @@ export default class PooComponent extends Component {
475475
`;
476476
477477
exports[`config > templateExportDefault: true > it formats ../cases/gts/issue-191-b.gts 1`] = `
478-
"<template>💩</template>
478+
"export default <template>💩</template>
479479
"
480480
`;
481481

0 commit comments

Comments
 (0)