@@ -65,8 +65,9 @@ export interface OutOfBandDiagnosticRecorder {
6565 *
6666 * @param id the type-checking ID of the template which contains the unknown pipe.
6767 * @param ast the `BindingPipe` invocation of the pipe which could not be found.
68+ * @param isStandalone whether the host component is standalone.
6869 */
69- missingPipe ( id : TypeCheckId , ast : BindingPipe ) : void ;
70+ missingPipe ( id : TypeCheckId , ast : BindingPipe , isStandalone : boolean ) : void ;
7071
7172 /**
7273 * Reports usage of a pipe imported via `@Component.deferredImports` outside
@@ -238,13 +239,30 @@ export interface OutOfBandDiagnosticRecorder {
238239}
239240
240241export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecorder {
241- private _diagnostics : TemplateDiagnostic [ ] = [ ] ;
242+ private readonly _diagnostics : TemplateDiagnostic [ ] = [ ] ;
242243
243244 /**
244245 * Tracks which `BindingPipe` nodes have already been recorded as invalid, so only one diagnostic
245246 * is ever produced per node.
246247 */
247- private recordedPipes = new Set < BindingPipe > ( ) ;
248+ private readonly recordedPipes = new Set < BindingPipe > ( ) ;
249+
250+ /** Common pipes that can be suggested to users. */
251+ private readonly pipeSuggestions = new Map < string , string > ( [
252+ [ 'async' , 'AsyncPipe' ] ,
253+ [ 'uppercase' , 'UpperCasePipe' ] ,
254+ [ 'lowercase' , 'LowerCasePipe' ] ,
255+ [ 'json' , 'JsonPipe' ] ,
256+ [ 'slice' , 'SlicePipe' ] ,
257+ [ 'number' , 'DecimalPipe' ] ,
258+ [ 'percent' , 'PercentPipe' ] ,
259+ [ 'titlecase' , 'TitleCasePipe' ] ,
260+ [ 'currency' , 'CurrencyPipe' ] ,
261+ [ 'date' , 'DatePipe' ] ,
262+ [ 'i18nPlural' , 'I18nPluralPipe' ] ,
263+ [ 'i18nSelect' , 'I18nSelectPipe' ] ,
264+ [ 'keyvalue' , 'KeyValuePipe' ] ,
265+ ] ) ;
248266
249267 constructor ( private resolver : TypeCheckSourceResolver ) { }
250268
@@ -269,20 +287,36 @@ export class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecor
269287 ) ;
270288 }
271289
272- missingPipe ( id : TypeCheckId , ast : BindingPipe ) : void {
290+ missingPipe ( id : TypeCheckId , ast : BindingPipe , isStandalone : boolean ) : void {
273291 if ( this . recordedPipes . has ( ast ) ) {
274292 return ;
275293 }
276294
277- const mapping = this . resolver . getTemplateSourceMapping ( id ) ;
278- const errorMsg = `No pipe found with name '${ ast . name } '.` ;
279-
280295 const sourceSpan = this . resolver . toTemplateParseSourceSpan ( id , ast . nameSpan ) ;
281296 if ( sourceSpan === null ) {
282297 throw new Error (
283298 `Assertion failure: no SourceLocation found for usage of pipe '${ ast . name } '.` ,
284299 ) ;
285300 }
301+
302+ const mapping = this . resolver . getTemplateSourceMapping ( id ) ;
303+ let errorMsg = `No pipe found with name '${ ast . name } '.` ;
304+
305+ if ( this . pipeSuggestions . has ( ast . name ) ) {
306+ const suggestedClassName = this . pipeSuggestions . get ( ast . name ) ! ;
307+ const suggestedImport = '@angular/common' ;
308+
309+ if ( isStandalone ) {
310+ errorMsg +=
311+ `\nTo fix this, import the "${ suggestedClassName } " class from "${ suggestedImport } "` +
312+ ` and add it to the "imports" array of the component.` ;
313+ } else {
314+ errorMsg +=
315+ `\nTo fix this, import the "${ suggestedClassName } " class from "${ suggestedImport } "` +
316+ ` and add it to the "imports" array of the module declaring the component.` ;
317+ }
318+ }
319+
286320 this . _diagnostics . push (
287321 makeTemplateDiagnostic (
288322 id ,
0 commit comments