Skip to content

Template parser produces wrong locations for HTML self-closing tags #39148

@AlexanderFSP

Description

@AlexanderFSP

🐞 bug report

Affected Package

The issue is caused by package @angular/compiler

Is this a regression?

No

Description

Template parser from @angular/compiler package produces wrong locations for HTML self-closing tags.
Here the initial simple template:

  <input type="text" />


        <span>
    
    </span>

And if we pass this template to the exported parseTemplate function from @angular/compiler package we can see that sourceSpan.end for input node located in front of the opening span tag.

{
  "nodes": [
    {
      "name": "input",
      "sourceSpan": {
        "start": {
          "offset": 3,
          "line": 1,
          "col": 2
        },
        "end": {
          "offset": 35,
          "line": 4,
          "col": 8
        }
      },
      ...,
      "endSourceSpan": {
        "start": {
          "offset": 3,
          "line": 1,
          "col": 2
        },
        "end": {
          "offset": 35,
          "line": 4,
          "col": 8
        }
      }
    },
    {
      "name": "span",
      "sourceSpan": {
        "start": {
          "offset": 35,
          "line": 4,
          "col": 8
        },
        ...
      },
      ...
    }
  ]
}

But from my point of view (let's say "expected result") sourceSpan.end should be pointed after the second input field's angle bracket and shouldn't include spaces and linebreaks.

🔬 Minimal Reproduction

https://stackblitz.com/edit/ng-tpl-parser-self-closing-tags?file=index.ts

🔥 Exception or Error

🌍 Your Environment

Angular Version:

@angular/compiler@10.1.4

Anything else relevant?
This issue produces some difficulties for static template code analysis (in this case I would like to mention https://github.com/angular-eslint/angular-eslint which uses @angular/compiler to generate AST). And here you can see the issue that produces by the wrong sourceSpan location.

image

Metadata

Metadata

Assignees

Labels

P5The team acknowledges the request but does not plan to address it, it remains open for discussionarea: compilerIssues related to `ngc`, Angular's template compilercompiler: parserstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions