fix(ivy): validate the NgModule declarations field (#34404)
This commit adds three previously missing validations to NgModule.declarations: 1. It checks that declared classes are actually within the current compilation. 2. It checks that declared classes are directives, components, or pipes. 3. It checks that classes are declared in at most one NgModule. PR Close #34404
This commit is contained in:

committed by
Kara Erickson

parent
9cabd6638e
commit
763f8d470a
@ -115,6 +115,26 @@ export class Reference<T extends ts.Node = ts.Node> {
|
||||
return this.identifiers.find(id => id.getSourceFile() === context) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a `ts.Identifier` for this `Reference` that exists within the given expression.
|
||||
*
|
||||
* This is very useful for producing `ts.Diagnostic`s that reference `Reference`s that were
|
||||
* extracted from some larger expression, as it can be used to pinpoint the `ts.Identifier` within
|
||||
* the expression from which the `Reference` originated.
|
||||
*/
|
||||
getIdentityInExpression(expr: ts.Expression): ts.Identifier|null {
|
||||
const sf = expr.getSourceFile();
|
||||
return this.identifiers.find(id => {
|
||||
if (id.getSourceFile() !== sf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This identifier is a match if its position lies within the given expression.
|
||||
return id.pos >= expr.pos && id.end <= expr.end;
|
||||
}) ||
|
||||
null;
|
||||
}
|
||||
|
||||
cloneWithAlias(alias: Expression): Reference<T> {
|
||||
const ref = new Reference(this.node, this.bestGuessOwningModule);
|
||||
ref.identifiers = [...this.identifiers];
|
||||
|
Reference in New Issue
Block a user