Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 23, 2025

Fixes the issue where lines starting with # inside {% liquid %} blocks were not treated as comments, causing the parser to skip subsequent statements.

Problem

Previously, when using # comments inside {% liquid %} blocks, the parser would stop processing statements after encountering the comment line:

{% liquid
  assign name = 'John'
  # very important information
  assign name = 'Jenna'
  echo name
%}

Expected output: Jenna
Actual output: `` (empty)

The assign name = 'Jenna' and echo name statements were being skipped.

Solution

Modified the LiquidTag parser to recognize # as a valid tag identifier in addition to regular identifiers. This allows the parser to properly handle # comments within liquid blocks by leveraging the existing inline comment infrastructure.

The key change is in FluidParser.cs, where the liquid tag parser now uses:

OneOf(Terms.Char('#').Then(x => "#"), Identifier).Switch(...)

This allows # to be recognized and processed by the InlineCommentTag handler, which correctly consumes the rest of the line as a comment (since inside liquid blocks, newlines act as tag terminators).

Testing

Added comprehensive test coverage:

  • Basic # comment functionality
  • Multiple comments in a single liquid block
  • Empty comments (# with no content)
  • Comments at the beginning and end of liquid blocks

All existing tests (1206) continue to pass, confirming backward compatibility.

Examples

Now works as expected:

{% liquid
  # required args:
  assign product = 'MyProduct'

  # optional args:
  assign should_show_border = true
  assign should_show_cursor = true
  
  echo product
%}

Output: MyProduct

Regular inline comments outside liquid blocks continue to work:

{% # this is an inline comment %}
Hello World

Output: Hello World

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow # style comments in the liquid tag</issue_title>
<issue_description>Inside {% liquid %} blocks, lines starting with # are not treated as comments. Instead, the parser skips the following statements.

Example:

{% liquid
  assign name = 'John'
  # very important information
  assign name = 'Jenna'
  echo name
%}

Observed behavior:

assign name = 'Jenna' is skipped because the parser treats the # line incorrectly.

Expected behavior:

Lines starting with # inside {% liquid %} should be treated as comments. All other statements should execute normally.

Goal:
Extend the parser so that both {% # comment %} and inline # comments inside {% liquid %} blocks are fully supported, aligning with standard Liquid behavior.

The example from the initial description:

{% liquid
  # required args:
  assign product = product

  # optional args:
  assign should_show_border = should_show_border | default: true
  assign should_show_cursor = should_show_cursor | default: true
%}

Originally posted by @MihaxXx in #833 (comment)</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #834


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Extend parser to support comments in liquid tags Add support for # style comments in {% liquid %} blocks Oct 23, 2025
Copilot AI requested a review from sebastienros October 23, 2025 13:47
Copilot finished work on behalf of sebastienros October 23, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow # style comments in the liquid tag

2 participants