fix(ivy): add support for optional nullable injection tokens (#27552)
FW-778 #resolve PR Close #27552
This commit is contained in:
@ -82,7 +82,8 @@ export function generateSetClassMetadataCall(
|
||||
function ctorParameterToMetadata(param: CtorParameter, isCore: boolean): ts.Expression {
|
||||
// Parameters sometimes have a type that can be referenced. If so, then use it, otherwise
|
||||
// its type is undefined.
|
||||
const type = param.type !== null ? param.type : ts.createIdentifier('undefined');
|
||||
const type =
|
||||
param.typeExpression !== null ? param.typeExpression : ts.createIdentifier('undefined');
|
||||
const properties: ts.ObjectLiteralElementLike[] = [
|
||||
ts.createPropertyAssignment('type', type),
|
||||
];
|
||||
|
@ -26,7 +26,7 @@ export function getConstructorDependencies(
|
||||
}
|
||||
}
|
||||
ctorParams.forEach((param, idx) => {
|
||||
let tokenExpr = param.type;
|
||||
let tokenExpr = param.typeExpression;
|
||||
let optional = false, self = false, skipSelf = false, host = false;
|
||||
let resolved = R3ResolvedDependencyType.Token;
|
||||
(param.decorators || []).filter(dec => isCore || isAngularCore(dec)).forEach(dec => {
|
||||
@ -62,7 +62,7 @@ export function getConstructorDependencies(
|
||||
if (tokenExpr === null) {
|
||||
throw new FatalDiagnosticError(
|
||||
ErrorCode.PARAM_MISSING_TOKEN, param.nameNode,
|
||||
`No suitable token for parameter ${param.name || idx} of class ${clazz.name!.text}`);
|
||||
`No suitable injection token for parameter '${param.name || idx}' of class '${clazz.name!.text}'. Found: ${param.typeNode!.getText()}`);
|
||||
}
|
||||
const token = new WrappedNodeExpr(tokenExpr);
|
||||
useType.push({token, optional, self, skipSelf, host, resolved});
|
||||
|
Reference in New Issue
Block a user