refactor(ngcc): simplify the `detectKnownDeclaration()` signature (#36989)
A number of overloads were added to `detectKnownDeclaration()` to allow it to support `null` being passed through. In practice this could easily be avoided, which allows the overloads to be removed and the method signature and implementations to be simplified. PR Close #36989
This commit is contained in:
parent
13ba84731f
commit
491da99abe
|
@ -32,7 +32,8 @@ export class DelegatingReflectionHost implements NgccReflectionHost {
|
|||
|
||||
getDeclarationOfIdentifier(id: ts.Identifier): Declaration|null {
|
||||
if (isFromDtsFile(id)) {
|
||||
return this.detectKnownDeclaration(this.tsHost.getDeclarationOfIdentifier(id));
|
||||
const declaration = this.tsHost.getDeclarationOfIdentifier(id);
|
||||
return declaration !== null ? this.detectKnownDeclaration(declaration) : null;
|
||||
}
|
||||
return this.ngccHost.getDeclarationOfIdentifier(id);
|
||||
}
|
||||
|
@ -157,10 +158,7 @@ export class DelegatingReflectionHost implements NgccReflectionHost {
|
|||
return this.ngccHost.getEndOfClass(classSymbol);
|
||||
}
|
||||
|
||||
detectKnownDeclaration(decl: null): null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null {
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T {
|
||||
return this.ngccHost.detectKnownDeclaration(decl);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -604,16 +604,12 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
|
|||
* @param decl The `Declaration` to check.
|
||||
* @return The passed in `Declaration` (potentially enhanced with a `KnownDeclaration`).
|
||||
*/
|
||||
detectKnownDeclaration(decl: null): null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null {
|
||||
if (decl !== null && decl.known === null && this.isJavaScriptObjectDeclaration(decl)) {
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T {
|
||||
if (decl.known === null && this.isJavaScriptObjectDeclaration(decl)) {
|
||||
// If the identifier resolves to the global JavaScript `Object`, update the declaration to
|
||||
// denote it as the known `JsGlobalObject` declaration.
|
||||
decl.known = KnownDeclaration.JsGlobalObject;
|
||||
}
|
||||
|
||||
return decl;
|
||||
}
|
||||
|
||||
|
@ -626,7 +622,11 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
|
|||
*/
|
||||
protected getDeclarationOfSymbol(symbol: ts.Symbol, originalId: ts.Identifier|null): Declaration
|
||||
|null {
|
||||
return this.detectKnownDeclaration(super.getDeclarationOfSymbol(symbol, originalId));
|
||||
const declaration = super.getDeclarationOfSymbol(symbol, originalId);
|
||||
if (declaration === null) {
|
||||
return null;
|
||||
}
|
||||
return this.detectKnownDeclaration(declaration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -283,13 +283,11 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
|
|||
* @param decl The `Declaration` to check.
|
||||
* @return The passed in `Declaration` (potentially enhanced with a `KnownDeclaration`).
|
||||
*/
|
||||
detectKnownDeclaration(decl: null): null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null {
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T {
|
||||
decl = super.detectKnownDeclaration(decl);
|
||||
|
||||
if (decl !== null && decl.known === null && decl.node !== null) {
|
||||
// Also check for TS helpers
|
||||
if (decl.known === null && decl.node !== null) {
|
||||
decl.known = getTsHelperFnFromDeclaration(decl.node);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,8 +100,8 @@ export interface NgccReflectionHost extends ReflectionHost {
|
|||
* Check whether a `Declaration` corresponds with a known declaration and set its `known` property
|
||||
* to the appropriate `KnownDeclaration`.
|
||||
*
|
||||
* @param decl The `Declaration` to check or `null` if there is no declaration.
|
||||
* @param decl The `Declaration` to check.
|
||||
* @return The passed in `Declaration` (potentially enhanced with a `KnownDeclaration`).
|
||||
*/
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T|null): T|null;
|
||||
detectKnownDeclaration<T extends Declaration>(decl: T): T;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue