fix(compiler): Update types for TypeScript nullability support
This commit is contained in:
@ -49,20 +49,20 @@ export class JitCompiler implements Compiler {
|
||||
get injector(): Injector { return this._injector; }
|
||||
|
||||
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> {
|
||||
return this._compileModuleAndComponents(moduleType, true).syncResult;
|
||||
return this._compileModuleAndComponents(moduleType, true).syncResult !;
|
||||
}
|
||||
|
||||
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> {
|
||||
return this._compileModuleAndComponents(moduleType, false).asyncResult;
|
||||
return this._compileModuleAndComponents(moduleType, false).asyncResult !;
|
||||
}
|
||||
|
||||
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
|
||||
return this._compileModuleAndAllComponents(moduleType, true).syncResult;
|
||||
return this._compileModuleAndAllComponents(moduleType, true).syncResult !;
|
||||
}
|
||||
|
||||
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
|
||||
Promise<ModuleWithComponentFactories<T>> {
|
||||
return this._compileModuleAndAllComponents(moduleType, false).asyncResult;
|
||||
return this._compileModuleAndAllComponents(moduleType, false).asyncResult !;
|
||||
}
|
||||
|
||||
getNgContentSelectors(component: Type<any>): string[] {
|
||||
@ -72,7 +72,7 @@ export class JitCompiler implements Compiler {
|
||||
if (!template) {
|
||||
throw new Error(`The component ${stringify(component)} is not yet compiled!`);
|
||||
}
|
||||
return template.compMeta.template.ngContentSelectors;
|
||||
return template.compMeta.template !.ngContentSelectors;
|
||||
}
|
||||
|
||||
private _compileModuleAndComponents<T>(moduleType: Type<T>, isSync: boolean):
|
||||
@ -106,7 +106,7 @@ export class JitCompiler implements Compiler {
|
||||
|
||||
private _loadModules(mainModule: any, isSync: boolean): Promise<any> {
|
||||
const loadingPromises: Promise<any>[] = [];
|
||||
const ngModule = this._metadataResolver.getNgModuleMetadata(mainModule);
|
||||
const ngModule = this._metadataResolver.getNgModuleMetadata(mainModule) !;
|
||||
// Note: the loadingPromise for a module only includes the loading of the exported directives
|
||||
// of imported modules.
|
||||
// However, for runtime compilation, we want to transitively compile all modules,
|
||||
@ -119,9 +119,9 @@ export class JitCompiler implements Compiler {
|
||||
}
|
||||
|
||||
private _compileModule<T>(moduleType: Type<T>): NgModuleFactory<T> {
|
||||
let ngModuleFactory = this._compiledNgModuleCache.get(moduleType);
|
||||
let ngModuleFactory = this._compiledNgModuleCache.get(moduleType) !;
|
||||
if (!ngModuleFactory) {
|
||||
const moduleMeta = this._metadataResolver.getNgModuleMetadata(moduleType);
|
||||
const moduleMeta = this._metadataResolver.getNgModuleMetadata(moduleType) !;
|
||||
// Always provide a bound Compiler
|
||||
const extraProviders = [this._metadataResolver.getProviderMetadata(new ProviderMeta(
|
||||
Compiler, {useFactory: () => new ModuleBoundCompiler(this, moduleMeta.type.reference)}))];
|
||||
@ -142,14 +142,14 @@ export class JitCompiler implements Compiler {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_compileComponents(mainModule: Type<any>, allComponentFactories: ComponentFactory<any>[]) {
|
||||
const ngModule = this._metadataResolver.getNgModuleMetadata(mainModule);
|
||||
_compileComponents(mainModule: Type<any>, allComponentFactories: ComponentFactory<any>[]|null) {
|
||||
const ngModule = this._metadataResolver.getNgModuleMetadata(mainModule) !;
|
||||
const moduleByDirective = new Map<any, CompileNgModuleMetadata>();
|
||||
const templates = new Set<CompiledTemplate>();
|
||||
|
||||
ngModule.transitiveModule.modules.forEach((localModuleSummary) => {
|
||||
const localModuleMeta =
|
||||
this._metadataResolver.getNgModuleMetadata(localModuleSummary.reference);
|
||||
this._metadataResolver.getNgModuleMetadata(localModuleSummary.reference) !;
|
||||
localModuleMeta.declaredDirectives.forEach((dirIdentifier) => {
|
||||
moduleByDirective.set(dirIdentifier.reference, localModuleMeta);
|
||||
const dirMeta = this._metadataResolver.getDirectiveMetadata(dirIdentifier.reference);
|
||||
@ -166,19 +166,19 @@ export class JitCompiler implements Compiler {
|
||||
});
|
||||
ngModule.transitiveModule.modules.forEach((localModuleSummary) => {
|
||||
const localModuleMeta =
|
||||
this._metadataResolver.getNgModuleMetadata(localModuleSummary.reference);
|
||||
this._metadataResolver.getNgModuleMetadata(localModuleSummary.reference) !;
|
||||
localModuleMeta.declaredDirectives.forEach((dirIdentifier) => {
|
||||
const dirMeta = this._metadataResolver.getDirectiveMetadata(dirIdentifier.reference);
|
||||
if (dirMeta.isComponent) {
|
||||
dirMeta.entryComponents.forEach((entryComponentType) => {
|
||||
const moduleMeta = moduleByDirective.get(entryComponentType.componentType);
|
||||
const moduleMeta = moduleByDirective.get(entryComponentType.componentType) !;
|
||||
templates.add(
|
||||
this._createCompiledHostTemplate(entryComponentType.componentType, moduleMeta));
|
||||
});
|
||||
}
|
||||
});
|
||||
localModuleMeta.entryComponents.forEach((entryComponentType) => {
|
||||
const moduleMeta = moduleByDirective.get(entryComponentType.componentType);
|
||||
const moduleMeta = moduleByDirective.get(entryComponentType.componentType) !;
|
||||
templates.add(
|
||||
this._createCompiledHostTemplate(entryComponentType.componentType, moduleMeta));
|
||||
});
|
||||
@ -245,7 +245,7 @@ export class JitCompiler implements Compiler {
|
||||
const externalStylesheetsByModuleUrl = new Map<string, CompiledStylesheet>();
|
||||
const stylesCompileResult = this._styleCompiler.compileComponent(compMeta);
|
||||
stylesCompileResult.externalStylesheets.forEach(
|
||||
(r) => { externalStylesheetsByModuleUrl.set(r.meta.moduleUrl, r); });
|
||||
(r) => { externalStylesheetsByModuleUrl.set(r.meta.moduleUrl !, r); });
|
||||
this._resolveStylesCompileResult(
|
||||
stylesCompileResult.componentStylesheet, externalStylesheetsByModuleUrl);
|
||||
const directives =
|
||||
@ -253,8 +253,8 @@ export class JitCompiler implements Compiler {
|
||||
const pipes = template.ngModule.transitiveModule.pipes.map(
|
||||
pipe => this._metadataResolver.getPipeSummary(pipe.reference));
|
||||
const {template: parsedTemplate, pipes: usedPipes} = this._templateParser.parse(
|
||||
compMeta, compMeta.template.template, directives, pipes, template.ngModule.schemas,
|
||||
templateSourceUrl(template.ngModule.type, template.compMeta, template.compMeta.template));
|
||||
compMeta, compMeta.template !.template !, directives, pipes, template.ngModule.schemas,
|
||||
templateSourceUrl(template.ngModule.type, template.compMeta, template.compMeta.template !));
|
||||
const compileResult = this._viewCompiler.compileComponent(
|
||||
compMeta, parsedTemplate, ir.variable(stylesCompileResult.componentStylesheet.stylesVar),
|
||||
usedPipes);
|
||||
@ -278,7 +278,7 @@ export class JitCompiler implements Compiler {
|
||||
private _resolveStylesCompileResult(
|
||||
result: CompiledStylesheet, externalStylesheetsByModuleUrl: Map<string, CompiledStylesheet>) {
|
||||
result.dependencies.forEach((dep, i) => {
|
||||
const nestedCompileResult = externalStylesheetsByModuleUrl.get(dep.moduleUrl);
|
||||
const nestedCompileResult = externalStylesheetsByModuleUrl.get(dep.moduleUrl) !;
|
||||
const nestedStylesArr = this._resolveAndEvalStylesCompileResult(
|
||||
nestedCompileResult, externalStylesheetsByModuleUrl);
|
||||
dep.valuePlaceholder.reference = nestedStylesArr;
|
||||
@ -300,7 +300,7 @@ export class JitCompiler implements Compiler {
|
||||
}
|
||||
|
||||
class CompiledTemplate {
|
||||
private _viewClass: Function = null;
|
||||
private _viewClass: Function = null !;
|
||||
isCompiled = false;
|
||||
|
||||
constructor(
|
||||
|
@ -59,7 +59,7 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
|
||||
useFactory: (parser: HtmlParser, translations: string, format: string, config: CompilerConfig,
|
||||
console: Console) =>
|
||||
new i18n.I18NHtmlParser(
|
||||
parser, translations, format, config.missingTranslation, console),
|
||||
parser, translations, format, config.missingTranslation !, console),
|
||||
deps: [
|
||||
baseHtmlParser,
|
||||
[new Optional(), new Inject(TRANSLATIONS)],
|
||||
@ -123,7 +123,7 @@ export class JitCompilerFactory implements CompilerFactory {
|
||||
},
|
||||
deps: []
|
||||
},
|
||||
opts.providers
|
||||
opts.providers !
|
||||
]);
|
||||
return injector.get(Compiler);
|
||||
}
|
||||
@ -148,12 +148,12 @@ function _mergeOptions(optionsArr: CompilerOptions[]): CompilerOptions {
|
||||
return {
|
||||
useJit: _lastDefined(optionsArr.map(options => options.useJit)),
|
||||
defaultEncapsulation: _lastDefined(optionsArr.map(options => options.defaultEncapsulation)),
|
||||
providers: _mergeArrays(optionsArr.map(options => options.providers)),
|
||||
providers: _mergeArrays(optionsArr.map(options => options.providers !)),
|
||||
missingTranslation: _lastDefined(optionsArr.map(options => options.missingTranslation)),
|
||||
};
|
||||
}
|
||||
|
||||
function _lastDefined<T>(args: T[]): T {
|
||||
function _lastDefined<T>(args: T[]): T|undefined {
|
||||
for (let i = args.length - 1; i >= 0; i--) {
|
||||
if (args[i] !== undefined) {
|
||||
return args[i];
|
||||
|
Reference in New Issue
Block a user