From 8d3d75e454dc27bcfad8f654e99afe1e20f8dfdd Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Fri, 29 Mar 2019 10:13:14 +0000 Subject: [PATCH] feat(compiler-cli): ngcc - make logging more configurable (#29591) This allows CLI usage to filter excessive log messages and integrations like webpack plugins to provide their own logger. // FW-1198 PR Close #29591 --- packages/compiler-cli/ngcc/index.ts | 2 + packages/compiler-cli/ngcc/main-ngcc.ts | 18 +- .../ngcc/src/host/esm2015_host.ts | 7 +- .../ngcc/src/logging/console_logger.ts | 46 +++++ .../compiler-cli/ngcc/src/logging/logger.ts | 18 ++ packages/compiler-cli/ngcc/src/main.ts | 28 +-- .../ngcc/src/packages/dependency_resolver.ts | 6 +- .../ngcc/src/packages/entry_point.ts | 10 +- .../ngcc/src/packages/entry_point_finder.ts | 164 +++++++++--------- .../ngcc/src/packages/transformer.ts | 11 +- .../ngcc/src/rendering/esm5_renderer.ts | 6 +- .../ngcc/src/rendering/esm_renderer.ts | 6 +- .../ngcc/src/rendering/renderer.ts | 9 +- .../test/analysis/decoration_analyzer_spec.ts | 4 +- .../module_with_providers_analyzer_spec.ts | 4 +- .../private_declarations_analyzer_spec.ts | 3 +- .../analysis/switch_marker_analyzer_spec.ts | 3 +- .../ngcc/test/helpers/mock_logger.ts | 17 ++ .../host/esm2015_host_import_helper_spec.ts | 34 ++-- .../ngcc/test/host/esm2015_host_spec.ts | 140 ++++++++------- .../test/host/esm5_host_import_helper_spec.ts | 37 ++-- .../ngcc/test/host/esm5_host_spec.ts | 145 ++++++++-------- .../ngcc/test/integration/ngcc_spec.ts | 16 ++ .../ngcc/test/logging/console_logger_spec.ts | 50 ++++++ .../test/packages/dependency_resolver_spec.ts | 6 +- .../test/packages/entry_point_finder_spec.ts | 5 +- .../ngcc/test/packages/entry_point_spec.ts | 26 ++- .../test/rendering/esm2015_renderer_spec.ts | 6 +- .../ngcc/test/rendering/esm5_renderer_spec.ts | 6 +- .../ngcc/test/rendering/renderer_spec.ts | 12 +- .../new_entry_point_file_writer_spec.ts | 10 +- 31 files changed, 544 insertions(+), 311 deletions(-) create mode 100644 packages/compiler-cli/ngcc/src/logging/console_logger.ts create mode 100644 packages/compiler-cli/ngcc/src/logging/logger.ts create mode 100644 packages/compiler-cli/ngcc/test/helpers/mock_logger.ts create mode 100644 packages/compiler-cli/ngcc/test/logging/console_logger_spec.ts diff --git a/packages/compiler-cli/ngcc/index.ts b/packages/compiler-cli/ngcc/index.ts index 463a5194d2..dc63ad76b8 100644 --- a/packages/compiler-cli/ngcc/index.ts +++ b/packages/compiler-cli/ngcc/index.ts @@ -9,6 +9,8 @@ import {hasBeenProcessed as _hasBeenProcessed} from './src/packages/build_marker'; import {EntryPointJsonProperty, EntryPointPackageJson} from './src/packages/entry_point'; +export {ConsoleLogger, LogLevel} from './src/logging/console_logger'; +export {Logger} from './src/logging/logger'; export {NgccOptions, mainNgcc as process} from './src/main'; export function hasBeenProcessed(packageJson: object, format: string) { diff --git a/packages/compiler-cli/ngcc/main-ngcc.ts b/packages/compiler-cli/ngcc/main-ngcc.ts index 50d7d1ed6a..a5ae11dc8e 100644 --- a/packages/compiler-cli/ngcc/main-ngcc.ts +++ b/packages/compiler-cli/ngcc/main-ngcc.ts @@ -10,6 +10,7 @@ import * as path from 'canonical-path'; import * as yargs from 'yargs'; import {mainNgcc} from './src/main'; +import {ConsoleLogger, LogLevel} from './src/logging/console_logger'; // CLI entry point if (require.main === module) { @@ -39,9 +40,14 @@ if (require.main === module) { }) .option('first-only', { describe: - 'If specified then only the first matching package.json property will be compiled', + 'If specified then only the first matching package.json property will be compiled.', type: 'boolean' }) + .option('l', { + alias: 'loglevel', + describe: 'The lowest severity logging message that should be output.', + choices: ['debug', 'info', 'warn', 'error'], + }) .help() .parse(args); @@ -54,9 +60,15 @@ if (require.main === module) { const propertiesToConsider: string[] = options['p']; const targetEntryPointPath = options['t'] ? options['t'] : undefined; const compileAllFormats = !options['first-only']; + const logLevel = options['l'] as keyof typeof LogLevel; try { - mainNgcc( - {basePath: baseSourcePath, propertiesToConsider, targetEntryPointPath, compileAllFormats}); + mainNgcc({ + basePath: baseSourcePath, + propertiesToConsider, + targetEntryPointPath, + compileAllFormats, + logger: new ConsoleLogger(LogLevel[logLevel]), + }); process.exitCode = 0; } catch (e) { console.error(e.stack || e.message); diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index b370b7347d..1ee3f154aa 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -9,6 +9,7 @@ import * as ts from 'typescript'; import {ClassDeclaration, ClassMember, ClassMemberKind, ClassSymbol, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../src/ngtsc/reflection'; +import {Logger} from '../logging/logger'; import {BundleProgram} from '../packages/bundle_program'; import {findAll, getNameText, hasNameIdentifier, isDefined} from '../utils'; @@ -49,7 +50,9 @@ export const CONSTRUCTOR_PARAMS = 'ctorParameters' as ts.__String; */ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements NgccReflectionHost { protected dtsDeclarationMap: Map|null; - constructor(protected isCore: boolean, checker: ts.TypeChecker, dts?: BundleProgram|null) { + constructor( + protected logger: Logger, protected isCore: boolean, checker: ts.TypeChecker, + dts?: BundleProgram|null) { super(checker); this.dtsDeclarationMap = dts && this.computeDtsDeclarationMap(dts.path, dts.program) || null; } @@ -848,7 +851,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N } if (kind === null) { - console.warn(`Unknown member type: "${node.getText()}`); + this.logger.warn(`Unknown member type: "${node.getText()}`); return null; } diff --git a/packages/compiler-cli/ngcc/src/logging/console_logger.ts b/packages/compiler-cli/ngcc/src/logging/console_logger.ts new file mode 100644 index 0000000000..7f358a13b6 --- /dev/null +++ b/packages/compiler-cli/ngcc/src/logging/console_logger.ts @@ -0,0 +1,46 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +import {Logger} from './logger'; + +const RESET = '\x1b[0m'; +const RED = '\x1b[31m'; +const YELLOW = '\x1b[33m'; +const BLUE = '\x1b[36m'; + +export const DEBUG = `${BLUE}Debug:${RESET}`; +export const WARN = `${YELLOW}Warning:${RESET}`; +export const ERROR = `${RED}Error:${RESET}`; + +export enum LogLevel { + debug, + info, + warn, + error, +} + +/** + * A simple logger that outputs directly to the Console. + * + * The log messages can be filtered based on severity via the `logLevel` + * constructor parameter. + */ +export class ConsoleLogger implements Logger { + constructor(private logLevel: LogLevel) {} + debug(...args: string[]) { + if (this.logLevel <= LogLevel.debug) console.debug(DEBUG, ...args); + } + info(...args: string[]) { + if (this.logLevel <= LogLevel.info) console.info(...args); + } + warn(...args: string[]) { + if (this.logLevel <= LogLevel.warn) console.warn(WARN, ...args); + } + error(...args: string[]) { + if (this.logLevel <= LogLevel.error) console.error(ERROR, ...args); + } +} diff --git a/packages/compiler-cli/ngcc/src/logging/logger.ts b/packages/compiler-cli/ngcc/src/logging/logger.ts new file mode 100644 index 0000000000..ed260081ee --- /dev/null +++ b/packages/compiler-cli/ngcc/src/logging/logger.ts @@ -0,0 +1,18 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * Implement this interface if you want to provide different logging + * output from the standard ConsoleLogger. + */ +export interface Logger { + debug(...args: string[]): void; + info(...args: string[]): void; + warn(...args: string[]): void; + error(...args: string[]): void; +} diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 3e9d6cec11..4dc7fa47d4 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -11,6 +11,8 @@ import {readFileSync} from 'fs'; import {AbsoluteFsPath} from '../../src/ngtsc/path'; +import {ConsoleLogger, LogLevel} from './logging/console_logger'; +import {Logger} from './logging/logger'; import {hasBeenProcessed, markAsProcessed} from './packages/build_marker'; import {DependencyHost} from './packages/dependency_host'; import {DependencyResolver} from './packages/dependency_resolver'; @@ -23,6 +25,7 @@ import {InPlaceFileWriter} from './writing/in_place_file_writer'; import {NewEntryPointFileWriter} from './writing/new_entry_point_file_writer'; + /** * The options to configure the ngcc compiler. */ @@ -50,6 +53,10 @@ export interface NgccOptions { * Whether to create new entry-points bundles rather than overwriting the original files. */ createNewEntryPointFormats?: boolean; + /** + * Provide a logger that will be called with log messages. + */ + logger?: Logger; } const SUPPORTED_FORMATS: EntryPointFormat[] = ['esm5', 'esm2015']; @@ -62,13 +69,14 @@ const SUPPORTED_FORMATS: EntryPointFormat[] = ['esm5', 'esm2015']; * * @param options The options telling ngcc what to compile and how. */ -export function mainNgcc( - {basePath, targetEntryPointPath, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES, - compileAllFormats = true, createNewEntryPointFormats = false}: NgccOptions): void { - const transformer = new Transformer(basePath); +export function mainNgcc({basePath, targetEntryPointPath, + propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES, + compileAllFormats = true, createNewEntryPointFormats = false, + logger = new ConsoleLogger(LogLevel.info)}: NgccOptions): void { + const transformer = new Transformer(logger, basePath); const host = new DependencyHost(); - const resolver = new DependencyResolver(host); - const finder = new EntryPointFinder(resolver); + const resolver = new DependencyResolver(logger, host); + const finder = new EntryPointFinder(logger, resolver); const fileWriter = getFileWriter(createNewEntryPointFormats); const absoluteTargetEntryPointPath = targetEntryPointPath ? @@ -112,7 +120,7 @@ export function mainNgcc( if (hasBeenProcessed(entryPointPackageJson, property)) { compiledFormats.add(formatPath); - console.warn(`Skipping ${entryPoint.name} : ${property} (already compiled).`); + logger.info(`Skipping ${entryPoint.name} : ${property} (already compiled).`); continue; } @@ -123,16 +131,16 @@ export function mainNgcc( entryPoint.path, formatPath, entryPoint.typings, isCore, property, format, compiledFormats.size === 0); if (bundle) { - console.warn(`Compiling ${entryPoint.name} : ${property} as ${format}`); + logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`); const transformedFiles = transformer.transform(bundle); fileWriter.writeBundle(entryPoint, bundle, transformedFiles); compiledFormats.add(formatPath); } else { - console.warn( + logger.warn( `Skipping ${entryPoint.name} : ${format} (no valid entry point file for this format).`); } } else if (!compileAllFormats) { - console.warn(`Skipping ${entryPoint.name} : ${property} (already compiled).`); + logger.info(`Skipping ${entryPoint.name} : ${property} (already compiled).`); } // Either this format was just compiled or its underlying format was compiled because of a diff --git a/packages/compiler-cli/ngcc/src/packages/dependency_resolver.ts b/packages/compiler-cli/ngcc/src/packages/dependency_resolver.ts index 8d151cd68e..59737ed322 100644 --- a/packages/compiler-cli/ngcc/src/packages/dependency_resolver.ts +++ b/packages/compiler-cli/ngcc/src/packages/dependency_resolver.ts @@ -10,6 +10,8 @@ import {resolve} from 'canonical-path'; import {DepGraph} from 'dependency-graph'; import {AbsoluteFsPath} from '../../../src/ngtsc/path'; +import {Logger} from '../logging/logger'; + import {DependencyHost} from './dependency_host'; import {EntryPoint, EntryPointJsonProperty, getEntryPointFormat} from './entry_point'; @@ -65,7 +67,7 @@ export interface SortedEntryPointsInfo { * A class that resolves dependencies between entry-points. */ export class DependencyResolver { - constructor(private host: DependencyHost) {} + constructor(private logger: Logger, private host: DependencyHost) {} /** * Sort the array of entry points so that the dependant entry points always come later than * their dependencies in the array. @@ -134,7 +136,7 @@ export class DependencyResolver { if (deepImports.size) { const imports = Array.from(deepImports).map(i => `'${i}'`).join(', '); - console.warn( + this.logger.warn( `Entry point '${entryPoint.name}' contains deep imports into ${imports}. ` + `This is probably not a problem, but may cause the compilation of entry points to be out of order.`); } diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point.ts b/packages/compiler-cli/ngcc/src/packages/entry_point.ts index c80d197806..a51ce1f25f 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point.ts @@ -10,6 +10,7 @@ import * as path from 'canonical-path'; import * as fs from 'fs'; import {AbsoluteFsPath} from '../../../src/ngtsc/path'; +import {Logger} from '../logging/logger'; /** @@ -67,13 +68,13 @@ export const SUPPORTED_FORMAT_PROPERTIES: EntryPointJsonProperty[] = * @returns An entry-point if it is valid, `null` otherwise. */ export function getEntryPointInfo( - packagePath: AbsoluteFsPath, entryPointPath: AbsoluteFsPath): EntryPoint|null { + logger: Logger, packagePath: AbsoluteFsPath, entryPointPath: AbsoluteFsPath): EntryPoint|null { const packageJsonPath = path.resolve(entryPointPath, 'package.json'); if (!fs.existsSync(packageJsonPath)) { return null; } - const entryPointPackageJson = loadEntryPointPackage(packageJsonPath); + const entryPointPackageJson = loadEntryPointPackage(logger, packageJsonPath); if (!entryPointPackageJson) { return null; } @@ -135,12 +136,13 @@ export function getEntryPointFormat(property: string): EntryPointFormat|undefine * @param packageJsonPath the absolute path to the package.json file. * @returns JSON from the package.json file if it is valid, `null` otherwise. */ -function loadEntryPointPackage(packageJsonPath: string): EntryPointPackageJson|null { +function loadEntryPointPackage(logger: Logger, packageJsonPath: string): EntryPointPackageJson| + null { try { return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); } catch (e) { // We may have run into a package.json with unexpected symbols - console.warn(`Failed to read entry point info from ${packageJsonPath} with error ${e}.`); + logger.warn(`Failed to read entry point info from ${packageJsonPath} with error ${e}.`); return null; } } diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point_finder.ts b/packages/compiler-cli/ngcc/src/packages/entry_point_finder.ts index 89b47c15c2..bbb2f51778 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_finder.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_finder.ts @@ -9,109 +9,111 @@ import * as path from 'canonical-path'; import * as fs from 'fs'; import {AbsoluteFsPath} from '../../../src/ngtsc/path'; +import {Logger} from '../logging/logger'; + import {DependencyResolver, SortedEntryPointsInfo} from './dependency_resolver'; import {EntryPoint, getEntryPointInfo} from './entry_point'; export class EntryPointFinder { - constructor(private resolver: DependencyResolver) {} + constructor(private logger: Logger, private resolver: DependencyResolver) {} /** * Search the given directory, and sub-directories, for Angular package entry points. * @param sourceDirectory An absolute path to the directory to search for entry points. */ findEntryPoints(sourceDirectory: AbsoluteFsPath, targetEntryPointPath?: AbsoluteFsPath): SortedEntryPointsInfo { - const unsortedEntryPoints = walkDirectoryForEntryPoints(sourceDirectory); + const unsortedEntryPoints = this.walkDirectoryForEntryPoints(sourceDirectory); const targetEntryPoint = targetEntryPointPath ? unsortedEntryPoints.find(entryPoint => entryPoint.path === targetEntryPointPath) : undefined; return this.resolver.sortEntryPointsByDependency(unsortedEntryPoints, targetEntryPoint); } -} -/** - * Look for entry points that need to be compiled, starting at the source directory. - * The function will recurse into directories that start with `@...`, e.g. `@angular/...`. - * @param sourceDirectory An absolute path to the root directory where searching begins. - */ -function walkDirectoryForEntryPoints(sourceDirectory: AbsoluteFsPath): EntryPoint[] { - const entryPoints: EntryPoint[] = []; - fs.readdirSync(sourceDirectory) - // Not interested in hidden files - .filter(p => !p.startsWith('.')) - // Ignore node_modules - .filter(p => p !== 'node_modules') - // Only interested in directories (and only those that are not symlinks) - .filter(p => { - const stat = fs.lstatSync(path.resolve(sourceDirectory, p)); - return stat.isDirectory() && !stat.isSymbolicLink(); - }) - .forEach(p => { - // Either the directory is a potential package or a namespace containing packages (e.g - // `@angular`). - const packagePath = AbsoluteFsPath.from(path.join(sourceDirectory, p)); - if (p.startsWith('@')) { - entryPoints.push(...walkDirectoryForEntryPoints(packagePath)); - } else { - entryPoints.push(...getEntryPointsForPackage(packagePath)); + /** + * Look for entry points that need to be compiled, starting at the source directory. + * The function will recurse into directories that start with `@...`, e.g. `@angular/...`. + * @param sourceDirectory An absolute path to the root directory where searching begins. + */ + private walkDirectoryForEntryPoints(sourceDirectory: AbsoluteFsPath): EntryPoint[] { + const entryPoints: EntryPoint[] = []; + fs.readdirSync(sourceDirectory) + // Not interested in hidden files + .filter(p => !p.startsWith('.')) + // Ignore node_modules + .filter(p => p !== 'node_modules') + // Only interested in directories (and only those that are not symlinks) + .filter(p => { + const stat = fs.lstatSync(path.resolve(sourceDirectory, p)); + return stat.isDirectory() && !stat.isSymbolicLink(); + }) + .forEach(p => { + // Either the directory is a potential package or a namespace containing packages (e.g + // `@angular`). + const packagePath = AbsoluteFsPath.from(path.join(sourceDirectory, p)); + if (p.startsWith('@')) { + entryPoints.push(...this.walkDirectoryForEntryPoints(packagePath)); + } else { + entryPoints.push(...this.getEntryPointsForPackage(packagePath)); - // Also check for any nested node_modules in this package - const nestedNodeModulesPath = - AbsoluteFsPath.from(path.resolve(packagePath, 'node_modules')); - if (fs.existsSync(nestedNodeModulesPath)) { - entryPoints.push(...walkDirectoryForEntryPoints(nestedNodeModulesPath)); + // Also check for any nested node_modules in this package + const nestedNodeModulesPath = + AbsoluteFsPath.from(path.resolve(packagePath, 'node_modules')); + if (fs.existsSync(nestedNodeModulesPath)) { + entryPoints.push(...this.walkDirectoryForEntryPoints(nestedNodeModulesPath)); + } } - } - }); - return entryPoints; -} - -/** - * Recurse the folder structure looking for all the entry points - * @param packagePath The absolute path to an npm package that may contain entry points - * @returns An array of entry points that were discovered. - */ -function getEntryPointsForPackage(packagePath: AbsoluteFsPath): EntryPoint[] { - const entryPoints: EntryPoint[] = []; - - // Try to get an entry point from the top level package directory - const topLevelEntryPoint = getEntryPointInfo(packagePath, packagePath); - if (topLevelEntryPoint !== null) { - entryPoints.push(topLevelEntryPoint); + }); + return entryPoints; } - // Now search all the directories of this package for possible entry points - walkDirectory(packagePath, subdir => { - const subEntryPoint = getEntryPointInfo(packagePath, subdir); - if (subEntryPoint !== null) { - entryPoints.push(subEntryPoint); + /** + * Recurse the folder structure looking for all the entry points + * @param packagePath The absolute path to an npm package that may contain entry points + * @returns An array of entry points that were discovered. + */ + private getEntryPointsForPackage(packagePath: AbsoluteFsPath): EntryPoint[] { + const entryPoints: EntryPoint[] = []; + + // Try to get an entry point from the top level package directory + const topLevelEntryPoint = getEntryPointInfo(this.logger, packagePath, packagePath); + if (topLevelEntryPoint !== null) { + entryPoints.push(topLevelEntryPoint); } - }); - return entryPoints; -} + // Now search all the directories of this package for possible entry points + this.walkDirectory(packagePath, subdir => { + const subEntryPoint = getEntryPointInfo(this.logger, packagePath, subdir); + if (subEntryPoint !== null) { + entryPoints.push(subEntryPoint); + } + }); -/** - * Recursively walk a directory and its sub-directories, applying a given - * function to each directory. - * @param dir the directory to recursively walk. - * @param fn the function to apply to each directory. - */ -function walkDirectory(dir: AbsoluteFsPath, fn: (dir: AbsoluteFsPath) => void) { - return fs - .readdirSync(dir) - // Not interested in hidden files - .filter(p => !p.startsWith('.')) - // Ignore node_modules - .filter(p => p !== 'node_modules') - // Only interested in directories (and only those that are not symlinks) - .filter(p => { - const stat = fs.lstatSync(path.resolve(dir, p)); - return stat.isDirectory() && !stat.isSymbolicLink(); - }) - .forEach(subDir => { - const resolvedSubDir = AbsoluteFsPath.from(path.resolve(dir, subDir)); - fn(resolvedSubDir); - walkDirectory(resolvedSubDir, fn); - }); + return entryPoints; + } + + /** + * Recursively walk a directory and its sub-directories, applying a given + * function to each directory. + * @param dir the directory to recursively walk. + * @param fn the function to apply to each directory. + */ + private walkDirectory(dir: AbsoluteFsPath, fn: (dir: AbsoluteFsPath) => void) { + return fs + .readdirSync(dir) + // Not interested in hidden files + .filter(p => !p.startsWith('.')) + // Ignore node_modules + .filter(p => p !== 'node_modules') + // Only interested in directories (and only those that are not symlinks) + .filter(p => { + const stat = fs.lstatSync(path.resolve(dir, p)); + return stat.isDirectory() && !stat.isSymbolicLink(); + }) + .forEach(subDir => { + const resolvedSubDir = AbsoluteFsPath.from(path.resolve(dir, subDir)); + fn(resolvedSubDir); + this.walkDirectory(resolvedSubDir, fn); + }); + } } diff --git a/packages/compiler-cli/ngcc/src/packages/transformer.ts b/packages/compiler-cli/ngcc/src/packages/transformer.ts index f46312d3e9..f4a9e76753 100644 --- a/packages/compiler-cli/ngcc/src/packages/transformer.ts +++ b/packages/compiler-cli/ngcc/src/packages/transformer.ts @@ -15,6 +15,7 @@ import {SwitchMarkerAnalyses, SwitchMarkerAnalyzer} from '../analysis/switch_mar import {Esm2015ReflectionHost} from '../host/esm2015_host'; import {Esm5ReflectionHost} from '../host/esm5_host'; import {NgccReflectionHost} from '../host/ngcc_host'; +import {Logger} from '../logging/logger'; import {Esm5Renderer} from '../rendering/esm5_renderer'; import {EsmRenderer} from '../rendering/esm_renderer'; import {FileInfo, Renderer} from '../rendering/renderer'; @@ -45,7 +46,7 @@ import {EntryPointBundle} from './entry_point_bundle'; * - Some formats may contain multiple "modules" in a single file. */ export class Transformer { - constructor(private sourcePath: string) {} + constructor(private logger: Logger, private sourcePath: string) {} /** * Transform the source (and typings) files of a bundle. @@ -73,9 +74,9 @@ export class Transformer { const typeChecker = bundle.src.program.getTypeChecker(); switch (bundle.format) { case 'esm2015': - return new Esm2015ReflectionHost(isCore, typeChecker, bundle.dts); + return new Esm2015ReflectionHost(this.logger, isCore, typeChecker, bundle.dts); case 'esm5': - return new Esm5ReflectionHost(isCore, typeChecker, bundle.dts); + return new Esm5ReflectionHost(this.logger, isCore, typeChecker, bundle.dts); default: throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`); } @@ -84,9 +85,9 @@ export class Transformer { getRenderer(host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle): Renderer { switch (bundle.format) { case 'esm2015': - return new EsmRenderer(host, isCore, bundle, this.sourcePath); + return new EsmRenderer(this.logger, host, isCore, bundle, this.sourcePath); case 'esm5': - return new Esm5Renderer(host, isCore, bundle, this.sourcePath); + return new Esm5Renderer(this.logger, host, isCore, bundle, this.sourcePath); default: throw new Error(`Renderer for "${bundle.format}" not yet implemented.`); } diff --git a/packages/compiler-cli/ngcc/src/rendering/esm5_renderer.ts b/packages/compiler-cli/ngcc/src/rendering/esm5_renderer.ts index 382b1ff1c8..9268fef45b 100644 --- a/packages/compiler-cli/ngcc/src/rendering/esm5_renderer.ts +++ b/packages/compiler-cli/ngcc/src/rendering/esm5_renderer.ts @@ -12,11 +12,13 @@ import {NgccReflectionHost} from '../host/ngcc_host'; import {CompiledClass} from '../analysis/decoration_analyzer'; import {EsmRenderer} from './esm_renderer'; import {EntryPointBundle} from '../packages/entry_point_bundle'; +import {Logger} from '../logging/logger'; export class Esm5Renderer extends EsmRenderer { constructor( - host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, sourcePath: string) { - super(host, isCore, bundle, sourcePath); + logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, + sourcePath: string) { + super(logger, host, isCore, bundle, sourcePath); } /** diff --git a/packages/compiler-cli/ngcc/src/rendering/esm_renderer.ts b/packages/compiler-cli/ngcc/src/rendering/esm_renderer.ts index 45cf8da203..8de2a47f46 100644 --- a/packages/compiler-cli/ngcc/src/rendering/esm_renderer.ts +++ b/packages/compiler-cli/ngcc/src/rendering/esm_renderer.ts @@ -14,11 +14,13 @@ import {RedundantDecoratorMap, Renderer, stripExtension} from './renderer'; import {EntryPointBundle} from '../packages/entry_point_bundle'; import {ExportInfo} from '../analysis/private_declarations_analyzer'; import {isDtsPath} from '../../../src/ngtsc/util/src/typescript'; +import {Logger} from '../logging/logger'; export class EsmRenderer extends Renderer { constructor( - host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, sourcePath: string) { - super(host, isCore, bundle, sourcePath); + logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, + sourcePath: string) { + super(logger, host, isCore, bundle, sourcePath); } /** diff --git a/packages/compiler-cli/ngcc/src/rendering/renderer.ts b/packages/compiler-cli/ngcc/src/rendering/renderer.ts index 9f4d05f3ae..89c2502023 100644 --- a/packages/compiler-cli/ngcc/src/rendering/renderer.ts +++ b/packages/compiler-cli/ngcc/src/rendering/renderer.ts @@ -24,6 +24,7 @@ import {SwitchMarkerAnalyses, SwitchMarkerAnalysis} from '../analysis/switch_mar import {IMPORT_PREFIX} from '../constants'; import {NgccReflectionHost, SwitchableVariableDeclaration} from '../host/ngcc_host'; import {EntryPointBundle} from '../packages/entry_point_bundle'; +import {Logger} from '../logging/logger'; interface SourceMapInfo { source: string; @@ -80,7 +81,7 @@ export const RedundantDecoratorMap = Map; */ export abstract class Renderer { constructor( - protected host: NgccReflectionHost, protected isCore: boolean, + protected logger: Logger, protected host: NgccReflectionHost, protected isCore: boolean, protected bundle: EntryPointBundle, protected sourcePath: string) {} renderProgram( @@ -299,16 +300,16 @@ export abstract class Renderer { externalSourceMap = fromMapFileSource(file.text, dirname(file.fileName)); } catch (e) { if (e.code === 'ENOENT') { - console.warn( + this.logger.warn( `The external map file specified in the source code comment "${e.path}" was not found on the file system.`); const mapPath = file.fileName + '.map'; if (basename(e.path) !== basename(mapPath) && statSync(mapPath).isFile()) { - console.warn( + this.logger.warn( `Guessing the map file name from the source file name: "${basename(mapPath)}"`); try { externalSourceMap = fromObject(JSON.parse(readFileSync(mapPath, 'utf8'))); } catch (e) { - console.error(e); + this.logger.error(e); } } } diff --git a/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts index b3ae542714..c3f629bacd 100644 --- a/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/decoration_analyzer_spec.ts @@ -13,6 +13,7 @@ import {DecoratorHandler, DetectResult} from '../../../src/ngtsc/transform'; import {CompiledClass, DecorationAnalyses, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer'; import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; +import {MockLogger} from '../helpers/mock_logger'; import {makeTestBundleProgram} from '../helpers/utils'; const TEST_PROGRAM = [ @@ -132,7 +133,8 @@ describe('DecorationAnalyzer', () => { const {options, host, ...bundle} = makeTestBundleProgram(...progArgs); program = bundle.program; - const reflectionHost = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const reflectionHost = + new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const referencesRegistry = new NgccReferencesRegistry(reflectionHost); const analyzer = new DecorationAnalyzer( program, options, host, program.getTypeChecker(), reflectionHost, referencesRegistry, diff --git a/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts index f8fa294b14..22a3a93ea5 100644 --- a/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts @@ -11,6 +11,7 @@ import {ModuleWithProvidersAnalyses, ModuleWithProvidersAnalyzer} from '../../sr import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {BundleProgram} from '../../src/packages/bundle_program'; +import {MockLogger} from '../helpers/mock_logger'; import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils'; const TEST_PROGRAM = [ @@ -321,7 +322,8 @@ describe('ModuleWithProvidersAnalyzer', () => { beforeAll(() => { program = makeTestProgram(...TEST_PROGRAM); dtsProgram = makeTestBundleProgram(TEST_DTS_PROGRAM); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker(), dtsProgram); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dtsProgram); referencesRegistry = new NgccReferencesRegistry(host); const analyzer = new ModuleWithProvidersAnalyzer(host, referencesRegistry); diff --git a/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts index 05504261d5..85a7edda8e 100644 --- a/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/private_declarations_analyzer_spec.ts @@ -12,6 +12,7 @@ import {Reference} from '../../../src/ngtsc/imports'; import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; import {PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; +import {MockLogger} from '../helpers/mock_logger'; import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils'; describe('PrivateDeclarationsAnalyzer', () => { @@ -222,7 +223,7 @@ type Files = { function setup(jsProgram: Files, dtsProgram: Files) { const program = makeTestProgram(...jsProgram); const dts = makeTestBundleProgram(dtsProgram); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker(), dts); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); const referencesRegistry = new NgccReferencesRegistry(host); const analyzer = new PrivateDeclarationsAnalyzer(host, referencesRegistry); return {program, referencesRegistry, analyzer}; diff --git a/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts index ff27fd9d1c..5edbfb827b 100644 --- a/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/switch_marker_analyzer_spec.ts @@ -9,6 +9,7 @@ import * as ts from 'typescript'; import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; +import {MockLogger} from '../helpers/mock_logger'; import {makeTestProgram} from '../helpers/utils'; const TEST_PROGRAM = [ @@ -47,7 +48,7 @@ describe('SwitchMarkerAnalyzer', () => { describe('analyzeProgram()', () => { it('should check for switchable markers in all the files of the program', () => { const program = makeTestProgram(...TEST_PROGRAM); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const analyzer = new SwitchMarkerAnalyzer(host); const analysis = analyzer.analyzeProgram(program); diff --git a/packages/compiler-cli/ngcc/test/helpers/mock_logger.ts b/packages/compiler-cli/ngcc/test/helpers/mock_logger.ts new file mode 100644 index 0000000000..ddc9bfeb04 --- /dev/null +++ b/packages/compiler-cli/ngcc/test/helpers/mock_logger.ts @@ -0,0 +1,17 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {Logger} from '../../src/logging/logger'; + +export class MockLogger implements Logger { + logs: string[][] = []; + debug(...args: string[]) { this.logs.push(args); } + info(...args: string[]) { this.logs.push(args); } + warn(...args: string[]) { this.logs.push(args); } + error(...args: string[]) { this.logs.push(args); } +} \ No newline at end of file diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts index 8637a2d30b..3d71518167 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_import_helper_spec.ts @@ -10,6 +10,7 @@ import * as ts from 'typescript'; import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; +import {MockLogger} from '../helpers/mock_logger'; import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils'; import {expectTypeValueReferencesForParameters} from './util'; @@ -106,7 +107,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -130,7 +131,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { {}); const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -145,7 +146,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should support decorators being used inside @angular/core', () => { const program = makeTestProgram(fileSystem.files[1]); - const host = new Esm2015ReflectionHost(true, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -166,7 +167,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -184,7 +185,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should find non decorated properties on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -198,7 +199,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should find static methods on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -211,7 +212,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should find static properties on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -228,7 +229,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { spyOn(Esm2015ReflectionHost.prototype, 'getImportOfIdentifier').and.returnValue({}); const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -239,7 +240,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should support decorators being used inside @angular/core', () => { const program = makeTestProgram(fileSystem.files[1]); - const host = new Esm2015ReflectionHost(true, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -255,7 +256,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -278,7 +279,8 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { .and.returnValue(mockImportInfo); const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -296,7 +298,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { describe('getDeclarationOfIdentifier', () => { it('should return the declaration of a locally defined identifier', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; @@ -316,7 +318,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should return the declaration of an externally defined identifier', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -339,7 +341,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { describe('getVariableValue', () => { it('should find the "actual" declaration of an aliased variable identifier', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const ngModuleRef = findVariableDeclaration( program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1'); @@ -354,7 +356,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should return null if the variable has no assignment', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const missingValue = findVariableDeclaration( program.getSourceFile(fileSystem.files[2].name) !, 'missingValue'); const value = host.getVariableValue(missingValue !); @@ -363,7 +365,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => { it('should return null if the variable is not assigned from a call to __decorate', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const nonDecoratedVar = findVariableDeclaration( program.getSourceFile(fileSystem.files[2].name) !, 'nonDecoratedVar'); const value = host.getVariableValue(nonDecoratedVar !); diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts index 4a7ab9581b..416151d408 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts @@ -10,6 +10,7 @@ import * as ts from 'typescript'; import {ClassMemberKind, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; +import {MockLogger} from '../helpers/mock_logger'; import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils'; import {expectTypeValueReferencesForParameters} from './util'; @@ -558,7 +559,7 @@ describe('Esm2015ReflectionHost', () => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -576,7 +577,7 @@ describe('Esm2015ReflectionHost', () => { it('should return null if the symbol is not a class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const functionNode = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); @@ -585,7 +586,7 @@ describe('Esm2015ReflectionHost', () => { it('should return null if there are no decorators', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); @@ -594,7 +595,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore `decorators` if it is not an array literal', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); @@ -603,7 +604,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore decorator elements that are not object literals', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -614,7 +615,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore decorator elements that have no `type` property', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -625,7 +626,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore decorator elements whose `type` value is not an identifier', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -640,7 +641,7 @@ describe('Esm2015ReflectionHost', () => { .and.returnValue(mockImportInfo); const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -655,7 +656,7 @@ describe('Esm2015ReflectionHost', () => { describe('(returned decorators `args`)', () => { it('should be an empty array if decorator has no `args` property', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -667,7 +668,7 @@ describe('Esm2015ReflectionHost', () => { it('should be an empty array if decorator\'s `args` has no property assignment', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedClassDeclaration); @@ -680,7 +681,7 @@ describe('Esm2015ReflectionHost', () => { it('should be an empty array if `args` property value is not an array literal', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -695,7 +696,7 @@ describe('Esm2015ReflectionHost', () => { describe('getMembersOfClass()', () => { it('should find decorated properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -713,7 +714,7 @@ describe('Esm2015ReflectionHost', () => { it('should find non decorated properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -727,7 +728,7 @@ describe('Esm2015ReflectionHost', () => { it('should handle equally named getter/setter pairs correctly', () => { const program = makeTestProgram(ACCESSORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -748,7 +749,7 @@ describe('Esm2015ReflectionHost', () => { it('should find static methods on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -761,7 +762,7 @@ describe('Esm2015ReflectionHost', () => { it('should find static properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -775,7 +776,7 @@ describe('Esm2015ReflectionHost', () => { it('should throw if the symbol is not a class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const functionNode = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { @@ -785,7 +786,7 @@ describe('Esm2015ReflectionHost', () => { it('should return an empty array if there are no prop decorators', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -796,7 +797,7 @@ describe('Esm2015ReflectionHost', () => { it('should not process decorated properties in `propDecorators` if it is not an object literal', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); @@ -807,7 +808,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore prop decorator elements that are not object literals', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', isNamedClassDeclaration); @@ -821,7 +822,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore prop decorator elements that have no `type` property', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -834,7 +835,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore prop decorator elements whose `type` value is not an identifier', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -854,7 +855,7 @@ describe('Esm2015ReflectionHost', () => { }); const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -876,7 +877,7 @@ describe('Esm2015ReflectionHost', () => { describe('(returned prop decorators `args`)', () => { it('should be an empty array if prop decorator has no `args` property', () => { const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); @@ -891,7 +892,7 @@ describe('Esm2015ReflectionHost', () => { it('should be an empty array if prop decorator\'s `args` has no property assignment', () => { const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedClassDeclaration); @@ -906,7 +907,7 @@ describe('Esm2015ReflectionHost', () => { it('should be an empty array if `args` property value is not an array literal', () => { const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); @@ -924,7 +925,7 @@ describe('Esm2015ReflectionHost', () => { describe('getConstructorParameters()', () => { it('should find the decorated constructor parameters', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -938,7 +939,7 @@ describe('Esm2015ReflectionHost', () => { it('should throw if the symbol is not a class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const functionNode = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) @@ -948,7 +949,7 @@ describe('Esm2015ReflectionHost', () => { it('should return `null` if there is no constructor', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -957,7 +958,7 @@ describe('Esm2015ReflectionHost', () => { it('should return an array even if there are no decorators', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -970,7 +971,7 @@ describe('Esm2015ReflectionHost', () => { it('should return an empty array if there are no constructor parameters', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -980,7 +981,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore decorators that are not imported from core', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -994,7 +995,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore `ctorParameters` if it is not an arrow function', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1008,7 +1009,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore `ctorParameters` if it does not return an array literal', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1033,7 +1034,7 @@ describe('Esm2015ReflectionHost', () => { }; const program = makeTestProgram(file); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration); return host.getConstructorParameters(classNode); } @@ -1087,7 +1088,7 @@ describe('Esm2015ReflectionHost', () => { describe('(returned parameters `decorators`)', () => { it('should ignore param decorator elements that are not object literals', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration); @@ -1106,7 +1107,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore param decorator elements that have no `type` property', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1118,7 +1119,7 @@ describe('Esm2015ReflectionHost', () => { it('should ignore param decorator elements whose `type` value is not an identifier', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1134,7 +1135,7 @@ describe('Esm2015ReflectionHost', () => { .and.returnValue(mockImportInfo); const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const parameters = host.getConstructorParameters(classNode) !; @@ -1151,7 +1152,7 @@ describe('Esm2015ReflectionHost', () => { describe('(returned parameters `decorators.args`)', () => { it('should be an empty array if param decorator has no `args` property', () => { const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration); @@ -1166,7 +1167,7 @@ describe('Esm2015ReflectionHost', () => { it('should be an empty array if param decorator\'s `args` has no property assignment', () => { const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedClassDeclaration); @@ -1180,7 +1181,7 @@ describe('Esm2015ReflectionHost', () => { it('should be an empty array if `args` property value is not an array literal', () => { const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration); @@ -1197,7 +1198,7 @@ describe('Esm2015ReflectionHost', () => { describe('getDefinitionOfFunction()', () => { it('should return an object describing the function declaration passed as an argument', () => { const program = makeTestProgram(FUNCTION_BODY_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const fooNode = getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; @@ -1259,7 +1260,7 @@ describe('Esm2015ReflectionHost', () => { describe('getImportOfIdentifier()', () => { it('should find the import of an identifier', () => { const program = makeTestProgram(...IMPORTS_FILES); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const variableNode = getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1269,7 +1270,7 @@ describe('Esm2015ReflectionHost', () => { it('should find the name by which the identifier was exported, not imported', () => { const program = makeTestProgram(...IMPORTS_FILES); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const variableNode = getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1279,7 +1280,7 @@ describe('Esm2015ReflectionHost', () => { it('should return null if the identifier was not imported', () => { const program = makeTestProgram(...IMPORTS_FILES); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const variableNode = getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1291,7 +1292,7 @@ describe('Esm2015ReflectionHost', () => { describe('getDeclarationOfIdentifier()', () => { it('should return the declaration of a locally defined identifier', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; @@ -1311,7 +1312,7 @@ describe('Esm2015ReflectionHost', () => { it('should return the declaration of an externally defined identifier', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1331,7 +1332,7 @@ describe('Esm2015ReflectionHost', () => { describe('getExportsOfModule()', () => { it('should return a map of all the exports from a given module', () => { const program = makeTestProgram(...EXPORTS_FILES); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const file = program.getSourceFile(EXPORTS_FILES[1].name) !; const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); @@ -1366,7 +1367,7 @@ describe('Esm2015ReflectionHost', () => { describe('isClass()', () => { it('should return true if a given node is a TS class declaration', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const node = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); expect(host.isClass(node)).toBe(true); @@ -1374,7 +1375,7 @@ describe('Esm2015ReflectionHost', () => { it('should return false if a given node is a TS function declaration', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const node = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(host.isClass(node)).toBe(false); @@ -1386,7 +1387,8 @@ describe('Esm2015ReflectionHost', () => { const program = makeTestProgram(ARITY_CLASSES[0]); const dtsProgram = makeTestProgram(ARITY_CLASSES[1]); const dts = makeTestBundleProgram([ARITY_CLASSES[1]]); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); const noTypeParamClass = getDeclaration(program, '/src/class.js', 'NoTypeParam', isNamedClassDeclaration); expect(host.getGenericArityOfClass(noTypeParamClass)).toBe(0); @@ -1403,7 +1405,7 @@ describe('Esm2015ReflectionHost', () => { it('should return a collection of all the switchable variable declarations in the given module', () => { const program = makeTestProgram(MARKER_FILE); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const file = program.getSourceFile(MARKER_FILE.name) !; const declarations = host.getSwitchableDeclarations(file); expect(declarations.map(d => [d.name.getText(), d.initializer !.getText()])).toEqual([ @@ -1415,7 +1417,7 @@ describe('Esm2015ReflectionHost', () => { describe('findDecoratedClasses()', () => { it('should return an array of all decorated classes in the given source file', () => { const program = makeTestProgram(...DECORATED_FILES); - const host = new Esm2015ReflectionHost(false, program.getTypeChecker()); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const primaryFile = program.getSourceFile(DECORATED_FILES[0].name) !; const secondaryFile = program.getSourceFile(DECORATED_FILES[1].name) !; @@ -1445,7 +1447,8 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class1 = getDeclaration(srcProgram, '/src/class1.js', 'Class1', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts'); @@ -1456,7 +1459,8 @@ describe('Esm2015ReflectionHost', () => { const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES); const mooFn = getDeclaration(srcProgram, '/src/func1.js', 'mooFn', isNamedFunctionDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dtsProgram); + const host = new Esm2015ReflectionHost( + new MockLogger(), false, srcProgram.getTypeChecker(), dtsProgram); const dtsDeclaration = host.getDtsDeclaration(mooFn); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/func1.d.ts'); @@ -1467,7 +1471,8 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const missingClass = getDeclaration(srcProgram, '/src/class1.js', 'MissingClass1', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -1477,7 +1482,8 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const missingClass = getDeclaration( srcProgram, '/src/missing-class.js', 'MissingClass2', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -1488,7 +1494,8 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class1 = getDeclaration(srcProgram, '/src/flat-file.js', 'Class1', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts'); @@ -1499,7 +1506,8 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class3 = getDeclaration(srcProgram, '/src/flat-file.js', 'Class3', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class3); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class3.d.ts'); @@ -1511,7 +1519,8 @@ describe('Esm2015ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const internalClass = getDeclaration( srcProgram, '/src/internal.js', 'InternalClass', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/internal.d.ts'); @@ -1525,7 +1534,8 @@ describe('Esm2015ReflectionHost', () => { getDeclaration(srcProgram, '/src/class2.js', 'Class2', isNamedClassDeclaration); const internalClass2 = getDeclaration(srcProgram, '/src/internal.js', 'Class2', isNamedClassDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); expect(class2DtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class2.d.ts'); @@ -1540,7 +1550,8 @@ describe('Esm2015ReflectionHost', () => { it('should find every exported function that returns an object that looks like a ModuleWithProviders object', () => { const srcProgram = makeTestProgram(...MODULE_WITH_PROVIDERS_PROGRAM); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker()); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker()); const file = srcProgram.getSourceFile('/src/functions.js') !; const fns = host.getModuleWithProvidersFunctions(file); expect(fns.map(info => [info.declaration.name !.getText(), info.ngModule.text])).toEqual([ @@ -1554,7 +1565,8 @@ describe('Esm2015ReflectionHost', () => { it('should find every static method on exported classes that return an object that looks like a ModuleWithProviders object', () => { const srcProgram = makeTestProgram(...MODULE_WITH_PROVIDERS_PROGRAM); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker()); + const host = + new Esm2015ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker()); const file = srcProgram.getSourceFile('/src/methods.js') !; const fn = host.getModuleWithProvidersFunctions(file); expect(fn.map(fn => [fn.declaration.name !.getText(), fn.ngModule.text])).toEqual([ diff --git a/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts b/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts index 8cb0501a0a..ca6c593123 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_import_helper_spec.ts @@ -10,6 +10,7 @@ import * as ts from 'typescript'; import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm5ReflectionHost} from '../../src/host/esm5_host'; +import {MockLogger} from '../helpers/mock_logger'; import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils'; import {expectTypeValueReferencesForParameters} from './util'; @@ -121,7 +122,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -145,7 +146,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { {}); const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -160,7 +161,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should support decorators being used inside @angular/core', () => { const program = makeTestProgram(fileSystem.files[1]); - const host = new Esm5ReflectionHost(true, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -181,7 +182,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -199,7 +200,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should find non decorated properties on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -213,7 +214,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should find static methods on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -226,7 +227,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should find static properties on a class', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -243,7 +244,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { spyOn(Esm5ReflectionHost.prototype, 'getImportOfIdentifier').and.returnValue({}); const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -254,7 +255,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should support decorators being used inside @angular/core', () => { const program = makeTestProgram(fileSystem.files[1]); - const host = new Esm5ReflectionHost(true, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), true, program.getTypeChecker()); const classNode = getDeclaration( program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); @@ -270,7 +271,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { describe('getConstructorParameters', () => { it('should find the decorated constructor parameters', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -293,7 +294,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { .and.returnValue(mockImportInfo); const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -311,7 +312,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { describe('findDecoratedClasses', () => { it('should return an array of all decorated classes in the given source file', () => { const program = makeTestProgram(...fileSystem.files); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const ngModuleFile = program.getSourceFile('/ngmodule.js') !; const ngModuleClasses = host.findDecoratedClasses(ngModuleFile); @@ -332,7 +333,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { describe('getDeclarationOfIdentifier', () => { it('should return the declaration of a locally defined identifier', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; @@ -352,7 +353,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should return the declaration of an externally defined identifier', () => { const program = makeTestProgram(fileSystem.files[0]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -374,7 +375,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should find the "actual" declaration of an aliased variable identifier', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const ngModuleRef = findIdentifier( program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1', isNgModulePropertyAssignment); @@ -389,7 +390,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { describe('getVariableValue', () => { it('should find the "actual" declaration of an aliased variable identifier', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const ngModuleRef = findVariableDeclaration( program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1'); @@ -404,7 +405,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should return undefined if the variable has no assignment', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const missingValue = findVariableDeclaration( program.getSourceFile(fileSystem.files[2].name) !, 'missingValue'); const value = host.getVariableValue(missingValue !); @@ -413,7 +414,7 @@ describe('Esm5ReflectionHost [import helper style]', () => { it('should return null if the variable is not assigned from a call to __decorate', () => { const program = makeTestProgram(fileSystem.files[2]); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const nonDecoratedVar = findVariableDeclaration( program.getSourceFile(fileSystem.files[2].name) !, 'nonDecoratedVar'); const value = host.getVariableValue(nonDecoratedVar !); diff --git a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts index 369ec31ee7..f94e131524 100644 --- a/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm5_host_spec.ts @@ -8,9 +8,10 @@ import * as ts from 'typescript'; -import {ClassMemberKind, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; +import {ClassMemberKind, Decorator, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {Esm5ReflectionHost, getIifeBody} from '../../src/host/esm5_host'; +import {MockLogger} from '../helpers/mock_logger'; import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils'; import {expectTypeValueReferencesForParameters} from './util'; @@ -707,7 +708,7 @@ describe('Esm5ReflectionHost', () => { describe('getDecoratorsOfDeclaration()', () => { it('should find the decorators on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -725,7 +726,7 @@ describe('Esm5ReflectionHost', () => { it('should return null if the symbol is not a class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const functionNode = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const decorators = host.getDecoratorsOfDeclaration(functionNode); @@ -734,7 +735,7 @@ describe('Esm5ReflectionHost', () => { it('should return null if there are no decorators', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); @@ -743,7 +744,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore `decorators` if it is not an array literal', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode); @@ -752,18 +753,18 @@ describe('Esm5ReflectionHost', () => { it('should ignore decorator elements that are not object literals', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; expect(decorators.length).toBe(1); - expect(decorators[0]).toEqual(jasmine.objectContaining({name: 'Directive'})); + expect(decorators[0]).toEqual(jasmine.objectContaining({name: 'Directive'})); }); it('should ignore decorator elements that have no `type` property', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -774,7 +775,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore decorator elements whose `type` value is not an identifier', () => { const program = makeTestProgram(INVALID_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -789,7 +790,7 @@ describe('Esm5ReflectionHost', () => { .and.returnValue(mockImportInfo); const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const decorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -804,7 +805,7 @@ describe('Esm5ReflectionHost', () => { describe('(returned decorators `args`)', () => { it('should be an empty array if decorator has no `args` property', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); @@ -817,7 +818,7 @@ describe('Esm5ReflectionHost', () => { it('should be an empty array if decorator\'s `args` has no property assignment', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); @@ -830,7 +831,7 @@ describe('Esm5ReflectionHost', () => { it('should be an empty array if `args` property value is not an array literal', () => { const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); @@ -846,7 +847,7 @@ describe('Esm5ReflectionHost', () => { describe('getMembersOfClass()', () => { it('should find decorated members on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -864,7 +865,7 @@ describe('Esm5ReflectionHost', () => { it('should find Object.defineProperty members on a class', () => { const program = makeTestProgram(ACCESSORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -911,7 +912,7 @@ describe('Esm5ReflectionHost', () => { it('should find non decorated properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -925,7 +926,7 @@ describe('Esm5ReflectionHost', () => { it('should find static methods on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -939,7 +940,7 @@ describe('Esm5ReflectionHost', () => { it('should find static properties on a class', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -953,7 +954,7 @@ describe('Esm5ReflectionHost', () => { it('should throw if the symbol is not a class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const functionNode = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { @@ -963,7 +964,7 @@ describe('Esm5ReflectionHost', () => { it('should return an empty array if there are no prop decorators', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -974,7 +975,7 @@ describe('Esm5ReflectionHost', () => { it('should not process decorated properties in `propDecorators` if it is not an object literal', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); @@ -985,7 +986,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore prop decorator elements that are not object literals', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp', isNamedVariableDeclaration); @@ -999,7 +1000,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore prop decorator elements that have no `type` property', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -1012,7 +1013,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore prop decorator elements whose `type` value is not an identifier', () => { const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -1031,7 +1032,7 @@ describe('Esm5ReflectionHost', () => { }); const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const members = host.getMembersOfClass(classNode); @@ -1047,7 +1048,7 @@ describe('Esm5ReflectionHost', () => { describe('(returned prop decorators `args`)', () => { it('should be an empty array if prop decorator has no `args` property', () => { const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); @@ -1062,7 +1063,7 @@ describe('Esm5ReflectionHost', () => { it('should be an empty array if prop decorator\'s `args` has no property assignment', () => { const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); @@ -1077,7 +1078,7 @@ describe('Esm5ReflectionHost', () => { it('should be an empty array if `args` property value is not an array literal', () => { const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); @@ -1094,7 +1095,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore the prototype pseudo-static property on class imported from typings files', () => { const program = makeTestProgram(UNWANTED_PROTOTYPE_EXPORT_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', isNamedClassDeclaration); const members = host.getMembersOfClass(classNode); @@ -1105,7 +1106,7 @@ describe('Esm5ReflectionHost', () => { describe('getConstructorParameters()', () => { it('should find the decorated constructor parameters', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1123,7 +1124,7 @@ describe('Esm5ReflectionHost', () => { it('should throw if the symbol is not a class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const functionNode = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); expect(() => { host.getConstructorParameters(functionNode); }) @@ -1136,7 +1137,7 @@ describe('Esm5ReflectionHost', () => { it('should return an array even if there are no decorators', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedVariableDeclaration); @@ -1150,7 +1151,7 @@ describe('Esm5ReflectionHost', () => { it('should return an empty array if there are no constructor parameters', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1163,7 +1164,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore `ctorParameters` if it does not return an array literal', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); @@ -1179,7 +1180,7 @@ describe('Esm5ReflectionHost', () => { describe('(returned parameters `decorators`)', () => { it('should ignore param decorator elements that are not object literals', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration); @@ -1198,7 +1199,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore param decorator elements that have no `type` property', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration); @@ -1211,7 +1212,7 @@ describe('Esm5ReflectionHost', () => { it('should ignore param decorator elements whose `type` value is not an identifier', () => { const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration); @@ -1228,7 +1229,7 @@ describe('Esm5ReflectionHost', () => { .and.returnValue(mockImportInfo); const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const parameters = host.getConstructorParameters(classNode); @@ -1256,7 +1257,7 @@ describe('Esm5ReflectionHost', () => { }; const program = makeTestProgram(file); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); return host.getConstructorParameters(classNode); @@ -1324,7 +1325,7 @@ describe('Esm5ReflectionHost', () => { describe('(returned parameters `decorators.args`)', () => { it('should be an empty array if param decorator has no `args` property', () => { const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedVariableDeclaration); @@ -1339,7 +1340,7 @@ describe('Esm5ReflectionHost', () => { it('should be an empty array if param decorator\'s `args` has no property assignment', () => { const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment', isNamedVariableDeclaration); @@ -1353,7 +1354,7 @@ describe('Esm5ReflectionHost', () => { it('should be an empty array if `args` property value is not an array literal', () => { const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration); @@ -1370,7 +1371,7 @@ describe('Esm5ReflectionHost', () => { describe('getDefinitionOfFunction()', () => { it('should return an object describing the function declaration passed as an argument', () => { const program = makeTestProgram(FUNCTION_BODY_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const fooNode = getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !; @@ -1418,7 +1419,7 @@ describe('Esm5ReflectionHost', () => { describe('getImportOfIdentifier()', () => { it('should find the import of an identifier', () => { const program = makeTestProgram(...IMPORTS_FILES); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const variableNode = getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1428,7 +1429,7 @@ describe('Esm5ReflectionHost', () => { it('should find the name by which the identifier was exported, not imported', () => { const program = makeTestProgram(...IMPORTS_FILES); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const variableNode = getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1438,7 +1439,7 @@ describe('Esm5ReflectionHost', () => { it('should return null if the identifier was not imported', () => { const program = makeTestProgram(...IMPORTS_FILES); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const variableNode = getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration); const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier); @@ -1450,7 +1451,7 @@ describe('Esm5ReflectionHost', () => { describe('getDeclarationOfIdentifier()', () => { it('should return the declaration of a locally defined identifier', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const ctrDecorators = host.getConstructorParameters(classNode) !; @@ -1470,7 +1471,7 @@ describe('Esm5ReflectionHost', () => { it('should return the declaration of an externally defined identifier', () => { const program = makeTestProgram(SOME_DIRECTIVE_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration( program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration); const classDecorators = host.getDecoratorsOfDeclaration(classNode) !; @@ -1491,7 +1492,7 @@ describe('Esm5ReflectionHost', () => { const superGetDeclarationOfIdentifierSpy = spyOn(Esm2015ReflectionHost.prototype, 'getDeclarationOfIdentifier').and.callThrough(); const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const outerDeclaration = getDeclaration( program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); @@ -1518,7 +1519,7 @@ describe('Esm5ReflectionHost', () => { describe('getExportsOfModule()', () => { it('should return a map of all the exports from a given module', () => { const program = makeTestProgram(...EXPORTS_FILES); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const file = program.getSourceFile(EXPORTS_FILES[1].name) !; const exportDeclarations = host.getExportsOfModule(file); expect(exportDeclarations).not.toBe(null); @@ -1559,7 +1560,7 @@ describe('Esm5ReflectionHost', () => { describe('getClassSymbol()', () => { it('should return the class symbol for an ES2015 class', () => { const program = makeTestProgram(SIMPLE_ES2015_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const node = getDeclaration( program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration); const classSymbol = host.getClassSymbol(node); @@ -1570,7 +1571,7 @@ describe('Esm5ReflectionHost', () => { it('should return the class symbol for an ES5 class (outer variable declaration)', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const node = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const classSymbol = host.getClassSymbol(node); @@ -1581,7 +1582,7 @@ describe('Esm5ReflectionHost', () => { it('should return the class symbol for an ES5 class (inner function declaration)', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const outerNode = getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; @@ -1594,7 +1595,7 @@ describe('Esm5ReflectionHost', () => { it('should return the same class symbol (of the outer declaration) for outer and inner declarations', () => { const program = makeTestProgram(SIMPLE_CLASS_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const outerNode = getDeclaration( program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration); const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !; @@ -1604,7 +1605,7 @@ describe('Esm5ReflectionHost', () => { it('should return undefined if node is not an ES5 class', () => { const program = makeTestProgram(FOO_FUNCTION_FILE); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const node = getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration); const classSymbol = host.getClassSymbol(node); @@ -1620,7 +1621,7 @@ describe('Esm5ReflectionHost', () => { let superGetClassDeclarationSpy: jasmine.Spy; beforeEach(() => { - host = new Esm5ReflectionHost(false, null as any); + host = new Esm5ReflectionHost(new MockLogger(), false, null as any); mockNode = {} as any; getClassDeclarationSpy = spyOn(Esm5ReflectionHost.prototype, 'getClassDeclaration'); @@ -1659,7 +1660,7 @@ describe('Esm5ReflectionHost', () => { }; const program = makeTestProgram(file); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const classNode = getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration); return host.hasBaseClass(classNode); } @@ -1699,7 +1700,7 @@ describe('Esm5ReflectionHost', () => { describe('findDecoratedClasses()', () => { it('should return an array of all decorated classes in the given source file', () => { const program = makeTestProgram(...DECORATED_FILES); - const host = new Esm5ReflectionHost(false, program.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const primary = program.getSourceFile(DECORATED_FILES[0].name) !; const primaryDecoratedClasses = host.findDecoratedClasses(primary); @@ -1726,7 +1727,8 @@ describe('Esm5ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class1 = getDeclaration(srcProgram, '/src/class1.js', 'Class1', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts'); @@ -1736,7 +1738,8 @@ describe('Esm5ReflectionHost', () => { const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES); const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES); const mooFn = getDeclaration(srcProgram, '/src/func1.js', 'mooFn', ts.isFunctionDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dtsProgram); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dtsProgram); const dtsDeclaration = host.getDtsDeclaration(mooFn); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/func1.d.ts'); @@ -1747,7 +1750,8 @@ describe('Esm5ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const missingClass = getDeclaration(srcProgram, '/src/class1.js', 'MissingClass1', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -1757,7 +1761,8 @@ describe('Esm5ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const missingClass = getDeclaration( srcProgram, '/src/missing-class.js', 'MissingClass2', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); expect(host.getDtsDeclaration(missingClass)).toBe(null); }); @@ -1768,7 +1773,8 @@ describe('Esm5ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class1 = getDeclaration(srcProgram, '/src/flat-file.js', 'Class1', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class1); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts'); @@ -1779,7 +1785,8 @@ describe('Esm5ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const class3 = getDeclaration(srcProgram, '/src/flat-file.js', 'Class3', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(class3); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class3.d.ts'); @@ -1791,7 +1798,8 @@ describe('Esm5ReflectionHost', () => { const dts = makeTestBundleProgram(TYPINGS_DTS_FILES); const internalClass = getDeclaration( srcProgram, '/src/internal.js', 'InternalClass', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const dtsDeclaration = host.getDtsDeclaration(internalClass); expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/internal.d.ts'); @@ -1805,7 +1813,8 @@ describe('Esm5ReflectionHost', () => { getDeclaration(srcProgram, '/src/class2.js', 'Class2', ts.isVariableDeclaration); const internalClass2 = getDeclaration(srcProgram, '/src/internal.js', 'Class2', ts.isVariableDeclaration); - const host = new Esm2015ReflectionHost(false, srcProgram.getTypeChecker(), dts); + const host = + new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker(), dts); const class2DtsDeclaration = host.getDtsDeclaration(class2); expect(class2DtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class2.d.ts'); @@ -1820,7 +1829,7 @@ describe('Esm5ReflectionHost', () => { it('should find every exported function that returns an object that looks like a ModuleWithProviders object', () => { const srcProgram = makeTestProgram(...MODULE_WITH_PROVIDERS_PROGRAM); - const host = new Esm5ReflectionHost(false, srcProgram.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker()); const file = srcProgram.getSourceFile('/src/functions.js') !; const fns = host.getModuleWithProvidersFunctions(file); expect(fns.map(info => [info.declaration.name !.getText(), info.ngModule.text])).toEqual([ @@ -1834,7 +1843,7 @@ describe('Esm5ReflectionHost', () => { it('should find every static method on exported classes that return an object that looks like a ModuleWithProviders object', () => { const srcProgram = makeTestProgram(...MODULE_WITH_PROVIDERS_PROGRAM); - const host = new Esm5ReflectionHost(false, srcProgram.getTypeChecker()); + const host = new Esm5ReflectionHost(new MockLogger(), false, srcProgram.getTypeChecker()); const file = srcProgram.getSourceFile('/src/methods.js') !; const fn = host.getModuleWithProvidersFunctions(file); expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.text])).toEqual([ diff --git a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts index 3c2593d7d7..9c1013f7cb 100644 --- a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts +++ b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts @@ -14,6 +14,7 @@ const Module = require('module'); import {mainNgcc} from '../../src/main'; import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from '../../../test/runfile_helpers'; import {EntryPointPackageJson} from '../../src/packages/entry_point'; +import {Logger} from '../../src/logging/logger'; describe('ngcc main()', () => { beforeEach(createMockFileSystem); @@ -179,6 +180,21 @@ describe('ngcc main()', () => { expect(existsSync(`/node_modules/@angular/common/common.d.ts.__ivy_ngcc_bak`)).toBe(true); }); }); + + describe('logger', () => { + it('should log info message to the console by default', () => { + const consoleInfoSpy = spyOn(console, 'info'); + mainNgcc({basePath: '/node_modules', propertiesToConsider: ['esm2015']}); + expect(consoleInfoSpy) + .toHaveBeenCalledWith('Compiling @angular/common/http : esm2015 as esm2015'); + }); + + it('should use a custom logger if provided', () => { + const logger: Logger = jasmine.createSpyObj(['debug', 'info', 'warn', 'error']); + mainNgcc({basePath: '/node_modules', propertiesToConsider: ['esm2015'], logger}); + expect(logger.info).toHaveBeenCalled(); + }); + }); }); diff --git a/packages/compiler-cli/ngcc/test/logging/console_logger_spec.ts b/packages/compiler-cli/ngcc/test/logging/console_logger_spec.ts new file mode 100644 index 0000000000..76b9bd8ed7 --- /dev/null +++ b/packages/compiler-cli/ngcc/test/logging/console_logger_spec.ts @@ -0,0 +1,50 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +import {ConsoleLogger, DEBUG, ERROR, LogLevel, WARN} from '../../src/logging/console_logger'; + +describe('ConsoleLogger', () => { + it('should pass through calls to Console', () => { + spyOn(console, 'debug'); + spyOn(console, 'info'); + spyOn(console, 'warn'); + spyOn(console, 'error'); + const logger = new ConsoleLogger(LogLevel.debug); + + logger.debug('debug', 'test'); + expect(console.debug).toHaveBeenCalledWith(DEBUG, 'debug', 'test'); + + logger.info('info', 'test'); + expect(console.info).toHaveBeenCalledWith('info', 'test'); + + logger.warn('warn', 'test'); + expect(console.warn).toHaveBeenCalledWith(WARN, 'warn', 'test'); + + logger.error('error', 'test'); + expect(console.error).toHaveBeenCalledWith(ERROR, 'error', 'test'); + }); + + it('should filter out calls below the given log level', () => { + spyOn(console, 'debug'); + spyOn(console, 'info'); + spyOn(console, 'warn'); + spyOn(console, 'error'); + const logger = new ConsoleLogger(LogLevel.warn); + + logger.debug('debug', 'test'); + expect(console.debug).not.toHaveBeenCalled(); + + logger.info('info', 'test'); + expect(console.info).not.toHaveBeenCalled(); + + logger.warn('warn', 'test'); + expect(console.warn).toHaveBeenCalledWith(WARN, 'warn', 'test'); + + logger.error('error', 'test'); + expect(console.error).toHaveBeenCalledWith(ERROR, 'error', 'test'); + }); +}); diff --git a/packages/compiler-cli/ngcc/test/packages/dependency_resolver_spec.ts b/packages/compiler-cli/ngcc/test/packages/dependency_resolver_spec.ts index e3deb28f9e..60c8f16d30 100644 --- a/packages/compiler-cli/ngcc/test/packages/dependency_resolver_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/dependency_resolver_spec.ts @@ -5,13 +5,11 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ - -import {resolve} from 'canonical-path'; - import {AbsoluteFsPath} from '../../../src/ngtsc/path'; import {DependencyHost} from '../../src/packages/dependency_host'; import {DependencyResolver, SortedEntryPointsInfo} from '../../src/packages/dependency_resolver'; import {EntryPoint} from '../../src/packages/entry_point'; +import {MockLogger} from '../helpers/mock_logger'; const _ = AbsoluteFsPath.from; @@ -20,7 +18,7 @@ describe('DependencyResolver', () => { let resolver: DependencyResolver; beforeEach(() => { host = new DependencyHost(); - resolver = new DependencyResolver(host); + resolver = new DependencyResolver(new MockLogger(), host); }); describe('sortEntryPointsByDependency()', () => { const first = { path: _('/first'), packageJson: {esm5: 'index.ts'} } as EntryPoint; diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_finder_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_finder_spec.ts index f2c7f8f92f..92967be770 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_finder_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_finder_spec.ts @@ -13,6 +13,7 @@ import {DependencyHost} from '../../src/packages/dependency_host'; import {DependencyResolver} from '../../src/packages/dependency_resolver'; import {EntryPoint} from '../../src/packages/entry_point'; import {EntryPointFinder} from '../../src/packages/entry_point_finder'; +import {MockLogger} from '../helpers/mock_logger'; const _ = AbsoluteFsPath.from; @@ -20,11 +21,11 @@ describe('findEntryPoints()', () => { let resolver: DependencyResolver; let finder: EntryPointFinder; beforeEach(() => { - resolver = new DependencyResolver(new DependencyHost()); + resolver = new DependencyResolver(new MockLogger(), new DependencyHost()); spyOn(resolver, 'sortEntryPointsByDependency').and.callFake((entryPoints: EntryPoint[]) => { return {entryPoints, ignoredEntryPoints: [], ignoredDependencies: []}; }); - finder = new EntryPointFinder(resolver); + finder = new EntryPointFinder(new MockLogger(), resolver); }); beforeEach(createMockFileSystem); afterEach(restoreRealFileSystem); diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts index de60cb2cb4..c360d80dfd 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts @@ -11,6 +11,7 @@ import {readFileSync} from 'fs'; import * as mockFs from 'mock-fs'; import {getEntryPointInfo} from '../../src/packages/entry_point'; +import {MockLogger} from '../helpers/mock_logger'; describe('getEntryPointInfo()', () => { beforeEach(createMockFileSystem); @@ -21,7 +22,8 @@ describe('getEntryPointInfo()', () => { it('should return an object containing absolute paths to the formats of the specified entry-point', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/valid_entry_point')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/valid_entry_point')); expect(entryPoint).toEqual({ name: 'some-package/valid_entry_point', package: SOME_PACKAGE, @@ -32,28 +34,32 @@ describe('getEntryPointInfo()', () => { }); it('should return null if there is no package.json at the entry-point path', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/missing_package_json')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/missing_package_json')); expect(entryPoint).toBe(null); }); it('should return null if there is no typings or types field in the package.json', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/missing_typings')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/missing_typings')); expect(entryPoint).toBe(null); }); it('should return null if there is no esm2015 nor fesm2015 field in the package.json', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/missing_esm2015')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/missing_esm2015')); expect(entryPoint).toBe(null); }); it('should return null if there is no metadata.json file next to the typing file', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/missing_metadata.json')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/missing_metadata.json')); expect(entryPoint).toBe(null); }); it('should work if the typings field is named `types', () => { - const entryPoint = - getEntryPointInfo(SOME_PACKAGE, _('/some_package/types_rather_than_typings')); + const entryPoint = getEntryPointInfo( + new MockLogger(), SOME_PACKAGE, _('/some_package/types_rather_than_typings')); expect(entryPoint).toEqual({ name: 'some-package/types_rather_than_typings', package: SOME_PACKAGE, @@ -64,7 +70,8 @@ describe('getEntryPointInfo()', () => { }); it('should work with Angular Material style package.json', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/material_style')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/material_style')); expect(entryPoint).toEqual({ name: 'some_package/material_style', package: SOME_PACKAGE, @@ -75,7 +82,8 @@ describe('getEntryPointInfo()', () => { }); it('should return null if the package.json is not valid JSON', () => { - const entryPoint = getEntryPointInfo(SOME_PACKAGE, _('/some_package/unexpected_symbols')); + const entryPoint = + getEntryPointInfo(new MockLogger(), SOME_PACKAGE, _('/some_package/unexpected_symbols')); expect(entryPoint).toBe(null); }); }); diff --git a/packages/compiler-cli/ngcc/test/rendering/esm2015_renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/esm2015_renderer_spec.ts index 21763076b1..894d0c6540 100644 --- a/packages/compiler-cli/ngcc/test/rendering/esm2015_renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/esm2015_renderer_spec.ts @@ -15,12 +15,14 @@ import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer'; import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {EsmRenderer} from '../../src/rendering/esm_renderer'; import {makeTestEntryPointBundle} from '../helpers/utils'; +import {MockLogger} from '../helpers/mock_logger'; function setup(file: {name: string, contents: string}) { + const logger = new MockLogger(); const dir = dirname(file.name); const bundle = makeTestEntryPointBundle('es2015', 'esm2015', false, [file]) !; const typeChecker = bundle.src.program.getTypeChecker(); - const host = new Esm2015ReflectionHost(false, typeChecker); + const host = new Esm2015ReflectionHost(logger, false, typeChecker); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer( @@ -28,7 +30,7 @@ function setup(file: {name: string, contents: string}) { referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false) .analyzeProgram(); const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program); - const renderer = new EsmRenderer(host, false, bundle, dir); + const renderer = new EsmRenderer(logger, host, false, bundle, dir); return { host, program: bundle.src.program, diff --git a/packages/compiler-cli/ngcc/test/rendering/esm5_renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/esm5_renderer_spec.ts index 8fd45339aa..03d987862f 100644 --- a/packages/compiler-cli/ngcc/test/rendering/esm5_renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/esm5_renderer_spec.ts @@ -15,12 +15,14 @@ import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer'; import {Esm5ReflectionHost} from '../../src/host/esm5_host'; import {Esm5Renderer} from '../../src/rendering/esm5_renderer'; import {makeTestEntryPointBundle, getDeclaration} from '../helpers/utils'; +import {MockLogger} from '../helpers/mock_logger'; function setup(file: {name: string, contents: string}) { + const logger = new MockLogger(); const dir = dirname(file.name); const bundle = makeTestEntryPointBundle('module', 'esm5', false, [file]); const typeChecker = bundle.src.program.getTypeChecker(); - const host = new Esm5ReflectionHost(false, typeChecker); + const host = new Esm5ReflectionHost(logger, false, typeChecker); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer( @@ -28,7 +30,7 @@ function setup(file: {name: string, contents: string}) { referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false) .analyzeProgram(); const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program); - const renderer = new Esm5Renderer(host, false, bundle, dir); + const renderer = new Esm5Renderer(logger, host, false, bundle, dir); return { host, program: bundle.src.program, diff --git a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts index 69efa4bcb9..db9dcbff8c 100644 --- a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts @@ -18,10 +18,13 @@ import {Esm2015ReflectionHost} from '../../src/host/esm2015_host'; import {RedundantDecoratorMap, Renderer} from '../../src/rendering/renderer'; import {EntryPointBundle} from '../../src/packages/entry_point_bundle'; import {makeTestEntryPointBundle} from '../helpers/utils'; +import {Logger} from '../../src/logging/logger'; +import {MockLogger} from '../helpers/mock_logger'; class TestRenderer extends Renderer { - constructor(host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) { - super(host, isCore, bundle, '/src'); + constructor( + logger: Logger, host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) { + super(logger, host, isCore, bundle, '/src'); } addImports(output: MagicString, imports: {specifier: string, qualifier: string}[]) { output.prepend('\n// ADD IMPORTS\n'); @@ -49,10 +52,11 @@ class TestRenderer extends Renderer { function createTestRenderer( packageName: string, files: {name: string, contents: string}[], dtsFiles?: {name: string, contents: string}[]) { + const logger = new MockLogger(); const isCore = packageName === '@angular/core'; const bundle = makeTestEntryPointBundle('es2015', 'esm2015', isCore, files, dtsFiles); const typeChecker = bundle.src.program.getTypeChecker(); - const host = new Esm2015ReflectionHost(isCore, typeChecker, bundle.dts); + const host = new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts); const referencesRegistry = new NgccReferencesRegistry(host); const decorationAnalyses = new DecorationAnalyzer( bundle.src.program, bundle.src.options, bundle.src.host, @@ -63,7 +67,7 @@ function createTestRenderer( new ModuleWithProvidersAnalyzer(host, referencesRegistry).analyzeProgram(bundle.src.program); const privateDeclarationsAnalyses = new PrivateDeclarationsAnalyzer(host, referencesRegistry).analyzeProgram(bundle.src.program); - const renderer = new TestRenderer(host, isCore, bundle); + const renderer = new TestRenderer(logger, host, isCore, bundle); spyOn(renderer, 'addImports').and.callThrough(); spyOn(renderer, 'addDefinitions').and.callThrough(); spyOn(renderer, 'removeDecorators').and.callThrough(); diff --git a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts index 9036f02392..0d3815031e 100644 --- a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts @@ -14,6 +14,7 @@ import {EntryPoint, EntryPointFormat, EntryPointJsonProperty, getEntryPointInfo} import {EntryPointBundle, makeEntryPointBundle} from '../../src/packages/entry_point_bundle'; import {FileWriter} from '../../src/writing/file_writer'; import {NewEntryPointFileWriter} from '../../src/writing/new_entry_point_file_writer'; +import {MockLogger} from '../helpers/mock_logger'; import {loadPackageJson} from '../packages/entry_point_spec'; const _ = AbsoluteFsPath.from; @@ -79,7 +80,8 @@ describe('NewEntryPointFileWriter', () => { describe('writeBundle() [primary entry-point]', () => { beforeEach(() => { fileWriter = new NewEntryPointFileWriter(); - entryPoint = getEntryPointInfo(_('/node_modules/test'), _('/node_modules/test')) !; + entryPoint = + getEntryPointInfo(new MockLogger(), _('/node_modules/test'), _('/node_modules/test')) !; esm5bundle = makeTestBundle(entryPoint, 'module', 'esm5'); esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015'); }); @@ -155,7 +157,8 @@ describe('NewEntryPointFileWriter', () => { describe('writeBundle() [secondary entry-point]', () => { beforeEach(() => { fileWriter = new NewEntryPointFileWriter(); - entryPoint = getEntryPointInfo(_('/node_modules/test'), _('/node_modules/test/a')) !; + entryPoint = + getEntryPointInfo(new MockLogger(), _('/node_modules/test'), _('/node_modules/test/a')) !; esm5bundle = makeTestBundle(entryPoint, 'module', 'esm5'); esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015'); }); @@ -219,7 +222,8 @@ describe('NewEntryPointFileWriter', () => { describe('writeBundle() [entry-point (with files placed outside entry-point folder)]', () => { beforeEach(() => { fileWriter = new NewEntryPointFileWriter(); - entryPoint = getEntryPointInfo(_('/node_modules/test'), _('/node_modules/test/b')) !; + entryPoint = + getEntryPointInfo(new MockLogger(), _('/node_modules/test'), _('/node_modules/test/b')) !; esm5bundle = makeTestBundle(entryPoint, 'module', 'esm5'); esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015'); });