-
-
Notifications
You must be signed in to change notification settings - Fork 52
fix: handle template engine comment syntax #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for template engine comment syntax by introducing an isComment flag to syntax configuration items. This allows template engines like Twig to properly handle comment blocks (e.g., {# ... #}) where inner template syntax should be ignored.
Key Changes:
- Extended syntax configuration to support an
isCommentboolean flag in addition to the existing object-based format - Modified the parser to ignore template syntax inside comment blocks
- Updated TWIG preset to use the new array-based syntax configuration with comment flag
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/template-syntax-parser/lib/types.ts | Added SyntaxConfigItem and SyntaxConfig types to support both object and array-based syntax configurations with optional isComment flag |
| packages/template-syntax-parser/lib/template-syntax-parser.js | Added normalization function to convert both syntax formats and refactored syntax pair sorting into a separate function |
| packages/template-syntax-parser/lib/parser.js | Updated parser logic to track and handle comment syntax, ignoring nested template syntax within comment blocks |
| packages/template-syntax-parser/tests/template-syntax-parser.test.js | Added TWIG configuration and test case for comment syntax handling |
| packages/template-syntax-parser/lib/exports.ts | Exported new SyntaxConfig and SyntaxConfigItem types |
| packages/parser/lib/types.ts | Updated ParserOptions to use the new SyntaxConfig type |
| packages/parser/lib/template-engine-syntax-preset.js | Converted TWIG preset from object to array format with comment flag for {# #} syntax |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| this.syntaxStack.pop(); | ||
| if (this.getPossibleCloseValueOf(top) === syntax.value) { |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stack is being popped before checking if the open and close values match. If they don't match (line 228), the top element has already been removed from the stack on line 227, which could lead to incorrect state. The pop should happen only after confirming the values match, or the logic should handle the mismatch case explicitly.
| this.syntaxStack.pop(); | |
| if (this.getPossibleCloseValueOf(top) === syntax.value) { | |
| if (this.getPossibleCloseValueOf(top) === syntax.value) { | |
| this.syntaxStack.pop(); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #459 +/- ##
=======================================
Coverage 98.71% 98.72%
=======================================
Files 85 85
Lines 2810 2829 +19
Branches 772 773 +1
=======================================
+ Hits 2774 2793 +19
Misses 36 36
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Checklist
Description