diff --git a/packages/compiler-cli/ngcc/src/host/delegating_host.ts b/packages/compiler-cli/ngcc/src/host/delegating_host.ts index 3bef3e432d..d4d36fc96f 100644 --- a/packages/compiler-cli/ngcc/src/host/delegating_host.ts +++ b/packages/compiler-cli/ngcc/src/host/delegating_host.ts @@ -32,7 +32,7 @@ export class DelegatingReflectionHost implements NgccReflectionHost { getDeclarationOfIdentifier(id: ts.Identifier): Declaration|null { if (isFromDtsFile(id)) { - return this.tsHost.getDeclarationOfIdentifier(id); + return this.detectKnownDeclaration(this.tsHost.getDeclarationOfIdentifier(id)); } return this.ngccHost.getDeclarationOfIdentifier(id); } @@ -60,7 +60,13 @@ export class DelegatingReflectionHost implements NgccReflectionHost { getExportsOfModule(module: ts.Node): Map|null { if (isFromDtsFile(module)) { - return this.tsHost.getExportsOfModule(module); + const exportMap = this.tsHost.getExportsOfModule(module); + + if (exportMap !== null) { + exportMap.forEach(decl => this.detectKnownDeclaration(decl)); + } + + return exportMap; } return this.ngccHost.getExportsOfModule(module); } @@ -154,4 +160,11 @@ export class DelegatingReflectionHost implements NgccReflectionHost { getEndOfClass(classSymbol: NgccClassSymbol): ts.Node { 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 { + return this.ngccHost.detectKnownDeclaration(decl); + } } diff --git a/packages/compiler-cli/ngcc/src/host/ngcc_host.ts b/packages/compiler-cli/ngcc/src/host/ngcc_host.ts index e1f3c07fde..eb16f662ea 100644 --- a/packages/compiler-cli/ngcc/src/host/ngcc_host.ts +++ b/packages/compiler-cli/ngcc/src/host/ngcc_host.ts @@ -7,12 +7,12 @@ */ import * as ts from 'typescript'; -import {ClassDeclaration, ConcreteDeclaration, Decorator, ReflectionHost} from '../../../src/ngtsc/reflection'; +import {ClassDeclaration, ConcreteDeclaration, Declaration, Decorator, ReflectionHost} from '../../../src/ngtsc/reflection'; export const PRE_R3_MARKER = '__PRE_R3__'; export const POST_R3_MARKER = '__POST_R3__'; -export type SwitchableVariableDeclaration = ts.VariableDeclaration & {initializer: ts.Identifier}; +export type SwitchableVariableDeclaration = ts.VariableDeclaration&{initializer: ts.Identifier}; export function isSwitchableVariableDeclaration(node: ts.Node): node is SwitchableVariableDeclaration { return ts.isVariableDeclaration(node) && !!node.initializer && @@ -47,7 +47,7 @@ export interface ModuleWithProvidersFunction { * The symbol corresponding to a "class" declaration. I.e. a `ts.Symbol` whose `valueDeclaration` is * a `ClassDeclaration`. */ -export type ClassSymbol = ts.Symbol & {valueDeclaration: ClassDeclaration}; +export type ClassSymbol = ts.Symbol&{valueDeclaration: ClassDeclaration}; /** * A representation of a class that accounts for the potential existence of two `ClassSymbol`s for a @@ -128,4 +128,13 @@ export interface NgccReflectionHost extends ReflectionHost { * @param classSymbol The class whose statements we want. */ getEndOfClass(classSymbol: NgccClassSymbol): ts.Node; + + /** + * 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. + * @return The passed in `Declaration` (potentially enhanced with a `KnownDeclaration`). + */ + detectKnownDeclaration(decl: T|null): T|null; }