@@ -51,7 +51,7 @@ export async function printTemplateContent(
5151 ) => Promise < AST . builders . Doc > ,
5252 options : PluginOptions ,
5353) : Promise < AST . builders . Doc > {
54- return await textToDoc ( text . trim ( ) , {
54+ return textToDoc ( text . trim ( ) , {
5555 ...options ,
5656 parser : 'glimmer' ,
5757 singleQuote : options . templateSingleQuote ?? options . singleQuote ,
@@ -70,9 +70,33 @@ export async function printTemplateContent(
7070export function printTemplateTag (
7171 content : AST . builders . Doc ,
7272) : AST . builders . Doc [ ] {
73- const contents = flattenDoc ( content ) ;
73+ const strings : string [ ] = [ ] ;
7474
75- const useHardline = contents . some (
75+ // Single pass: collect strings for the hardline/softline decision and
76+ // simultaneously force any group that contains an HBS comment
77+ // ({{! ... }} or {{!-- ... --}}) to always expand. This prevents the
78+ // Glimmer printer from collapsing a component tag onto one line when a
79+ // Glint annotation comment appears between its attributes.
80+ const processedContent = AST . utils . mapDoc ( content , ( node ) => {
81+ if ( typeof node === 'string' ) {
82+ strings . push ( node ) ;
83+ } else if (
84+ node &&
85+ typeof node === 'object' &&
86+ 'type' in node &&
87+ node . type === 'group'
88+ ) {
89+ const groupStrings = flattenDoc (
90+ ( node as { contents : AST . builders . Doc } ) . contents ,
91+ ) ;
92+ if ( groupStrings . some ( ( s ) => s . startsWith ( '{{!' ) || s . trim ( ) === '!' ) ) {
93+ return { ...node , break : true } ;
94+ }
95+ }
96+ return node ;
97+ } ) ;
98+
99+ const useHardline = strings . some (
76100 ( c ) =>
77101 // contains angle bracket tag
78102 / < .+ > / . test ( c ) ||
@@ -83,7 +107,7 @@ export function printTemplateTag(
83107
84108 const doc = [
85109 TEMPLATE_TAG_OPEN ,
86- AST . builders . indent ( [ line , AST . builders . group ( content ) ] ) ,
110+ AST . builders . indent ( [ line , AST . builders . group ( processedContent ) ] ) ,
87111 line ,
88112 TEMPLATE_TAG_CLOSE ,
89113 ] ;
0 commit comments