-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Wrong location information when parsing a[b]=1 #62617
Copy link
Copy link
Closed
Labels
area: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilercompiler: parserstate: has PR
Milestone
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilercompiler: parserstate: has PR