Fix templateExportDefault: true not adding export default to bare module-level templates#422
Merged
evoactivity merged 2 commits intomainfrom Apr 17, 2026
Merged
Conversation
…ule-level templates Co-authored-by: gitKrystan <14152574+gitKrystan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [Bug] Fix templateExportDefault not adding export default correctly
Fix Mar 13, 2026
templateExportDefault: true not adding export default to bare module-level templates
Member
|
This looks ok, @gitKrystan any reason to keep this a draft or can we merge to get it in next release? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bare
<template>tags in.gjsfiles (or.gtsfiles without a TypeScript type annotation) were not gettingexport defaultprepended whentemplateExportDefault: true, leaving the file unchanged.Root Cause
The preprocessing converts a bare
<template>at module level into aBlockStatementdirectly insideProgram. The existingexport defaultinjection logic lives inprint()and only fires for nodes matched byisGlimmerTemplateParent— which coversExportDefaultDeclarationand TypeScriptExpressionStatement > TSAsExpression > template, but not aBlockStatementthat is a direct child ofProgram. Becauseembed()handles these template nodes beforeprint()ever sees them, the injection was silently skipped.Fix
Added the
export defaultinjection intoembed(), where bare module-level templates are actually handled:The
path.parent?.type === 'Program'guard ensures only truly bare module-level templates are affected — templates nested insideExportDefaultDeclaration,VariableDeclarator, class bodies, etc. are untouched.Snapshot Updates
Four snapshots corrected in the
templateExportDefault: trueconfig suite:gjs/simple.gjs<template>what</template>export default <template>what</template>gjs/simple-with-tag.gjsexport default;const-assigned templates unaffectedgjs/preceded-by-object.gjsexport defaultgts/issue-191-b.gts<template>💩</template>export default <template>💩</template>Original prompt
templateExportDefault: truedoes not addexport defaultcorrectly #402💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.