Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-cli): report missing pipes when fullTemplateTypeCheck is disabled #39320

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,11 @@ export class Context {
return ts.createIdentifier(`_t${this.nextId++}`);
}

getPipeByName(name: string): ts.Expression|null {
getPipeByName(name: string): Reference<ClassDeclaration<ts.ClassDeclaration>>|null {
if (!this.pipes.has(name)) {
return null;
}
return this.env.pipeInst(this.pipes.get(name)!);
return this.pipes.get(name)!;
}
}

Expand Down Expand Up @@ -1568,19 +1568,20 @@ class TcbExpressionTranslator {
return ts.createIdentifier('ctx');
} else if (ast instanceof BindingPipe) {
const expr = this.translate(ast.exp);
const pipeRef = this.tcb.getPipeByName(ast.name);
let pipe: ts.Expression|null;
if (this.tcb.env.config.checkTypeOfPipes) {
pipe = this.tcb.getPipeByName(ast.name);
if (pipe === null) {
// No pipe by that name exists in scope. Record this as an error.
this.tcb.oobRecorder.missingPipe(this.tcb.id, ast);

// Return an 'any' value to at least allow the rest of the expression to be checked.
pipe = NULL_AS_ANY;
}
if (pipeRef === null) {
// No pipe by that name exists in scope. Record this as an error.
this.tcb.oobRecorder.missingPipe(this.tcb.id, ast);

// Use an 'any' value to at least allow the rest of the expression to be checked.
pipe = NULL_AS_ANY;
} else if (this.tcb.env.config.checkTypeOfPipes) {
// Use a variable declared as the pipe's type.
pipe = this.tcb.env.pipeInst(pipeRef);
} else {
pipe = ts.createParen(ts.createAsExpression(
ts.createNull(), ts.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
// Use an 'any' value when not checking the type of the pipe.
pipe = NULL_AS_ANY;
}
const args = ast.args.map(arg => this.translate(arg));
const result = tsCallMethod(pipe, 'transform', [expr, ...args]);
Expand Down
25 changes: 25 additions & 0 deletions packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,31 @@ export declare class AnimationEvent {
expect(getSourceCodeForDiagnostic(diags[0])).toBe('unknown');
});

it('should report an error with an unknown pipe even if `fullTemplateTypeCheck` is disabled',
() => {
env.tsconfig({ivyTemplateTypeCheck: true, fullTemplateTypeCheck: false});
env.write('test.ts', `
import {Component, NgModule} from '@angular/core';

@Component({
selector: 'test',
template: '{{expr | unknown}}',
})
class TestCmp {
expr = 3;
}

@NgModule({
declarations: [TestCmp],
})
class Module {}
`);
const diags = env.driveDiagnostics();
expect(diags.length).toBe(1);
expect(diags[0].messageText).toBe(`No pipe found with name 'unknown'.`);
expect(getSourceCodeForDiagnostic(diags[0])).toBe('unknown');
});

it('should report an error with pipe bindings', () => {
env.write('test.ts', `
import {CommonModule} from '@angular/common';
Expand Down