feat(ivy): reference external classes by their exported name (#27743)
Previously, ngtsc would assume that a given directive/pipe being imported from an external package was importable using the same name by which it was declared. This isn't always true; sometimes a package will export a directive under a different name. For example, Angular frequently prefixes directive names with the 'ɵ' character to indicate that they're part of the package's private API, and not for public consumption. This commit introduces the TsReferenceResolver class which, given a declaration to import and a module name to import it from, can determine the exported name of the declared class within the module. This allows ngtsc to pick the correct name by which to import the class instead of making assumptions about how it was exported. This resolver is used to select a correct symbol name when creating an AbsoluteReference. FW-517 #resolve FW-536 #resolve PR Close #27743
This commit is contained in:

committed by
Kara Erickson

parent
0b9094ec63
commit
1c39ad38d3
@ -16,7 +16,7 @@ import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecorato
|
||||
import {BaseDefDecoratorHandler} from './annotations/src/base_def';
|
||||
import {ErrorCode, ngErrorCode} from './diagnostics';
|
||||
import {FlatIndexGenerator, ReferenceGraph, checkForPrivateExports, findFlatIndexEntryPoint} from './entry_point';
|
||||
import {Reference} from './imports';
|
||||
import {Reference, TsReferenceResolver} from './imports';
|
||||
import {PartialEvaluator} from './partial_evaluator';
|
||||
import {TypeScriptReflectionHost} from './reflection';
|
||||
import {FileResourceLoader, HostResourceLoader} from './resource_loader';
|
||||
@ -274,8 +274,9 @@ export class NgtscProgram implements api.Program {
|
||||
|
||||
private makeCompilation(): IvyCompilation {
|
||||
const checker = this.tsProgram.getTypeChecker();
|
||||
const evaluator = new PartialEvaluator(this.reflector, checker);
|
||||
const scopeRegistry = new SelectorScopeRegistry(checker, this.reflector);
|
||||
const refResolver = new TsReferenceResolver(this.tsProgram, checker, this.options, this.host);
|
||||
const evaluator = new PartialEvaluator(this.reflector, checker, refResolver);
|
||||
const scopeRegistry = new SelectorScopeRegistry(checker, this.reflector, refResolver);
|
||||
|
||||
// If a flat module entrypoint was specified, then track references via a `ReferenceGraph` in
|
||||
// order to produce proper diagnostics for incorrectly exported directives/pipes/etc. If there
|
||||
|
Reference in New Issue
Block a user