fix(compiler): return full spans for Comment nodes#50855
fix(compiler): return full spans for Comment nodes#50855P4 wants to merge 1 commit intoangular:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
6f190ce to
c62801f
Compare
|
@AndrewKushnir It's been a month, is this still blocked on something internally? |
Change sourceSpan for Comment nodes to cover the whole comment instead of just the opening token. The primary motivation for this is the interaction between ESLint and `@angular-eslint`. ESLint can detect unused `eslint-disable` directives in comments and automatically remove them when running with `--fix`. This is based on ranges computed from AST spans, and as a result does not work inside Angular templates - right now all comments claim to be 4 characters long so only the opening `<!--` is removed.
c62801f to
2ca6d2f
Compare
|
@P4 sorry for the delay. I've rebased the PR on top of the most recent main and restarted tests in Google's codebase (internal-only link). Will let you know if there are any issues identified by those tests. |
|
Caretaker note: presubmit is "green" (only pre-existing failing tests). This PR is ready for merge. |
|
This PR was merged into the repository by commit 6755f53. |
Change sourceSpan for Comment nodes to cover the whole comment instead of just the opening token. The primary motivation for this is the interaction between ESLint and `@angular-eslint`. ESLint can detect unused `eslint-disable` directives in comments and automatically remove them when running with `--fix`. This is based on ranges computed from AST spans, and as a result does not work inside Angular templates - right now all comments claim to be 4 characters long so only the opening `<!--` is removed. PR Close #50855
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Change sourceSpan for Comment nodes to cover the whole comment instead of just the opening token. The primary motivation for this is the interaction between ESLint and `@angular-eslint`. ESLint can detect unused `eslint-disable` directives in comments and automatically remove them when running with `--fix`. This is based on ranges computed from AST spans, and as a result does not work inside Angular templates - right now all comments claim to be 4 characters long so only the opening `<!--` is removed. PR Close angular#50855
Change sourceSpan for Comment nodes to cover the whole comment instead of just the opening token.
The primary motivation for this is the interaction between ESLint and
@angular-eslint. ESLint can detect unusedeslint-disabledirectives in comments and automatically remove them when running with--fix.This is based on ranges computed from AST spans, and as a result does not work inside Angular templates - right now all comments claim to be 4 characters long so only the opening
<!--is removed.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The HTML parser creates
Commentnodes withParseSourceSpantaken directly from the openingCOMMENT_STARTtoken, causing every comment to claim to be 4 characters long -sourceSpan.toString()always returns<!--.What is the new behavior?
The parser computes a new
ParseSourceSpanfrom the start and end tokens, covering the full comment.sourceSpan.toString()returns the whole comment starting with<!--and ending with-->.Does this PR introduce a breaking change?
Not sure honestly. Several tests for
@angular/compilerhad to be updated because they expected a stringified version of the AST node to be<!--, similar issues might occur in any third-party code that uses the AST directly.Other information
Example of what the
@angular-eslintinteraction mentioned above looks like:Since there are no call expressions, linting this file reports an unused directive:
Running with
--fixshould remove the comment entirely, but instead produces the following change:The eslint directive ends up as text inside the component, which is not ideal.