@@ -637,6 +637,31 @@ describe('Unit: Stage 2 (AST)', () => {
637637 } ) ;
638638 } ) ;
639639
640+ it ( 'should parse snippet blocks' , ( ) => {
641+ for ( const { toAST, expectPath, expectPosition } of testCases ) {
642+ ast = toAST ( `{% snippet hello_snippet %}<div>Hello content</div>{% endsnippet %}` ) ;
643+ expectPath ( ast , 'children.0' ) . to . exist ;
644+ expectPath ( ast , 'children.0.type' ) . to . eql ( 'LiquidTag' ) ;
645+ expectPath ( ast , 'children.0.name' ) . to . eql ( 'snippet' ) ;
646+ expectPath ( ast , 'children.0.markup.type' ) . to . eql ( 'VariableLookup' ) ;
647+ expectPath ( ast , 'children.0.markup.name' ) . to . eql ( 'hello_snippet' ) ;
648+
649+ // toLiquidHtmlAST parses HTML, toLiquidAST treats it as text
650+ if ( toAST === toLiquidHtmlAST ) {
651+ expectPath ( ast , 'children.0.children.0.type' ) . to . eql ( 'HtmlElement' ) ;
652+ expectPath ( ast , 'children.0.children.0.name.0.value' ) . to . eql ( 'div' ) ;
653+ expectPath ( ast , 'children.0.children.0.children.0.type' ) . to . eql ( 'TextNode' ) ;
654+ expectPath ( ast , 'children.0.children.0.children.0.value' ) . to . eql ( 'Hello content' ) ;
655+ } else {
656+ expectPath ( ast , 'children.0.children.0.type' ) . to . eql ( 'TextNode' ) ;
657+ expectPath ( ast , 'children.0.children.0.value' ) . to . eql ( '<div>Hello content</div>' ) ;
658+ }
659+
660+ expectPosition ( ast , 'children.0' ) ;
661+ expectPosition ( ast , 'children.0.markup' ) ;
662+ }
663+ } ) ;
664+
640665 describe ( 'Case: content_for' , ( ) => {
641666 it ( 'should parse content_for tags with no arguments' , ( ) => {
642667 for ( const { toAST, expectPath, expectPosition } of testCases ) {
@@ -1230,6 +1255,23 @@ describe('Unit: Stage 2 (AST)', () => {
12301255 expectPosition ( ast , 'children.0.body.nodes.2' ) . toEqual ( '}' ) ;
12311256 expectPosition ( ast , 'children.0' ) ;
12321257 } ) ;
1258+
1259+ it ( 'should parse snippet blocks with HTML content' , ( ) => {
1260+ ast = toLiquidHtmlAST ( `{% snippet hello_snippet %}<div class="component"><p>Hello</p></div>{% endsnippet %}` ) ;
1261+ expectPath ( ast , 'children.0.type' ) . to . eql ( 'LiquidTag' ) ;
1262+ expectPath ( ast , 'children.0.name' ) . to . eql ( 'snippet' ) ;
1263+ expectPath ( ast , 'children.0.markup.type' ) . to . eql ( 'VariableLookup' ) ;
1264+ expectPath ( ast , 'children.0.markup.name' ) . to . eql ( 'hello_snippet' ) ;
1265+ expectPath ( ast , 'children.0.children.0.type' ) . to . eql ( 'HtmlElement' ) ;
1266+ expectPath ( ast , 'children.0.children.0.name.0.value' ) . to . eql ( 'div' ) ;
1267+ expectPath ( ast , 'children.0.children.0.attributes.0.name.0.value' ) . to . eql ( 'class' ) ;
1268+ expectPath ( ast , 'children.0.children.0.attributes.0.value.0.value' ) . to . eql ( 'component' ) ;
1269+ expectPath ( ast , 'children.0.children.0.children.0.type' ) . to . eql ( 'HtmlElement' ) ;
1270+ expectPath ( ast , 'children.0.children.0.children.0.name.0.value' ) . to . eql ( 'p' ) ;
1271+ expectPath ( ast , 'children.0.children.0.children.0.children.0.type' ) . to . eql ( 'TextNode' ) ;
1272+ expectPath ( ast , 'children.0.children.0.children.0.children.0.value' ) . to . eql ( 'Hello' ) ;
1273+ expectPosition ( ast , 'children.0' ) ;
1274+ } ) ;
12331275 } ) ;
12341276
12351277 describe ( 'Unit: toLiquidAST(text)' , ( ) => {
0 commit comments