@@ -637,6 +637,25 @@ 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 %}{% echo "Hello content" %}{% 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+ expectPath ( ast , 'children.0.children.0.type' ) . to . eql ( 'LiquidTag' ) ;
650+ expectPath ( ast , 'children.0.children.0.name' ) . to . eql ( 'echo' ) ;
651+ expectPath ( ast , 'children.0.children.0.markup.type' ) . to . eql ( 'LiquidVariable' ) ;
652+ expectPath ( ast , 'children.0.children.0.markup.expression.value' ) . to . eql ( 'Hello content' ) ;
653+
654+ expectPosition ( ast , 'children.0' ) ;
655+ expectPosition ( ast , 'children.0.markup' ) ;
656+ }
657+ } ) ;
658+
640659 describe ( 'Case: content_for' , ( ) => {
641660 it ( 'should parse content_for tags with no arguments' , ( ) => {
642661 for ( const { toAST, expectPath, expectPosition } of testCases ) {
@@ -1230,6 +1249,25 @@ describe('Unit: Stage 2 (AST)', () => {
12301249 expectPosition ( ast , 'children.0.body.nodes.2' ) . toEqual ( '}' ) ;
12311250 expectPosition ( ast , 'children.0' ) ;
12321251 } ) ;
1252+
1253+ it ( 'should parse snippet blocks with HTML content' , ( ) => {
1254+ ast = toLiquidHtmlAST (
1255+ `{% snippet hello_snippet %}<div class="component"><p>Hello</p></div>{% endsnippet %}` ,
1256+ ) ;
1257+ expectPath ( ast , 'children.0.type' ) . to . eql ( 'LiquidTag' ) ;
1258+ expectPath ( ast , 'children.0.name' ) . to . eql ( 'snippet' ) ;
1259+ expectPath ( ast , 'children.0.markup.type' ) . to . eql ( 'VariableLookup' ) ;
1260+ expectPath ( ast , 'children.0.markup.name' ) . to . eql ( 'hello_snippet' ) ;
1261+ expectPath ( ast , 'children.0.children.0.type' ) . to . eql ( 'HtmlElement' ) ;
1262+ expectPath ( ast , 'children.0.children.0.name.0.value' ) . to . eql ( 'div' ) ;
1263+ expectPath ( ast , 'children.0.children.0.attributes.0.name.0.value' ) . to . eql ( 'class' ) ;
1264+ expectPath ( ast , 'children.0.children.0.attributes.0.value.0.value' ) . to . eql ( 'component' ) ;
1265+ expectPath ( ast , 'children.0.children.0.children.0.type' ) . to . eql ( 'HtmlElement' ) ;
1266+ expectPath ( ast , 'children.0.children.0.children.0.name.0.value' ) . to . eql ( 'p' ) ;
1267+ expectPath ( ast , 'children.0.children.0.children.0.children.0.type' ) . to . eql ( 'TextNode' ) ;
1268+ expectPath ( ast , 'children.0.children.0.children.0.children.0.value' ) . to . eql ( 'Hello' ) ;
1269+ expectPosition ( ast , 'children.0' ) ;
1270+ } ) ;
12331271 } ) ;
12341272
12351273 describe ( 'Unit: toLiquidAST(text)' , ( ) => {
0 commit comments