Skip to content

Commit

Permalink
fix(compiler-cli): report missing pipes when fullTemplateTypeCheck
Browse files Browse the repository at this point in the history
…is disabled

Even if `fullTemplateTypeCheck` is disabled should missing pipes still
be reported, as was the case in View Engine.

Fixes #38195
  • Loading branch information
JoostK committed Oct 17, 2020
1 parent 0875fd2 commit 0dd4bdf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
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

0 comments on commit 0dd4bdf

Please sign in to comment.