* Produce a `ts.Diagnostic` for an invalid import or export from an NgModule.
( decl: Reference<ClassDeclaration>, rawExpr: ts.Expression | null, type: 'import' | 'export', )
| 700 | * Produce a `ts.Diagnostic` for an invalid import or export from an NgModule. |
| 701 | */ |
| 702 | function invalidRef( |
| 703 | decl: Reference<ClassDeclaration>, |
| 704 | rawExpr: ts.Expression | null, |
| 705 | type: 'import' | 'export', |
| 706 | ): ts.Diagnostic { |
| 707 | const code = |
| 708 | type === 'import' ? ErrorCode.NGMODULE_INVALID_IMPORT : ErrorCode.NGMODULE_INVALID_EXPORT; |
| 709 | const resolveTarget = type === 'import' ? 'NgModule' : 'NgModule, Component, Directive, or Pipe'; |
| 710 | const message = `'${decl.node.name.text}' does not appear to be an ${resolveTarget} class.`; |
| 711 | const library = decl.ownedByModuleGuess !== null ? ` (${decl.ownedByModuleGuess})` : ''; |
| 712 | const sf = decl.node.getSourceFile(); |
| 713 | |
| 714 | let relatedMessage: string; |
| 715 | |
| 716 | // Provide extra context to the error for the user. |
| 717 | if (!sf.isDeclarationFile) { |
| 718 | // This is a file in the user's program. Highlight the class as undecorated. |
| 719 | const annotationType = type === 'import' ? '@NgModule' : 'Angular'; |
| 720 | relatedMessage = `Is it missing an ${annotationType} annotation?`; |
| 721 | } else if (sf.fileName.indexOf('node_modules') !== -1) { |
| 722 | // This file comes from a third-party library in node_modules. |
| 723 | relatedMessage = |
| 724 | `This likely means that the library${library} which declares ${decl.debugName} is not ` + |
| 725 | 'compatible with Angular Ivy. Check if a newer version of the library is available, ' + |
| 726 | "and update if so. Also consider checking with the library's authors to see if the " + |
| 727 | 'library is expected to be compatible with Ivy.'; |
| 728 | } else { |
| 729 | // This is a monorepo style local dependency. Unfortunately these are too different to really |
| 730 | // offer much more advice than this. |
| 731 | relatedMessage = `This likely means that the dependency${library} which declares ${decl.debugName} is not compatible with Angular Ivy.`; |
| 732 | } |
| 733 | |
| 734 | return makeDiagnostic(code, getDiagnosticNode(decl, rawExpr), message, [ |
| 735 | makeRelatedInformation(decl.node.name, relatedMessage), |
| 736 | ]); |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Produce a `ts.Diagnostic` for an import or export which itself has errors. |
no test coverage detected