diff --git a/src/printers.ts b/src/printers.ts index 78f75c3c..a81e446b 100644 --- a/src/printers.ts +++ b/src/printers.ts @@ -40,6 +40,11 @@ function embed(path: AstPath, options: PluginOptions) { ); const printed = printTemplateTag(content); + + if (options.templateExportDefault && path.parent?.type === 'Program') { + printed.unshift('export ', 'default '); + } + saveCurrentPrintOnSiblingNode(path, printed); return printed; } catch (error) { diff --git a/tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap b/tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap index c10016e6..2393ac58 100644 --- a/tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap +++ b/tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap @@ -170,7 +170,7 @@ exports[`config > templateExportDefault: true > it formats ../cases/gjs/one-line exports[`config > templateExportDefault: true > it formats ../cases/gjs/preceded-by-object.gjs 1`] = ` "const foo = {}; - +export default " `; @@ -276,12 +276,12 @@ export default Route( `; exports[`config > templateExportDefault: true > it formats ../cases/gjs/simple.gjs 1`] = ` -" +"export default " `; exports[`config > templateExportDefault: true > it formats ../cases/gjs/simple-with-tag.gjs 1`] = ` -"