Content-Length: 343441 | pFad | https://github.com/angular/angular/commit/2d51a203dc87d6d880c3cf6d68bf8590f5dd689b

27 fix(compiler-cli): wrong event name for host listener decorators (#60… · angular/angular@2d51a20 · GitHub
Skip to content

Commit 2d51a20

Browse files
crisbetopkozlowski-opensource
authored andcommitted
fix(compiler-cli): wrong event name for host listener decorators (#60460)
Fixes that when generating the type checking code `@HostListener`, we were using the method name instead of the event name. PR Close #60460
1 parent c7cacbf commit 2d51a20

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/compiler-cli/src/ngtsc/typecheck/src/host_bindings.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ function createNodeFromListenerDecorator(
341341
// manually here. Note that we use a dummy span with -1/-1 as offsets, because it isn't
342342
// used for type checking and constructing it accurately would take some effort.
343343
const span = new ParseSpan(-1, -1);
344-
const [name, phase] = method.name.text.split('.');
345344
const argNodes: AST[] = [];
346345
const methodStart = method.getStart();
347346
const methodReceiver = new ThisReceiver(span, new AbsoluteSourceSpan(methodStart, methodStart));
@@ -387,17 +386,19 @@ function createNodeFromListenerDecorator(
387386
}
388387

389388
const callNode = new Call(span, nameSpan, receiver, argNodes, span);
389+
const eventNameNode = args[0];
390+
const [eventName, phase] = eventNameNode.text.split('.');
390391

391392
listeners.push(
392393
new TmplAstBoundEvent(
393-
name,
394-
name.startsWith('@') ? ParsedEventType.Animation : ParsedEventType.Regular,
394+
eventName,
395+
eventName.startsWith('@') ? ParsedEventType.Animation : ParsedEventType.Regular,
395396
callNode,
396397
null,
397398
phase,
398399
createSourceSpan(decorator),
399400
createSourceSpan(decorator),
400-
createStaticExpressionSpan(method.name),
401+
createStaticExpressionSpan(eventNameNode),
401402
),
402403
);
403404
}

packages/compiler-cli/test/ngtsc/host_bindings_type_check_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ runInEachFileSystem(() => {
506506
const diags = env.driveDiagnostics();
507507
expect(diags.length).toBe(1);
508508
expect(diags[0].messageText).toBe(
509-
`Argument of type 'Event' is not assignable to parameter of type 'string'.`,
509+
`Argument of type 'MouseEvent' is not assignable to parameter of type 'string'.`,
510510
);
511511
expect(getDiagnosticSourceCode(diags[0])).toBe('$event');
512512
});

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/commit/2d51a203dc87d6d880c3cf6d68bf8590f5dd689b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy