Shopify / prettier-plugin-liquid

Prettier Liquid/HTML plugin
https://npm.im/@shopify/prettier-plugin-liquid
MIT License
94 stars 15 forks source link

Add support to broken templates in the Liquid parser #177

Closed karreiro closed 1 year ago

karreiro commented 1 year ago

This PR introduces support to broken templates in the Liquid parser. In other words, this PR makes this unit pass:

it('should parse unclosed tables with assignments', () => {
  ast = toLiquidAST(`
    {%- liquid
      assign var1 = product
    -%}
    <table>
      {% tablerow var2 in collections.first.products %}
        {% assign var3 = var2 %}
        {{ var3.title }}
  `);

  expectPath(ast, 'children.0.type').to.eql('LiquidTag');
  expectPath(ast, 'children.0.name').to.eql('liquid');
  expectPath(ast, 'children.0.markup.0.type').to.eql('LiquidTag');
  expectPath(ast, 'children.0.markup.0.name').to.eql('assign');
  expectPath(ast, 'children.0.markup.0.markup.name').to.eql('var1');

  expectPath(ast, 'children.1.type').to.eql('TextNode');
  expectPath(ast, 'children.1.value').to.eql('<table>');

  expectPath(ast, 'children.2.type').to.eql('LiquidTag');
  expectPath(ast, 'children.2.name').to.eql('tablerow');
});