mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler-cli): Make getKnown return an array of nodes. (#48354)
`MetadataReaderWithIndex.getKnown` currently returns an iterator. It will be easier to work with for upcoming usages if it returns an array instead. PR Close #48354
This commit is contained in:
committed by
Andrew Kushnir
parent
2a4c5b4391
commit
ea8b33934b
@@ -251,10 +251,17 @@ export interface MetadataReader {
|
||||
}
|
||||
|
||||
/**
|
||||
* A MetadataReader which also allows access to the set of all known directive classes.
|
||||
* A MetadataReader which also allows access to the set of all known trait classes.
|
||||
*/
|
||||
export interface MetadataReaderWithIndex extends MetadataReader {
|
||||
getKnown(kind: MetaKind): Iterable<ClassDeclaration>;
|
||||
getKnown(kind: MetaKind): Array<ClassDeclaration>;
|
||||
}
|
||||
|
||||
/**
|
||||
* An NgModuleIndex allows access to information about traits exported by NgModules.
|
||||
*/
|
||||
export interface NgModuleIndex {
|
||||
getNgModulesExporting(directiveOrPipe: ClassDeclaration): Array<Reference<ClassDeclaration>>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,14 +40,14 @@ export class LocalMetadataRegistry implements MetadataRegistry, MetadataReaderWi
|
||||
this.pipes.set(meta.ref.node, meta);
|
||||
}
|
||||
|
||||
getKnown(kind: MetaKind): Iterable<ClassDeclaration> {
|
||||
getKnown(kind: MetaKind): Array<ClassDeclaration> {
|
||||
switch (kind) {
|
||||
case MetaKind.Directive:
|
||||
return this.directives.keys();
|
||||
return Array.from(this.directives.values()).map(v => v.ref.node);
|
||||
case MetaKind.Pipe:
|
||||
return this.pipes.keys();
|
||||
return Array.from(this.pipes.values()).map(v => v.ref.node);
|
||||
case MetaKind.NgModule:
|
||||
return this.ngModules.keys();
|
||||
return Array.from(this.ngModules.values()).map(v => v.ref.node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import {absoluteFrom, AbsoluteFsPath, getSourceFileOrError, LogicalFileSystem} f
|
||||
import {TestFile} from '../../file_system/testing';
|
||||
import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, Reexport, Reference, ReferenceEmitter, RelativePathStrategy} from '../../imports';
|
||||
import {NOOP_INCREMENTAL_BUILD} from '../../incremental';
|
||||
import {ClassPropertyMapping, CompoundMetadataReader, DirectiveMeta, HostDirectivesResolver, MatchSource, MetadataReader, MetadataReaderWithIndex, MetaKind} from '../../metadata';
|
||||
import {ClassPropertyMapping, CompoundMetadataReader, DirectiveMeta, HostDirectivesResolver, MatchSource, MetadataReader, MetadataReaderWithIndex, MetaKind, NgModuleIndex, NgModuleMeta, PipeMeta} from '../../metadata';
|
||||
import {NOOP_PERF_RECORDER} from '../../perf';
|
||||
import {TsCreateProgramDriver} from '../../program_driver';
|
||||
import {ClassDeclaration, isNamedClassDeclaration, TypeScriptReflectionHost} from '../../reflection';
|
||||
@@ -550,14 +550,15 @@ export function setup(targets: TypeCheckingTarget[], overrides: {
|
||||
};
|
||||
|
||||
const fakeMetadataReader = getFakeMetadataReader(fakeMetadataRegistry);
|
||||
const fakeNgModuleIndex = getFakeNgModuleIndex(fakeMetadataRegistry);
|
||||
const typeCheckScopeRegistry = new TypeCheckScopeRegistry(
|
||||
fakeScopeReader, new CompoundMetadataReader([fakeMetadataReader]),
|
||||
new HostDirectivesResolver(fakeMetadataReader));
|
||||
|
||||
const templateTypeChecker = new TemplateTypeCheckerImpl(
|
||||
program, programStrategy, checkAdapter, fullConfig, emitter, reflectionHost, host,
|
||||
NOOP_INCREMENTAL_BUILD, fakeMetadataReader, fakeMetadataReader, fakeScopeReader,
|
||||
typeCheckScopeRegistry, NOOP_PERF_RECORDER);
|
||||
NOOP_INCREMENTAL_BUILD, fakeMetadataReader, fakeMetadataReader, fakeNgModuleIndex,
|
||||
fakeScopeReader, typeCheckScopeRegistry, NOOP_PERF_RECORDER);
|
||||
return {
|
||||
templateTypeChecker,
|
||||
program,
|
||||
@@ -577,10 +578,9 @@ function getFakeMetadataReader(fakeMetadataRegistry: Map<any, DirectiveMeta|null
|
||||
null {
|
||||
return fakeMetadataRegistry.get(node.debugName) ?? null;
|
||||
},
|
||||
getKnown(kind: MetaKind): Iterable<ClassDeclaration> {
|
||||
getKnown(kind: MetaKind): Array<ClassDeclaration> {
|
||||
switch (kind) {
|
||||
case MetaKind.Directive:
|
||||
return fakeMetadataRegistry.keys();
|
||||
// TODO: This is not needed for these ngtsc tests, but may be wanted in the future.
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
@@ -588,6 +588,14 @@ function getFakeMetadataReader(fakeMetadataRegistry: Map<any, DirectiveMeta|null
|
||||
} as MetadataReaderWithIndex;
|
||||
}
|
||||
|
||||
function getFakeNgModuleIndex(fakeMetadataRegistry: Map<any, DirectiveMeta|null>): NgModuleIndex {
|
||||
return {
|
||||
getNgModulesExporting(trait: ClassDeclaration): Array<Reference<ClassDeclaration>> {
|
||||
return [];
|
||||
}
|
||||
} as NgModuleIndex;
|
||||
}
|
||||
|
||||
type DeclarationResolver = (decl: TestDeclaration) => ClassDeclaration<ts.ClassDeclaration>;
|
||||
|
||||
function prepareDeclarations(
|
||||
|
||||
Reference in New Issue
Block a user