Skip to content

Wrong location information in TemplateLiteralElement #60320

Description

@fisker

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

Location information for TemplateLiteralElement are wrong.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

import { Lexer, Parser } from '@angular/compiler';

const parse = (text) => {
  const lexer = new Lexer();
  const parser = new Parser(lexer);

  return parser.parseBinding(text, '', 0);
};

console.log(parse('`a${b}c`').ast.elements);




[
  TemplateLiteralElement {
    span: ParseSpan { start: 0, end: 0 },
    sourceSpan: AbsoluteSourceSpan { start: 0, end: 0 },
    text: 'a'
  },
  TemplateLiteralElement {
    span: ParseSpan { start: 6, end: 6 },
    sourceSpan: AbsoluteSourceSpan { start: 6, end: 6 },
    text: 'c'
  }
]

Please provide the environment you discovered this bug in (run ng version)

@angular/compiler 19.2.1

Anything else?

I'm adding support to Prettier prettier/prettier#17238 .

In angular-estree-parser which used in Prettier, I'm locating the TemplateLiteralElement by the sibling expressions.

https://github.com/prettier/angular-estree-parser/blob/72bfe63e0f237527726819a0401b9be5c26071f8/src/transform-node.ts#L558-L575

Correct location information can help us get ride of this hack.

Related issue #60319

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions