-
-
Notifications
You must be signed in to change notification settings - Fork 52
Description
The @html-eslint/parser throws a parsing error when Twig syntax delimiters ({{, {%) appear inside Twig comments ({# #}). The parser incorrectly interprets these nested tokens as the start of new template expressions instead of treating them as part of the comment content.
Expected Behavior
Twig comments ({# ... #}) should be treated as complete units, with their content ignored during parsing. Any template syntax tokens inside comments should not be parsed as actual template expressions.
Actual Behavior
The parser throws: Parsing error: Expecting "#}", but found "{%" at (line, column)
To Reproduce
Minimal example:
{# {% include "template.twig" %} #}ESLint Configuration:
// Same as https://github.com/yeonjuan/html-eslint/blob/main/packages/parser/lib/template-engine-syntax-preset.js
parserOptions: {
templateEngineSyntax: {
"{{": "}}",
"{%": "%}",
"{#": "#}"
}
}Additional Notes
This is a common use case when temporarily commenting out template code during development. Other valid examples that would fail:
{# TODO: {{ variable }} needs to be escaped #}
{# Disabled: {% for item in items %}...{% endfor %} #}Looking at the template-engine-syntax-preset.js, the current implementation appears to treat all delimiter pairs independently:
const TWIG = {
"{{": "}}",
"{%": "%}",
"{#": "#}",
};This doesn't account for the fact that Twig comments should have higher precedence and their content should be completely ignored, including any nested template syntax.
Suggested Fix
The parser should recognize when it's inside a comment block and skip all content until the matching closing delimiter, similar to how HTML comments work. Comment delimiters should take precedence over other template syntax.