fix(compiler-cli): more accurate diagnostics for host binding parser errors by crisbeto · Pull Request #58870 · angular/angular · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5114,9 +5114,7 @@ runInEachFileSystem((os: string) => {
);

const errors = env.driveDiagnostics();
expect(getDiagnosticSourceCode(errors[0])).toBe(`{
'(click)': 'act() | pipe',
}`);
expect(getDiagnosticSourceCode(errors[0])).toBe(`'act() | pipe'`);
expect(errors[0].messageText).toContain('/test.ts@7:17');
});

Expand Down Expand Up @@ -5158,10 +5156,12 @@ runInEachFileSystem((os: string) => {
class FooCmp {}
`,
);
const errors = env.driveDiagnostics();
expect(trim(errors[0].messageText as string)).toContain(
const diags = env.driveDiagnostics();
expect(diags.length).toBe(1);
expect(trim(diags[0].messageText as string)).toContain(
'Host binding expression cannot contain pipes',
);
expect(getDiagnosticSourceCode(diags[0])).toBe(`'id | myPipe'`);
});

it('should generate host bindings for directives', () => {
Expand Down
14 changes: 11 additions & 3 deletions packages/compiler/src/parse_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,17 @@ export enum ParseErrorLevel {

export class ParseError {
constructor(
public span: ParseSourceSpan,
public msg: string,
public level: ParseErrorLevel = ParseErrorLevel.ERROR,
/** Location of the error. */
readonly span: ParseSourceSpan,
/** Error message. */
readonly msg: string,
/** Severity level of the error. */
readonly level: ParseErrorLevel = ParseErrorLevel.ERROR,
/**
* Error that caused the error to be surfaced. For example, an error in a sub-expression that
* couldn't be parsed. Not guaranteed to be defined, but can be used to provide more context.
*/
readonly relatedError?: unknown,
) {}

contextualMessage(): string {
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler/src/template_parser/binding_parser.ts