Skip to content

Commit

Permalink
fixup! perf(compiler-cli): optimize computation of type-check scope i…
Browse files Browse the repository at this point in the history
…nformation
  • Loading branch information
JoostK committed Aug 31, 2020
1 parent ec45482 commit 59afd0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Expand Up @@ -12,7 +12,7 @@ import * as ts from 'typescript';
import {Reference} from '../../imports';
import {DirectiveMeta, flattenInheritedDirectiveMetadata, MetadataReader} from '../../metadata';
import {ClassDeclaration} from '../../reflection';
import {ComponentScopeReader, LocalModuleScope} from '../../scope';
import {ComponentScopeReader} from '../../scope';

/**
* The scope that is used for type-check code generation of a component template.
Expand Down Expand Up @@ -46,9 +46,9 @@ export class TypeCheckScopes {
private flattenedDirectiveMetaCache = new Map<ClassDeclaration, DirectiveMeta>();

/**
* Cache of the computed type check scope per NgModule scope.
* Cache of the computed type check scope per NgModule declaration.
*/
private scopeCache = new Map<LocalModuleScope, TypeCheckScope>();
private scopeCache = new Map<ClassDeclaration, TypeCheckScope>();

constructor(private scopeReader: ComponentScopeReader, private metaReader: MetadataReader) {}

Expand All @@ -68,8 +68,8 @@ export class TypeCheckScopes {
return scope;
}

if (this.scopeCache.has(scope)) {
return this.scopeCache.get(scope)!;
if (this.scopeCache.has(scope.ngModule)) {
return this.scopeCache.get(scope.ngModule)!;
}

for (const meta of scope.compilation.directives) {
Expand All @@ -88,7 +88,7 @@ export class TypeCheckScopes {
}

const typeCheckScope: TypeCheckScope = {matcher, pipes, schemas: scope.schemas};
this.scopeCache.set(scope, typeCheckScope);
this.scopeCache.set(scope.ngModule, typeCheckScope);
return typeCheckScope;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-cli/src/ngtsc/scope/src/local.ts
Expand Up @@ -26,6 +26,7 @@ export interface LocalNgModuleData {
}

export interface LocalModuleScope extends ExportScope {
ngModule: ClassDeclaration;
compilation: ScopeData;
reexports: Reexport[]|null;
schemas: SchemaMetadata[];
Expand Down Expand Up @@ -433,7 +434,8 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
}

// Finally, produce the `LocalModuleScope` with both the compilation and export scopes.
const scope = {
const scope: LocalModuleScope = {
ngModule: ngModule.ref.node,
compilation: {
directives: Array.from(compilationDirectives.values()),
pipes: Array.from(compilationPipes.values()),
Expand Down

0 comments on commit 59afd0f

Please sign in to comment.