MCPcopy Create free account
hub / github.com/angular/angular / invalidReexport

Function invalidReexport

packages/compiler-cli/src/ngtsc/scope/src/local.ts:760–786  ·  view source on GitHub ↗

* Produce a `ts.Diagnostic` for an exported directive or pipe which was not declared or imported * by the NgModule in question.

(
  decl: Reference<ClassDeclaration>,
  rawExpr: ts.Expression | null,
  isStandalone: boolean,
)

Source from the content-addressed store, hash-verified

758 * by the NgModule in question.
759 */
760function invalidReexport(
761 decl: Reference<ClassDeclaration>,
762 rawExpr: ts.Expression | null,
763 isStandalone: boolean,
764): ts.Diagnostic {
765 // The root error is the same here - this export is not valid. Give a helpful error message based
766 // on the specific circumstance.
767 let message = `Can't be exported from this NgModule, as `;
768 if (isStandalone) {
769 // Standalone types need to be imported into an NgModule before they can be re-exported.
770 message += 'it must be imported first';
771 } else if (decl.node.getSourceFile().isDeclarationFile) {
772 // Non-standalone types can be re-exported, but need to be imported into the NgModule first.
773 // This requires importing their own NgModule.
774 message += 'it must be imported via its NgModule first';
775 } else {
776 // Local non-standalone types must either be declared directly by this NgModule, or imported as
777 // above.
778 message +=
779 'it must be either declared by this NgModule, or imported here via its NgModule first';
780 }
781 return makeDiagnostic(
782 ErrorCode.NGMODULE_INVALID_REEXPORT,
783 getDiagnosticNode(decl, rawExpr),
784 message,
785 );
786}
787
788/**
789 * Produce a `ts.Diagnostic` for a collision in re-export names between two directives/pipes.

Callers 1

Calls 3

makeDiagnosticFunction · 0.90
getDiagnosticNodeFunction · 0.90
getSourceFileMethod · 0.45

Tested by

no test coverage detected