diff --git a/packages/compiler-cli/ngcc/src/host/delegating_host.ts b/packages/compiler-cli/ngcc/src/host/delegating_host.ts index d1e7293feb..b7cc897e84 100644 --- a/packages/compiler-cli/ngcc/src/host/delegating_host.ts +++ b/packages/compiler-cli/ngcc/src/host/delegating_host.ts @@ -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(decl: T): T; - detectKnownDeclaration(decl: T|null): T|null; - detectKnownDeclaration(decl: T|null): T|null { + detectKnownDeclaration(decl: T): T { return this.ngccHost.detectKnownDeclaration(decl); } } diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index a401f6ea64..31b88bded5 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -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(decl: T): T; - detectKnownDeclaration(decl: T|null): T|null; - detectKnownDeclaration(decl: T|null): T|null { - if (decl !== null && decl.known === null && this.isJavaScriptObjectDeclaration(decl)) { + detectKnownDeclaration(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); } /** diff --git a/packages/compiler-cli/ngcc/src/host/esm5_host.ts b/packages/compiler-cli/ngcc/src/host/esm5_host.ts index f620e38243..b93d37d968 100644 --- a/packages/compiler-cli/ngcc/src/host/esm5_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm5_host.ts @@ -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(decl: T): T; - detectKnownDeclaration(decl: T|null): T|null; - detectKnownDeclaration(decl: T|null): T|null { + detectKnownDeclaration(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); } diff --git a/packages/compiler-cli/ngcc/src/host/ngcc_host.ts b/packages/compiler-cli/ngcc/src/host/ngcc_host.ts index 2d74d0532b..a6165e7bb4 100644 --- a/packages/compiler-cli/ngcc/src/host/ngcc_host.ts +++ b/packages/compiler-cli/ngcc/src/host/ngcc_host.ts @@ -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(decl: T|null): T|null; + detectKnownDeclaration(decl: T): T; }