Repository navigation
fix(php) end one-line comments at the closing ?> tag - #4572
Open
clark719664 wants to merge 1 commit into
Open
clark719664 wants to merge 1 commit into
clark719664 wants to merge 1 commit into
Conversation
A `//` or `#` comment in PHP ends at the end of the line or at `?>`, whichever comes first. The grammar used the generic line-comment modes, which run to the end of the line, so in `php-template` a comment right before the closing tag swallowed `?>` and the tag lost its `meta` scope while the markup after it was still treated as PHP. Use comment modes whose end is either end of line or a lookahead for `?>` everywhere php.js used the generic ones, so the tag is highlighted and the template switches back to markup as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Assisted-by: Claude Fable 5.1 (high)
2 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #4569
Changes
In PHP a
//or#comment ends at the end of the line or at the closing?>tag, whichever comes first.php.jsused the genericC_LINE_COMMENT_MODE/HASH_COMMENT_MODE(and oneCOMMENT('//', '$')), which run to the end of the line. Inphp-templatethe closing tag is the end lexeme of the PHP block, so it is handed to thephpsub-language together with the comment and swallowed by it:?>lost itsmetascope, and anything after it on the same line was highlighted as PHP instead of markup. This is common in WordPress templates (// phpcs:ignore ?>).php.jsnow defines its own line-comment modes whose end is/$|(?=\?>)/and uses them in all five places the generic modes were used (top level, the attribute andSUBSTcontents). Block comments are untouched, and#[...]attributes still win over#comments as before.test/markup/php-template/comment-closing-tagcovering//and#comments before?>, a quoted string inside the comment, and a comment with no closing tag on its line.CHANGES.mdentry.Verification (Node 24, Windows):
npm run build && mocha test: the newshould markup comment-closing-tagtest fails onmain(comment span contains?>, nohljs-metafor the tag) and passes with this change; the full suite is 1651 passing, 3 pending.<span class="hljs-comment">// note </span><span class="hljs-meta">?></span>and highlighting returns to markup right after the tag.eslint src/languages/php.jsreports the same 2 errors / 4 warnings as onmain(pre-existingobject-property-newlineon thePREPROCESSORvariants); no new findings.Assisted-by: Claude Fable 5.1 (high). This change was developed with an AI coding assistant (Claude Code) and reviewed by Clark.
Checklist
🤖 Generated with Claude Code