fix(compiler): Update types for TypeScript nullability support
This commit is contained in:
@ -33,7 +33,7 @@ export class CompilerHost implements AotCompilerHost {
|
||||
private resolverCache = new Map<string, ModuleMetadata[]>();
|
||||
private bundleIndexCache = new Map<string, boolean>();
|
||||
private bundleIndexNames = new Set<string>();
|
||||
private moduleFileNames = new Map<string, string>();
|
||||
private moduleFileNames = new Map<string, string|null>();
|
||||
protected resolveModuleNameHost: CompilerHostContext;
|
||||
|
||||
constructor(
|
||||
@ -71,7 +71,7 @@ export class CompilerHost implements AotCompilerHost {
|
||||
|
||||
moduleNameToFileName(m: string, containingFile: string): string|null {
|
||||
const key = m + ':' + (containingFile || '');
|
||||
let result = this.moduleFileNames.get(key);
|
||||
let result: string|null = this.moduleFileNames.get(key) || null;
|
||||
if (!result) {
|
||||
if (!containingFile || !containingFile.length) {
|
||||
if (m.indexOf('.') === 0) {
|
||||
@ -183,7 +183,7 @@ export class CompilerHost implements AotCompilerHost {
|
||||
return sf;
|
||||
}
|
||||
|
||||
getMetadataFor(filePath: string): ModuleMetadata[] {
|
||||
getMetadataFor(filePath: string): ModuleMetadata[]|undefined {
|
||||
if (!this.context.fileExists(filePath)) {
|
||||
// If the file doesn't exists then we cannot return metadata for the file.
|
||||
// This will occur if the user refernced a declared module for which no file
|
||||
@ -263,6 +263,7 @@ export class CompilerHost implements AotCompilerHost {
|
||||
if (this.context.fileExists(filePath)) {
|
||||
return this.context.readFile(filePath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getOutputFileName(sourceFilePath: string): string {
|
||||
@ -287,7 +288,7 @@ export class CompilerHost implements AotCompilerHost {
|
||||
|
||||
calculateEmitPath(filePath: string): string {
|
||||
// Write codegen in a directory structure matching the sources.
|
||||
let root = this.options.basePath;
|
||||
let root = this.options.basePath !;
|
||||
for (const eachRootDir of this.options.rootDirs || []) {
|
||||
if (this.options.trace) {
|
||||
console.error(`Check if ${filePath} is under rootDirs element ${eachRootDir}`);
|
||||
@ -373,7 +374,7 @@ export class ModuleResolutionHostAdapter extends CompilerHostContextAdapter impl
|
||||
constructor(private host: ts.ModuleResolutionHost) {
|
||||
super();
|
||||
if (host.directoryExists) {
|
||||
this.directoryExists = (directoryName: string) => host.directoryExists(directoryName);
|
||||
this.directoryExists = (directoryName: string) => host.directoryExists !(directoryName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ function extract(
|
||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
||||
program: ts.Program, host: ts.CompilerHost): Promise<void> {
|
||||
return Extractor.create(ngOptions, program, host, cliOptions.locale)
|
||||
.extract(cliOptions.i18nFormat, cliOptions.outFile);
|
||||
.extract(cliOptions.i18nFormat !, cliOptions.outFile);
|
||||
}
|
||||
|
||||
// Entry point
|
||||
|
@ -92,9 +92,9 @@ export class NgTools_InternalApi_NG_2 {
|
||||
const hostContext: CompilerHostContext =
|
||||
new CustomLoaderModuleResolutionHostAdapter(options.readResource, options.host);
|
||||
const cliOptions: NgcCliOptions = {
|
||||
i18nFormat: options.i18nFormat,
|
||||
i18nFile: options.i18nFile,
|
||||
locale: options.locale,
|
||||
i18nFormat: options.i18nFormat !,
|
||||
i18nFile: options.i18nFile !,
|
||||
locale: options.locale !,
|
||||
basePath: options.basePath
|
||||
};
|
||||
|
||||
@ -148,6 +148,6 @@ export class NgTools_InternalApi_NG_2 {
|
||||
const extractor = Extractor.create(
|
||||
options.angularCompilerOptions, options.program, options.host, locale, hostContext);
|
||||
|
||||
return extractor.extract(options.i18nFormat, options.outFile || null);
|
||||
return extractor.extract(options.i18nFormat !, options.outFile || null);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ export type LazyRouteMap = {
|
||||
// A route definition. Normally the short form 'path/to/module#ModuleClassName' is used by
|
||||
// the user, and this is a helper class to extract information from it.
|
||||
export class RouteDef {
|
||||
private constructor(public readonly path: string, public readonly className: string = null) {}
|
||||
private constructor(public readonly path: string, public readonly className: string|null = null) {
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (this.className === null || this.className == 'default') ?
|
||||
@ -58,7 +59,7 @@ export function listLazyRoutesOfModule(
|
||||
const entryRouteDef = RouteDef.fromString(entryModule);
|
||||
const containingFile = _resolveModule(entryRouteDef.path, entryRouteDef.path, host);
|
||||
const modulePath = `./${containingFile.replace(/^(.*)\//, '')}`;
|
||||
const className = entryRouteDef.className;
|
||||
const className = entryRouteDef.className !;
|
||||
|
||||
// List loadChildren of this single module.
|
||||
const appStaticSymbol = reflector.findDeclaration(modulePath, className, containingFile);
|
||||
|
@ -40,7 +40,7 @@ export class PathMappedCompilerHost extends CompilerHost {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
moduleNameToFileName(m: string, containingFile: string) {
|
||||
moduleNameToFileName(m: string, containingFile: string): string|null {
|
||||
if (!containingFile || !containingFile.length) {
|
||||
if (m.indexOf('.') === 0) {
|
||||
throw new Error('Resolution of relative paths requires a containing file.');
|
||||
@ -59,6 +59,7 @@ export class PathMappedCompilerHost extends CompilerHost {
|
||||
return this.getCanonicalFileName(resolved.resolvedFileName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +91,7 @@ export class PathMappedCompilerHost extends CompilerHost {
|
||||
|
||||
const importModuleName = importedFile.replace(EXT, '');
|
||||
const parts = importModuleName.split(path.sep).filter(p => !!p);
|
||||
let foundRelativeImport: string;
|
||||
let foundRelativeImport: string = undefined !;
|
||||
for (let index = parts.length - 1; index >= 0; index--) {
|
||||
let candidate = parts.slice(index, parts.length).join(path.sep);
|
||||
if (resolvable(candidate)) {
|
||||
@ -135,5 +136,6 @@ export class PathMappedCompilerHost extends CompilerHost {
|
||||
return metadata ? [metadata] : [];
|
||||
}
|
||||
}
|
||||
return null !;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
"declaration": true,
|
||||
"experimentalDecorators": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"module": "commonjs",
|
||||
"outDir": "../../dist/packages/compiler-cli",
|
||||
"paths": {
|
||||
|
Reference in New Issue
Block a user