Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 14b492d

Browse filesBrowse files
crisbetoAndrewKushnir
authored andcommitted
fix(compiler): do not error if $any is used inside a listener (#43866)
Fixes that `$any` casts weren't being converted to statements inside listeners which resulted in a compiler error. Fixes #43841. PR Close #43866
1 parent cbde9ed commit 14b492d
Copy full SHA for 14b492d

File tree

Expand file treeCollapse file tree

2 files changed

+21
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-2
lines changed

‎packages/compiler-cli/test/ngtsc/ngtsc_spec.ts

Copy file name to clipboardExpand all lines: packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,6 +3557,23 @@ function allTests(os: string) {
35573557
expect(trim(jsContents)).toContain(trim(hostBindingsFn));
35583558
});
35593559

3560+
it('should handle $any used inside a listener', () => {
3561+
env.write('test.ts', `
3562+
import {Component} from '@angular/core';
3563+
3564+
@Component({
3565+
selector: 'test-cmp',
3566+
template: '<div (click)="$any(123)"></div>',
3567+
})
3568+
export class TestCmp {}
3569+
`);
3570+
3571+
env.driveMain();
3572+
expect(env.getContents('test.js'))
3573+
.toContain(
3574+
`ɵɵlistener("click", function TestCmp_Template_div_click_0_listener() { return 123; });`);
3575+
});
3576+
35603577
it('should accept dynamic host attribute bindings', () => {
35613578
env.write('other.d.ts', `
35623579
export declare const foo: any;

‎packages/compiler/src/compiler_util/expression_converter.ts

Copy file name to clipboardExpand all lines: packages/compiler/src/compiler_util/expression_converter.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,10 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
610610
throw new Error(`Invalid call to $any, expected 1 argument but received ${
611611
convertedArgs.length || 'none'}`);
612612
}
613-
return (convertedArgs[0] as o.Expression)
614-
.cast(o.DYNAMIC_TYPE, this.convertSourceSpan(ast.span));
613+
return convertToStatementIfNeeded(
614+
mode,
615+
(convertedArgs[0] as o.Expression)
616+
.cast(o.DYNAMIC_TYPE, this.convertSourceSpan(ast.span)));
615617
}
616618

617619
const leftMostSafe = this.leftMostSafeNode(ast);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.