Skip to content

Commit a8fab04

Browse files
JoostKprofanis
authored andcommitted
fix(compiler-cli): infer quote expressions as any type in type checker (angular#37917)
"Quote expressions" are expressions that start with an identifier followed by a comma, allowing arbitrary syntax to follow. These kinds of expressions would throw a an error in the template type checker, which would make them hard to track down. As quote expressions are not generally used at all, the error would typically occur for URLs that would inadvertently occur in a binding: ```html <a [href]="https://example.com"></a> ``` This commit lets such bindings be inferred as the `any` type. Fixes angular#36568 Resolves FW-2051 PR Close angular#37917
1 parent 67f5871 commit a8fab04

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ class AstTranslator implements AstVisitor {
234234
return node;
235235
}
236236

237-
visitQuote(ast: Quote): never {
238-
throw new Error('Method not implemented.');
237+
visitQuote(ast: Quote): ts.Expression {
238+
return NULL_AS_ANY;
239239
}
240240

241241
visitSafeMethodCall(ast: SafeMethodCall): ts.Expression {

packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ describe('type check blocks', () => {
4242
.toContain('(((ctx).a) ? ((ctx).b) : (((ctx).c) ? ((ctx).d) : ((ctx).e)))');
4343
});
4444

45+
it('should handle quote expressions as any type', () => {
46+
const TEMPLATE = `<span [quote]="sql:expression"></span>`;
47+
expect(tcb(TEMPLATE)).toContain('null as any');
48+
});
49+
4550
it('should handle attribute values for directive inputs', () => {
4651
const TEMPLATE = `<div dir inputA="value"></div>`;
4752
const DIRECTIVES: TestDeclaration[] = [{

0 commit comments

Comments
 (0)