core icon indicating copy to clipboard operation
core copied to clipboard

feat(compiler): allow HTML comments in template interpolation syntax

Open GiantAxeWhy opened this issue 2 years ago • 1 comments

feat(compiler): Add support for parsing comments in template syntax

This commit introduces a new feature to the compiler that allows for parsing comments in the template syntax. Comments can now be written using the syntax , which will be treated as comments and not affect the parsing process.

To ensure the functionality of this feature, two new test cases have been added:

Test case: Parsing template with a comment Description: This test verifies that the compiler can successfully parse a template that contains a comment. Steps: Create a template with a comment using the syntax. Invoke the compiler to parse the template. Expected result: The compiler should parse the template without any errors and treat the comment as a comment, not affecting the parsing of other elements.

Test case: Parsing templates with comments and valid content Description: Verify that the compiler can successfully parse templates that contain both comments and valid content, and correctly handle the comment sections. Steps: Create a template that includes both comments and valid content, using the syntax for comments. Invoke the compiler to parse the template. Expected result: The compiler should be able to parse the template without errors, treating the valid content as valid and ignoring the comment sections.

In addition to the test cases, relevant method comments have been added to enhance code readability and maintainability.

GiantAxeWhy avatar Jun 21 '23 09:06 GiantAxeWhy

New features are typically expected to go through an RFC, to allow the community to provide feedback on the proposal. As far as I'm aware there hasn't been an RFC for this feature.

The PR description doesn't really explain the motivation behind the feature, but it seems like #8629 goes into more detail. As noted there, JS /* */ comments already work inside text interpolation, so it's already possible to include comments.

I suspect we'd run into syntax collisions trying to mix HTML comments with JS expressions. For example:

{{ '<!-- I am not a comment -->' }}

Currently Vue will treat that as a string and output the 'comment' as text:

With the changes in this PR, that text is gone:

I'm not sure which would be considered correct.

skirtles-code avatar Jun 22 '24 16:06 skirtles-code

see https://github.com/vuejs/core/issues/8629#issuecomment-1603875593

edison1105 avatar Aug 26 '24 09:08 edison1105