Skip to content

Wrong location information when parsing a[b]=1 #62617

Closed

Description

@fisker

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

compiler

Is this a regression?

Yes

Description

The end location of left is incorrect.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

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

function getFakeSpan(fileName = 'test.html') {
  const file = new ParseSourceFile('', fileName);
  const location = new ParseLocation(file, 0, 0, 0);
  return new ParseSourceSpan(location, location);
}

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

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

console.log(parse('a[b]=1').ast);
Binary {
  span: ParseSpan { start: 0, end: 6 },
  sourceSpan: AbsoluteSourceSpan { start: 0, end: 6 },
  operation: '=',
  left: KeyedRead {
    span: ParseSpan { start: 0, end: 5 },
    sourceSpan: AbsoluteSourceSpan { start: 0, end: 5 },   // <-- Should end at 4, not 5
    receiver: PropertyRead {
      span: [ParseSpan],
      sourceSpan: [AbsoluteSourceSpan],
      nameSpan: [AbsoluteSourceSpan],
      receiver: [ImplicitReceiver],
      name: 'a'
    },
    key: PropertyRead {
      span: [ParseSpan],
      sourceSpan: [AbsoluteSourceSpan],
      nameSpan: [AbsoluteSourceSpan],
      receiver: [ImplicitReceiver],
      name: 'b'
    }
  },
  right: LiteralPrimitive {
    span: ParseSpan { start: 5, end: 6 },
    sourceSpan: AbsoluteSourceSpan { start: 5, end: 6 },
    value: 1
  }
}

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

@angular/compiler 20.1.0

Anything else?

No response

Activity

  1. added
    area: compiler
    on Jul 13, 2025
  2. added this to the needsTriage milestone on Jul 13, 2025
  3. self-assigned this
    on Jul 15, 2025
  4. added
    area: testing
    and removed
    area: testing
    on Jul 15, 2025
  5. added 2 commits that reference this issue on Jul 15, 2025
    4867ecd
    1a693b1
  6. added a commit that references this issue on Jul 15, 2025
    75d2a34
  7. added a commit that references this issue on Jul 15, 2025
    a1e3f2b
  8. angular-automatic-lock-bot commented on Aug 15, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilercompiler: parserstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions