Skip to content

Commit 481c9b3

Browse files
chuckjazvicb
authored andcommitted
refactor(compiler): allows synchronous retrieving of metadata (#12908)
Allows non-normalized metadata to be retrieved synchronously. Related to #7482
1 parent 8b2dfb2 commit 481c9b3

4 files changed

Lines changed: 228 additions & 155 deletions

File tree

modules/@angular/compiler-cli/src/extractor.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,34 @@ export class Extractor {
3434
const programSymbols: StaticSymbol[] =
3535
extractProgramSymbols(this.program, this.staticReflector, this.reflectorHost, this.options);
3636

37-
return compiler
38-
.analyzeNgModules(programSymbols, {transitiveModules: true}, this.metadataResolver)
39-
.then(({files}) => {
40-
const errors: compiler.ParseError[] = [];
41-
42-
files.forEach(file => {
43-
const compMetas: compiler.CompileDirectiveMetadata[] = [];
44-
file.directives.forEach(directiveType => {
45-
const dirMeta = this.metadataResolver.getDirectiveMetadata(directiveType);
46-
if (dirMeta && dirMeta.isComponent) {
47-
compMetas.push(dirMeta);
48-
}
49-
});
50-
compMetas.forEach(compMeta => {
51-
const html = compMeta.template.template;
52-
const interpolationConfig =
53-
compiler.InterpolationConfig.fromArray(compMeta.template.interpolation);
54-
errors.push(
55-
...this.messageBundle.updateFromTemplate(html, file.srcUrl, interpolationConfig));
56-
});
57-
});
58-
59-
if (errors.length) {
60-
throw new Error(errors.map(e => e.toString()).join('\n'));
37+
const {ngModules, files} = compiler.analyzeAndValidateNgModules(
38+
programSymbols, {transitiveModules: true}, this.metadataResolver);
39+
return compiler.loadNgModuleDirectives(ngModules).then(() => {
40+
const errors: compiler.ParseError[] = [];
41+
42+
files.forEach(file => {
43+
const compMetas: compiler.CompileDirectiveMetadata[] = [];
44+
file.directives.forEach(directiveType => {
45+
const dirMeta = this.metadataResolver.getDirectiveMetadata(directiveType);
46+
if (dirMeta && dirMeta.isComponent) {
47+
compMetas.push(dirMeta);
6148
}
62-
63-
return this.messageBundle;
6449
});
50+
compMetas.forEach(compMeta => {
51+
const html = compMeta.template.template;
52+
const interpolationConfig =
53+
compiler.InterpolationConfig.fromArray(compMeta.template.interpolation);
54+
errors.push(
55+
...this.messageBundle.updateFromTemplate(html, file.srcUrl, interpolationConfig));
56+
});
57+
});
58+
59+
if (errors.length) {
60+
throw new Error(errors.map(e => e.toString()).join('\n'));
61+
}
62+
63+
return this.messageBundle;
64+
});
6565
}
6666

6767
static create(

modules/@angular/compiler/src/compile_metadata.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ export interface CompileNgModuleDirectiveSummary extends CompileSummary {
589589
exportedDirectives: CompileIdentifierMetadata[];
590590
exportedPipes: CompileIdentifierMetadata[];
591591
exportedModules: CompileNgModuleDirectiveSummary[];
592-
loadingPromises: Promise<any>[];
592+
directiveLoaders: (() => Promise<void>)[];
593593
}
594594

595595
export type CompileNgModuleSummary =
@@ -661,7 +661,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
661661
exportedModules: this.exportedModules,
662662
exportedDirectives: this.exportedDirectives,
663663
exportedPipes: this.exportedPipes,
664-
loadingPromises: this.transitiveModule.loadingPromises
664+
directiveLoaders: this.transitiveModule.directiveLoaders
665665
};
666666
}
667667

@@ -682,7 +682,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
682682
exportedDirectives: this.exportedDirectives,
683683
exportedPipes: this.exportedPipes,
684684
exportedModules: this.exportedModules,
685-
loadingPromises: this.transitiveModule.loadingPromises
685+
directiveLoaders: this.transitiveModule.directiveLoaders
686686
};
687687
}
688688
}
@@ -695,7 +695,7 @@ export class TransitiveCompileNgModuleMetadata {
695695
public modules: CompileNgModuleInjectorSummary[], public providers: CompileProviderMetadata[],
696696
public entryComponents: CompileIdentifierMetadata[],
697697
public directives: CompileIdentifierMetadata[], public pipes: CompileIdentifierMetadata[],
698-
public loadingPromises: Promise<any>[]) {
698+
public directiveLoaders: (() => Promise<void>)[]) {
699699
directives.forEach(dir => this.directivesSet.add(dir.reference));
700700
pipes.forEach(pipe => this.pipesSet.add(pipe.reference));
701701
}

0 commit comments

Comments
 (0)