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
This commit is contained in:
parent
39345b6fae
commit
8d3d75e454
|
@ -9,6 +9,8 @@
|
||||||
import {hasBeenProcessed as _hasBeenProcessed} from './src/packages/build_marker';
|
import {hasBeenProcessed as _hasBeenProcessed} from './src/packages/build_marker';
|
||||||
import {EntryPointJsonProperty, EntryPointPackageJson} from './src/packages/entry_point';
|
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 {NgccOptions, mainNgcc as process} from './src/main';
|
||||||
|
|
||||||
export function hasBeenProcessed(packageJson: object, format: string) {
|
export function hasBeenProcessed(packageJson: object, format: string) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as path from 'canonical-path';
|
||||||
import * as yargs from 'yargs';
|
import * as yargs from 'yargs';
|
||||||
|
|
||||||
import {mainNgcc} from './src/main';
|
import {mainNgcc} from './src/main';
|
||||||
|
import {ConsoleLogger, LogLevel} from './src/logging/console_logger';
|
||||||
|
|
||||||
// CLI entry point
|
// CLI entry point
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
@ -39,9 +40,14 @@ if (require.main === module) {
|
||||||
})
|
})
|
||||||
.option('first-only', {
|
.option('first-only', {
|
||||||
describe:
|
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'
|
type: 'boolean'
|
||||||
})
|
})
|
||||||
|
.option('l', {
|
||||||
|
alias: 'loglevel',
|
||||||
|
describe: 'The lowest severity logging message that should be output.',
|
||||||
|
choices: ['debug', 'info', 'warn', 'error'],
|
||||||
|
})
|
||||||
.help()
|
.help()
|
||||||
.parse(args);
|
.parse(args);
|
||||||
|
|
||||||
|
@ -54,9 +60,15 @@ if (require.main === module) {
|
||||||
const propertiesToConsider: string[] = options['p'];
|
const propertiesToConsider: string[] = options['p'];
|
||||||
const targetEntryPointPath = options['t'] ? options['t'] : undefined;
|
const targetEntryPointPath = options['t'] ? options['t'] : undefined;
|
||||||
const compileAllFormats = !options['first-only'];
|
const compileAllFormats = !options['first-only'];
|
||||||
|
const logLevel = options['l'] as keyof typeof LogLevel;
|
||||||
try {
|
try {
|
||||||
mainNgcc(
|
mainNgcc({
|
||||||
{basePath: baseSourcePath, propertiesToConsider, targetEntryPointPath, compileAllFormats});
|
basePath: baseSourcePath,
|
||||||
|
propertiesToConsider,
|
||||||
|
targetEntryPointPath,
|
||||||
|
compileAllFormats,
|
||||||
|
logger: new ConsoleLogger(LogLevel[logLevel]),
|
||||||
|
});
|
||||||
process.exitCode = 0;
|
process.exitCode = 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.stack || e.message);
|
console.error(e.stack || e.message);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {ClassDeclaration, ClassMember, ClassMemberKind, ClassSymbol, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../src/ngtsc/reflection';
|
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 {BundleProgram} from '../packages/bundle_program';
|
||||||
import {findAll, getNameText, hasNameIdentifier, isDefined} from '../utils';
|
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 {
|
export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements NgccReflectionHost {
|
||||||
protected dtsDeclarationMap: Map<string, ts.Declaration>|null;
|
protected dtsDeclarationMap: Map<string, ts.Declaration>|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);
|
super(checker);
|
||||||
this.dtsDeclarationMap = dts && this.computeDtsDeclarationMap(dts.path, dts.program) || null;
|
this.dtsDeclarationMap = dts && this.computeDtsDeclarationMap(dts.path, dts.program) || null;
|
||||||
}
|
}
|
||||||
|
@ -848,7 +851,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind === null) {
|
if (kind === null) {
|
||||||
console.warn(`Unknown member type: "${node.getText()}`);
|
this.logger.warn(`Unknown member type: "${node.getText()}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -11,6 +11,8 @@ import {readFileSync} from 'fs';
|
||||||
|
|
||||||
import {AbsoluteFsPath} from '../../src/ngtsc/path';
|
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 {hasBeenProcessed, markAsProcessed} from './packages/build_marker';
|
||||||
import {DependencyHost} from './packages/dependency_host';
|
import {DependencyHost} from './packages/dependency_host';
|
||||||
import {DependencyResolver} from './packages/dependency_resolver';
|
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';
|
import {NewEntryPointFileWriter} from './writing/new_entry_point_file_writer';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The options to configure the ngcc compiler.
|
* 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.
|
* Whether to create new entry-points bundles rather than overwriting the original files.
|
||||||
*/
|
*/
|
||||||
createNewEntryPointFormats?: boolean;
|
createNewEntryPointFormats?: boolean;
|
||||||
|
/**
|
||||||
|
* Provide a logger that will be called with log messages.
|
||||||
|
*/
|
||||||
|
logger?: Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SUPPORTED_FORMATS: EntryPointFormat[] = ['esm5', 'esm2015'];
|
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.
|
* @param options The options telling ngcc what to compile and how.
|
||||||
*/
|
*/
|
||||||
export function mainNgcc(
|
export function mainNgcc({basePath, targetEntryPointPath,
|
||||||
{basePath, targetEntryPointPath, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
|
propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
|
||||||
compileAllFormats = true, createNewEntryPointFormats = false}: NgccOptions): void {
|
compileAllFormats = true, createNewEntryPointFormats = false,
|
||||||
const transformer = new Transformer(basePath);
|
logger = new ConsoleLogger(LogLevel.info)}: NgccOptions): void {
|
||||||
|
const transformer = new Transformer(logger, basePath);
|
||||||
const host = new DependencyHost();
|
const host = new DependencyHost();
|
||||||
const resolver = new DependencyResolver(host);
|
const resolver = new DependencyResolver(logger, host);
|
||||||
const finder = new EntryPointFinder(resolver);
|
const finder = new EntryPointFinder(logger, resolver);
|
||||||
const fileWriter = getFileWriter(createNewEntryPointFormats);
|
const fileWriter = getFileWriter(createNewEntryPointFormats);
|
||||||
|
|
||||||
const absoluteTargetEntryPointPath = targetEntryPointPath ?
|
const absoluteTargetEntryPointPath = targetEntryPointPath ?
|
||||||
|
@ -112,7 +120,7 @@ export function mainNgcc(
|
||||||
|
|
||||||
if (hasBeenProcessed(entryPointPackageJson, property)) {
|
if (hasBeenProcessed(entryPointPackageJson, property)) {
|
||||||
compiledFormats.add(formatPath);
|
compiledFormats.add(formatPath);
|
||||||
console.warn(`Skipping ${entryPoint.name} : ${property} (already compiled).`);
|
logger.info(`Skipping ${entryPoint.name} : ${property} (already compiled).`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,16 +131,16 @@ export function mainNgcc(
|
||||||
entryPoint.path, formatPath, entryPoint.typings, isCore, property, format,
|
entryPoint.path, formatPath, entryPoint.typings, isCore, property, format,
|
||||||
compiledFormats.size === 0);
|
compiledFormats.size === 0);
|
||||||
if (bundle) {
|
if (bundle) {
|
||||||
console.warn(`Compiling ${entryPoint.name} : ${property} as ${format}`);
|
logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`);
|
||||||
const transformedFiles = transformer.transform(bundle);
|
const transformedFiles = transformer.transform(bundle);
|
||||||
fileWriter.writeBundle(entryPoint, bundle, transformedFiles);
|
fileWriter.writeBundle(entryPoint, bundle, transformedFiles);
|
||||||
compiledFormats.add(formatPath);
|
compiledFormats.add(formatPath);
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`Skipping ${entryPoint.name} : ${format} (no valid entry point file for this format).`);
|
`Skipping ${entryPoint.name} : ${format} (no valid entry point file for this format).`);
|
||||||
}
|
}
|
||||||
} else if (!compileAllFormats) {
|
} 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
|
// Either this format was just compiled or its underlying format was compiled because of a
|
||||||
|
|
|
@ -10,6 +10,8 @@ import {resolve} from 'canonical-path';
|
||||||
import {DepGraph} from 'dependency-graph';
|
import {DepGraph} from 'dependency-graph';
|
||||||
|
|
||||||
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
||||||
|
import {Logger} from '../logging/logger';
|
||||||
|
|
||||||
import {DependencyHost} from './dependency_host';
|
import {DependencyHost} from './dependency_host';
|
||||||
import {EntryPoint, EntryPointJsonProperty, getEntryPointFormat} from './entry_point';
|
import {EntryPoint, EntryPointJsonProperty, getEntryPointFormat} from './entry_point';
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ export interface SortedEntryPointsInfo {
|
||||||
* A class that resolves dependencies between entry-points.
|
* A class that resolves dependencies between entry-points.
|
||||||
*/
|
*/
|
||||||
export class DependencyResolver {
|
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
|
* Sort the array of entry points so that the dependant entry points always come later than
|
||||||
* their dependencies in the array.
|
* their dependencies in the array.
|
||||||
|
@ -134,7 +136,7 @@ export class DependencyResolver {
|
||||||
|
|
||||||
if (deepImports.size) {
|
if (deepImports.size) {
|
||||||
const imports = Array.from(deepImports).map(i => `'${i}'`).join(', ');
|
const imports = Array.from(deepImports).map(i => `'${i}'`).join(', ');
|
||||||
console.warn(
|
this.logger.warn(
|
||||||
`Entry point '${entryPoint.name}' contains deep imports into ${imports}. ` +
|
`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.`);
|
`This is probably not a problem, but may cause the compilation of entry points to be out of order.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as path from 'canonical-path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
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.
|
* @returns An entry-point if it is valid, `null` otherwise.
|
||||||
*/
|
*/
|
||||||
export function getEntryPointInfo(
|
export function getEntryPointInfo(
|
||||||
packagePath: AbsoluteFsPath, entryPointPath: AbsoluteFsPath): EntryPoint|null {
|
logger: Logger, packagePath: AbsoluteFsPath, entryPointPath: AbsoluteFsPath): EntryPoint|null {
|
||||||
const packageJsonPath = path.resolve(entryPointPath, 'package.json');
|
const packageJsonPath = path.resolve(entryPointPath, 'package.json');
|
||||||
if (!fs.existsSync(packageJsonPath)) {
|
if (!fs.existsSync(packageJsonPath)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const entryPointPackageJson = loadEntryPointPackage(packageJsonPath);
|
const entryPointPackageJson = loadEntryPointPackage(logger, packageJsonPath);
|
||||||
if (!entryPointPackageJson) {
|
if (!entryPointPackageJson) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -135,12 +136,13 @@ export function getEntryPointFormat(property: string): EntryPointFormat|undefine
|
||||||
* @param packageJsonPath the absolute path to the package.json file.
|
* @param packageJsonPath the absolute path to the package.json file.
|
||||||
* @returns JSON from the package.json file if it is valid, `null` otherwise.
|
* @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 {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// We may have run into a package.json with unexpected symbols
|
// 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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,32 +9,33 @@ import * as path from 'canonical-path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
||||||
|
import {Logger} from '../logging/logger';
|
||||||
|
|
||||||
import {DependencyResolver, SortedEntryPointsInfo} from './dependency_resolver';
|
import {DependencyResolver, SortedEntryPointsInfo} from './dependency_resolver';
|
||||||
import {EntryPoint, getEntryPointInfo} from './entry_point';
|
import {EntryPoint, getEntryPointInfo} from './entry_point';
|
||||||
|
|
||||||
|
|
||||||
export class EntryPointFinder {
|
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.
|
* 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.
|
* @param sourceDirectory An absolute path to the directory to search for entry points.
|
||||||
*/
|
*/
|
||||||
findEntryPoints(sourceDirectory: AbsoluteFsPath, targetEntryPointPath?: AbsoluteFsPath):
|
findEntryPoints(sourceDirectory: AbsoluteFsPath, targetEntryPointPath?: AbsoluteFsPath):
|
||||||
SortedEntryPointsInfo {
|
SortedEntryPointsInfo {
|
||||||
const unsortedEntryPoints = walkDirectoryForEntryPoints(sourceDirectory);
|
const unsortedEntryPoints = this.walkDirectoryForEntryPoints(sourceDirectory);
|
||||||
const targetEntryPoint = targetEntryPointPath ?
|
const targetEntryPoint = targetEntryPointPath ?
|
||||||
unsortedEntryPoints.find(entryPoint => entryPoint.path === targetEntryPointPath) :
|
unsortedEntryPoints.find(entryPoint => entryPoint.path === targetEntryPointPath) :
|
||||||
undefined;
|
undefined;
|
||||||
return this.resolver.sortEntryPointsByDependency(unsortedEntryPoints, targetEntryPoint);
|
return this.resolver.sortEntryPointsByDependency(unsortedEntryPoints, targetEntryPoint);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for entry points that need to be compiled, starting at the source directory.
|
* 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/...`.
|
* The function will recurse into directories that start with `@...`, e.g. `@angular/...`.
|
||||||
* @param sourceDirectory An absolute path to the root directory where searching begins.
|
* @param sourceDirectory An absolute path to the root directory where searching begins.
|
||||||
*/
|
*/
|
||||||
function walkDirectoryForEntryPoints(sourceDirectory: AbsoluteFsPath): EntryPoint[] {
|
private walkDirectoryForEntryPoints(sourceDirectory: AbsoluteFsPath): EntryPoint[] {
|
||||||
const entryPoints: EntryPoint[] = [];
|
const entryPoints: EntryPoint[] = [];
|
||||||
fs.readdirSync(sourceDirectory)
|
fs.readdirSync(sourceDirectory)
|
||||||
// Not interested in hidden files
|
// Not interested in hidden files
|
||||||
|
@ -51,53 +52,53 @@ function walkDirectoryForEntryPoints(sourceDirectory: AbsoluteFsPath): EntryPoin
|
||||||
// `@angular`).
|
// `@angular`).
|
||||||
const packagePath = AbsoluteFsPath.from(path.join(sourceDirectory, p));
|
const packagePath = AbsoluteFsPath.from(path.join(sourceDirectory, p));
|
||||||
if (p.startsWith('@')) {
|
if (p.startsWith('@')) {
|
||||||
entryPoints.push(...walkDirectoryForEntryPoints(packagePath));
|
entryPoints.push(...this.walkDirectoryForEntryPoints(packagePath));
|
||||||
} else {
|
} else {
|
||||||
entryPoints.push(...getEntryPointsForPackage(packagePath));
|
entryPoints.push(...this.getEntryPointsForPackage(packagePath));
|
||||||
|
|
||||||
// Also check for any nested node_modules in this package
|
// Also check for any nested node_modules in this package
|
||||||
const nestedNodeModulesPath =
|
const nestedNodeModulesPath =
|
||||||
AbsoluteFsPath.from(path.resolve(packagePath, 'node_modules'));
|
AbsoluteFsPath.from(path.resolve(packagePath, 'node_modules'));
|
||||||
if (fs.existsSync(nestedNodeModulesPath)) {
|
if (fs.existsSync(nestedNodeModulesPath)) {
|
||||||
entryPoints.push(...walkDirectoryForEntryPoints(nestedNodeModulesPath));
|
entryPoints.push(...this.walkDirectoryForEntryPoints(nestedNodeModulesPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return entryPoints;
|
return entryPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recurse the folder structure looking for all the entry points
|
* Recurse the folder structure looking for all the entry points
|
||||||
* @param packagePath The absolute path to an npm package that may contain 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.
|
* @returns An array of entry points that were discovered.
|
||||||
*/
|
*/
|
||||||
function getEntryPointsForPackage(packagePath: AbsoluteFsPath): EntryPoint[] {
|
private getEntryPointsForPackage(packagePath: AbsoluteFsPath): EntryPoint[] {
|
||||||
const entryPoints: EntryPoint[] = [];
|
const entryPoints: EntryPoint[] = [];
|
||||||
|
|
||||||
// Try to get an entry point from the top level package directory
|
// Try to get an entry point from the top level package directory
|
||||||
const topLevelEntryPoint = getEntryPointInfo(packagePath, packagePath);
|
const topLevelEntryPoint = getEntryPointInfo(this.logger, packagePath, packagePath);
|
||||||
if (topLevelEntryPoint !== null) {
|
if (topLevelEntryPoint !== null) {
|
||||||
entryPoints.push(topLevelEntryPoint);
|
entryPoints.push(topLevelEntryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now search all the directories of this package for possible entry points
|
// Now search all the directories of this package for possible entry points
|
||||||
walkDirectory(packagePath, subdir => {
|
this.walkDirectory(packagePath, subdir => {
|
||||||
const subEntryPoint = getEntryPointInfo(packagePath, subdir);
|
const subEntryPoint = getEntryPointInfo(this.logger, packagePath, subdir);
|
||||||
if (subEntryPoint !== null) {
|
if (subEntryPoint !== null) {
|
||||||
entryPoints.push(subEntryPoint);
|
entryPoints.push(subEntryPoint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return entryPoints;
|
return entryPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively walk a directory and its sub-directories, applying a given
|
* Recursively walk a directory and its sub-directories, applying a given
|
||||||
* function to each directory.
|
* function to each directory.
|
||||||
* @param dir the directory to recursively walk.
|
* @param dir the directory to recursively walk.
|
||||||
* @param fn the function to apply to each directory.
|
* @param fn the function to apply to each directory.
|
||||||
*/
|
*/
|
||||||
function walkDirectory(dir: AbsoluteFsPath, fn: (dir: AbsoluteFsPath) => void) {
|
private walkDirectory(dir: AbsoluteFsPath, fn: (dir: AbsoluteFsPath) => void) {
|
||||||
return fs
|
return fs
|
||||||
.readdirSync(dir)
|
.readdirSync(dir)
|
||||||
// Not interested in hidden files
|
// Not interested in hidden files
|
||||||
|
@ -112,6 +113,7 @@ function walkDirectory(dir: AbsoluteFsPath, fn: (dir: AbsoluteFsPath) => void) {
|
||||||
.forEach(subDir => {
|
.forEach(subDir => {
|
||||||
const resolvedSubDir = AbsoluteFsPath.from(path.resolve(dir, subDir));
|
const resolvedSubDir = AbsoluteFsPath.from(path.resolve(dir, subDir));
|
||||||
fn(resolvedSubDir);
|
fn(resolvedSubDir);
|
||||||
walkDirectory(resolvedSubDir, fn);
|
this.walkDirectory(resolvedSubDir, fn);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {SwitchMarkerAnalyses, SwitchMarkerAnalyzer} from '../analysis/switch_mar
|
||||||
import {Esm2015ReflectionHost} from '../host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../host/esm2015_host';
|
||||||
import {Esm5ReflectionHost} from '../host/esm5_host';
|
import {Esm5ReflectionHost} from '../host/esm5_host';
|
||||||
import {NgccReflectionHost} from '../host/ngcc_host';
|
import {NgccReflectionHost} from '../host/ngcc_host';
|
||||||
|
import {Logger} from '../logging/logger';
|
||||||
import {Esm5Renderer} from '../rendering/esm5_renderer';
|
import {Esm5Renderer} from '../rendering/esm5_renderer';
|
||||||
import {EsmRenderer} from '../rendering/esm_renderer';
|
import {EsmRenderer} from '../rendering/esm_renderer';
|
||||||
import {FileInfo, Renderer} from '../rendering/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.
|
* - Some formats may contain multiple "modules" in a single file.
|
||||||
*/
|
*/
|
||||||
export class Transformer {
|
export class Transformer {
|
||||||
constructor(private sourcePath: string) {}
|
constructor(private logger: Logger, private sourcePath: string) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform the source (and typings) files of a bundle.
|
* Transform the source (and typings) files of a bundle.
|
||||||
|
@ -73,9 +74,9 @@ export class Transformer {
|
||||||
const typeChecker = bundle.src.program.getTypeChecker();
|
const typeChecker = bundle.src.program.getTypeChecker();
|
||||||
switch (bundle.format) {
|
switch (bundle.format) {
|
||||||
case 'esm2015':
|
case 'esm2015':
|
||||||
return new Esm2015ReflectionHost(isCore, typeChecker, bundle.dts);
|
return new Esm2015ReflectionHost(this.logger, isCore, typeChecker, bundle.dts);
|
||||||
case 'esm5':
|
case 'esm5':
|
||||||
return new Esm5ReflectionHost(isCore, typeChecker, bundle.dts);
|
return new Esm5ReflectionHost(this.logger, isCore, typeChecker, bundle.dts);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`);
|
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 {
|
getRenderer(host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle): Renderer {
|
||||||
switch (bundle.format) {
|
switch (bundle.format) {
|
||||||
case 'esm2015':
|
case 'esm2015':
|
||||||
return new EsmRenderer(host, isCore, bundle, this.sourcePath);
|
return new EsmRenderer(this.logger, host, isCore, bundle, this.sourcePath);
|
||||||
case 'esm5':
|
case 'esm5':
|
||||||
return new Esm5Renderer(host, isCore, bundle, this.sourcePath);
|
return new Esm5Renderer(this.logger, host, isCore, bundle, this.sourcePath);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
|
throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,13 @@ import {NgccReflectionHost} from '../host/ngcc_host';
|
||||||
import {CompiledClass} from '../analysis/decoration_analyzer';
|
import {CompiledClass} from '../analysis/decoration_analyzer';
|
||||||
import {EsmRenderer} from './esm_renderer';
|
import {EsmRenderer} from './esm_renderer';
|
||||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||||
|
import {Logger} from '../logging/logger';
|
||||||
|
|
||||||
export class Esm5Renderer extends EsmRenderer {
|
export class Esm5Renderer extends EsmRenderer {
|
||||||
constructor(
|
constructor(
|
||||||
host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, sourcePath: string) {
|
logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle,
|
||||||
super(host, isCore, bundle, sourcePath);
|
sourcePath: string) {
|
||||||
|
super(logger, host, isCore, bundle, sourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,11 +14,13 @@ import {RedundantDecoratorMap, Renderer, stripExtension} from './renderer';
|
||||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||||
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||||
import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
|
import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
|
||||||
|
import {Logger} from '../logging/logger';
|
||||||
|
|
||||||
export class EsmRenderer extends Renderer {
|
export class EsmRenderer extends Renderer {
|
||||||
constructor(
|
constructor(
|
||||||
host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle, sourcePath: string) {
|
logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle,
|
||||||
super(host, isCore, bundle, sourcePath);
|
sourcePath: string) {
|
||||||
|
super(logger, host, isCore, bundle, sourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@ import {SwitchMarkerAnalyses, SwitchMarkerAnalysis} from '../analysis/switch_mar
|
||||||
import {IMPORT_PREFIX} from '../constants';
|
import {IMPORT_PREFIX} from '../constants';
|
||||||
import {NgccReflectionHost, SwitchableVariableDeclaration} from '../host/ngcc_host';
|
import {NgccReflectionHost, SwitchableVariableDeclaration} from '../host/ngcc_host';
|
||||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||||
|
import {Logger} from '../logging/logger';
|
||||||
|
|
||||||
interface SourceMapInfo {
|
interface SourceMapInfo {
|
||||||
source: string;
|
source: string;
|
||||||
|
@ -80,7 +81,7 @@ export const RedundantDecoratorMap = Map;
|
||||||
*/
|
*/
|
||||||
export abstract class Renderer {
|
export abstract class Renderer {
|
||||||
constructor(
|
constructor(
|
||||||
protected host: NgccReflectionHost, protected isCore: boolean,
|
protected logger: Logger, protected host: NgccReflectionHost, protected isCore: boolean,
|
||||||
protected bundle: EntryPointBundle, protected sourcePath: string) {}
|
protected bundle: EntryPointBundle, protected sourcePath: string) {}
|
||||||
|
|
||||||
renderProgram(
|
renderProgram(
|
||||||
|
@ -299,16 +300,16 @@ export abstract class Renderer {
|
||||||
externalSourceMap = fromMapFileSource(file.text, dirname(file.fileName));
|
externalSourceMap = fromMapFileSource(file.text, dirname(file.fileName));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === 'ENOENT') {
|
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.`);
|
`The external map file specified in the source code comment "${e.path}" was not found on the file system.`);
|
||||||
const mapPath = file.fileName + '.map';
|
const mapPath = file.fileName + '.map';
|
||||||
if (basename(e.path) !== basename(mapPath) && statSync(mapPath).isFile()) {
|
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)}"`);
|
`Guessing the map file name from the source file name: "${basename(mapPath)}"`);
|
||||||
try {
|
try {
|
||||||
externalSourceMap = fromObject(JSON.parse(readFileSync(mapPath, 'utf8')));
|
externalSourceMap = fromObject(JSON.parse(readFileSync(mapPath, 'utf8')));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
this.logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {DecoratorHandler, DetectResult} from '../../../src/ngtsc/transform';
|
||||||
import {CompiledClass, DecorationAnalyses, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
import {CompiledClass, DecorationAnalyses, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {makeTestBundleProgram} from '../helpers/utils';
|
import {makeTestBundleProgram} from '../helpers/utils';
|
||||||
|
|
||||||
const TEST_PROGRAM = [
|
const TEST_PROGRAM = [
|
||||||
|
@ -132,7 +133,8 @@ describe('DecorationAnalyzer', () => {
|
||||||
const {options, host, ...bundle} = makeTestBundleProgram(...progArgs);
|
const {options, host, ...bundle} = makeTestBundleProgram(...progArgs);
|
||||||
program = bundle.program;
|
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 referencesRegistry = new NgccReferencesRegistry(reflectionHost);
|
||||||
const analyzer = new DecorationAnalyzer(
|
const analyzer = new DecorationAnalyzer(
|
||||||
program, options, host, program.getTypeChecker(), reflectionHost, referencesRegistry,
|
program, options, host, program.getTypeChecker(), reflectionHost, referencesRegistry,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {ModuleWithProvidersAnalyses, ModuleWithProvidersAnalyzer} from '../../sr
|
||||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
import {BundleProgram} from '../../src/packages/bundle_program';
|
import {BundleProgram} from '../../src/packages/bundle_program';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
const TEST_PROGRAM = [
|
const TEST_PROGRAM = [
|
||||||
|
@ -321,7 +322,8 @@ describe('ModuleWithProvidersAnalyzer', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
program = makeTestProgram(...TEST_PROGRAM);
|
program = makeTestProgram(...TEST_PROGRAM);
|
||||||
dtsProgram = makeTestBundleProgram(TEST_DTS_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);
|
referencesRegistry = new NgccReferencesRegistry(host);
|
||||||
|
|
||||||
const analyzer = new ModuleWithProvidersAnalyzer(host, referencesRegistry);
|
const analyzer = new ModuleWithProvidersAnalyzer(host, referencesRegistry);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {Reference} from '../../../src/ngtsc/imports';
|
||||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||||
import {PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
import {PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
describe('PrivateDeclarationsAnalyzer', () => {
|
describe('PrivateDeclarationsAnalyzer', () => {
|
||||||
|
@ -222,7 +223,7 @@ type Files = {
|
||||||
function setup(jsProgram: Files, dtsProgram: Files) {
|
function setup(jsProgram: Files, dtsProgram: Files) {
|
||||||
const program = makeTestProgram(...jsProgram);
|
const program = makeTestProgram(...jsProgram);
|
||||||
const dts = makeTestBundleProgram(dtsProgram);
|
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 referencesRegistry = new NgccReferencesRegistry(host);
|
||||||
const analyzer = new PrivateDeclarationsAnalyzer(host, referencesRegistry);
|
const analyzer = new PrivateDeclarationsAnalyzer(host, referencesRegistry);
|
||||||
return {program, referencesRegistry, analyzer};
|
return {program, referencesRegistry, analyzer};
|
||||||
|
|
|
@ -9,6 +9,7 @@ import * as ts from 'typescript';
|
||||||
|
|
||||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {makeTestProgram} from '../helpers/utils';
|
import {makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
const TEST_PROGRAM = [
|
const TEST_PROGRAM = [
|
||||||
|
@ -47,7 +48,7 @@ describe('SwitchMarkerAnalyzer', () => {
|
||||||
describe('analyzeProgram()', () => {
|
describe('analyzeProgram()', () => {
|
||||||
it('should check for switchable markers in all the files of the program', () => {
|
it('should check for switchable markers in all the files of the program', () => {
|
||||||
const program = makeTestProgram(...TEST_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 analyzer = new SwitchMarkerAnalyzer(host);
|
||||||
const analysis = analyzer.analyzeProgram(program);
|
const analysis = analyzer.analyzeProgram(program);
|
||||||
|
|
||||||
|
|
|
@ -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); }
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import * as ts from 'typescript';
|
||||||
|
|
||||||
import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';
|
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
import {expectTypeValueReferencesForParameters} from './util';
|
import {expectTypeValueReferencesForParameters} from './util';
|
||||||
|
@ -106,7 +107,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
describe('getDecoratorsOfDeclaration()', () => {
|
describe('getDecoratorsOfDeclaration()', () => {
|
||||||
it('should find the decorators on a class', () => {
|
it('should find the decorators on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -130,7 +131,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
{});
|
{});
|
||||||
|
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should support decorators being used inside @angular/core', () => {
|
it('should support decorators being used inside @angular/core', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[1]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -166,7 +167,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
describe('getMembersOfClass()', () => {
|
describe('getMembersOfClass()', () => {
|
||||||
it('should find decorated members on a class', () => {
|
it('should find decorated members on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -184,7 +185,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should find non decorated properties on a class', () => {
|
it('should find non decorated properties on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -198,7 +199,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should find static methods on a class', () => {
|
it('should find static methods on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -211,7 +212,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should find static properties on a class', () => {
|
it('should find static properties on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
|
|
||||||
|
@ -228,7 +229,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
spyOn(Esm2015ReflectionHost.prototype, 'getImportOfIdentifier').and.returnValue({});
|
spyOn(Esm2015ReflectionHost.prototype, 'getImportOfIdentifier').and.returnValue({});
|
||||||
|
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
|
|
||||||
|
@ -239,7 +240,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should support decorators being used inside @angular/core', () => {
|
it('should support decorators being used inside @angular/core', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[1]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -255,7 +256,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
describe('getConstructorParameters', () => {
|
describe('getConstructorParameters', () => {
|
||||||
it('should find the decorated constructor parameters', () => {
|
it('should find the decorated constructor parameters', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -278,7 +279,8 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
.and.returnValue(mockImportInfo);
|
.and.returnValue(mockImportInfo);
|
||||||
|
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -296,7 +298,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
describe('getDeclarationOfIdentifier', () => {
|
describe('getDeclarationOfIdentifier', () => {
|
||||||
it('should return the declaration of a locally defined identifier', () => {
|
it('should return the declaration of a locally defined identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -316,7 +318,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should return the declaration of an externally defined identifier', () => {
|
it('should return the declaration of an externally defined identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -339,7 +341,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
|
||||||
describe('getVariableValue', () => {
|
describe('getVariableValue', () => {
|
||||||
it('should find the "actual" declaration of an aliased variable identifier', () => {
|
it('should find the "actual" declaration of an aliased variable identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const ngModuleRef = findVariableDeclaration(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1');
|
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', () => {
|
it('should return null if the variable has no assignment', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const missingValue = findVariableDeclaration(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'missingValue');
|
program.getSourceFile(fileSystem.files[2].name) !, 'missingValue');
|
||||||
const value = host.getVariableValue(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', () => {
|
it('should return null if the variable is not assigned from a call to __decorate', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const nonDecoratedVar = findVariableDeclaration(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'nonDecoratedVar');
|
program.getSourceFile(fileSystem.files[2].name) !, 'nonDecoratedVar');
|
||||||
const value = host.getVariableValue(nonDecoratedVar !);
|
const value = host.getVariableValue(nonDecoratedVar !);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as ts from 'typescript';
|
||||||
|
|
||||||
import {ClassMemberKind, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
import {ClassMemberKind, Import, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
import {expectTypeValueReferencesForParameters} from './util';
|
import {expectTypeValueReferencesForParameters} from './util';
|
||||||
|
@ -558,7 +559,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getDecoratorsOfDeclaration()', () => {
|
describe('getDecoratorsOfDeclaration()', () => {
|
||||||
it('should find the decorators on a class', () => {
|
it('should find the decorators on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -576,7 +577,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return null if the symbol is not a class', () => {
|
it('should return null if the symbol is not a class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const functionNode =
|
const functionNode =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
||||||
|
@ -585,7 +586,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return null if there are no decorators', () => {
|
it('should return null if there are no decorators', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||||
|
@ -594,7 +595,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore `decorators` if it is not an array literal', () => {
|
it('should ignore `decorators` if it is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||||
|
@ -603,7 +604,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore decorator elements that are not object literals', () => {
|
it('should ignore decorator elements that are not object literals', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -614,7 +615,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore decorator elements that have no `type` property', () => {
|
it('should ignore decorator elements that have no `type` property', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -625,7 +626,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -640,7 +641,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
.and.returnValue(mockImportInfo);
|
.and.returnValue(mockImportInfo);
|
||||||
|
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -655,7 +656,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('(returned decorators `args`)', () => {
|
describe('(returned decorators `args`)', () => {
|
||||||
it('should be an empty array if decorator has no `args` property', () => {
|
it('should be an empty array if decorator has no `args` property', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration);
|
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
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', () => {
|
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -680,7 +681,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if `args` property value is not an array literal', () => {
|
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration);
|
program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -695,7 +696,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getMembersOfClass()', () => {
|
describe('getMembersOfClass()', () => {
|
||||||
it('should find decorated properties on a class', () => {
|
it('should find decorated properties on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -713,7 +714,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find non decorated properties on a class', () => {
|
it('should find non decorated properties on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -727,7 +728,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should handle equally named getter/setter pairs correctly', () => {
|
it('should handle equally named getter/setter pairs correctly', () => {
|
||||||
const program = makeTestProgram(ACCESSORS_FILE);
|
const program = makeTestProgram(ACCESSORS_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -748,7 +749,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find static methods on a class', () => {
|
it('should find static methods on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -761,7 +762,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find static properties on a class', () => {
|
it('should find static properties on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -775,7 +776,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should throw if the symbol is not a class', () => {
|
it('should throw if the symbol is not a class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const functionNode =
|
const functionNode =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
expect(() => {
|
expect(() => {
|
||||||
|
@ -785,7 +786,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return an empty array if there are no prop decorators', () => {
|
it('should return an empty array if there are no prop decorators', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
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',
|
it('should not process decorated properties in `propDecorators` if it is not an object literal',
|
||||||
() => {
|
() => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -807,7 +808,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore prop decorator elements that are not object literals', () => {
|
it('should ignore prop decorator elements that are not object literals', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -821,7 +822,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore prop decorator elements that have no `type` property', () => {
|
it('should ignore prop decorator elements that have no `type` property', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration);
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -834,7 +835,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -854,7 +855,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -876,7 +877,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('(returned prop decorators `args`)', () => {
|
describe('(returned prop decorators `args`)', () => {
|
||||||
it('should be an empty array if prop decorator has no `args` property', () => {
|
it('should be an empty array if prop decorator has no `args` property', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -891,7 +892,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if prop decorator\'s `args` has no property assignment', () => {
|
it('should be an empty array if prop decorator\'s `args` has no property assignment', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -906,7 +907,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if `args` property value is not an array literal', () => {
|
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -924,7 +925,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getConstructorParameters()', () => {
|
describe('getConstructorParameters()', () => {
|
||||||
it('should find the decorated constructor parameters', () => {
|
it('should find the decorated constructor parameters', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode) !;
|
const parameters = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -938,7 +939,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should throw if the symbol is not a class', () => {
|
it('should throw if the symbol is not a class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const functionNode =
|
const functionNode =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
expect(() => { host.getConstructorParameters(functionNode); })
|
expect(() => { host.getConstructorParameters(functionNode); })
|
||||||
|
@ -948,7 +949,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return `null` if there is no constructor', () => {
|
it('should return `null` if there is no constructor', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -957,7 +958,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return an array even if there are no decorators', () => {
|
it('should return an array even if there are no decorators', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedClassDeclaration);
|
program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode) !;
|
const parameters = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -970,7 +971,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return an empty array if there are no constructor parameters', () => {
|
it('should return an empty array if there are no constructor parameters', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedClassDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -980,7 +981,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore decorators that are not imported from core', () => {
|
it('should ignore decorators that are not imported from core', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', isNamedClassDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotFromCore', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode) !;
|
const parameters = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -994,7 +995,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore `ctorParameters` if it is not an arrow function', () => {
|
it('should ignore `ctorParameters` if it is not an arrow function', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', isNamedClassDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrowFunction', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode) !;
|
const parameters = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -1008,7 +1009,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode) !;
|
const parameters = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -1033,7 +1034,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const program = makeTestProgram(file);
|
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);
|
const classNode = getDeclaration(program, file.name, 'TestClass', isNamedClassDeclaration);
|
||||||
return host.getConstructorParameters(classNode);
|
return host.getConstructorParameters(classNode);
|
||||||
}
|
}
|
||||||
|
@ -1087,7 +1088,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('(returned parameters `decorators`)', () => {
|
describe('(returned parameters `decorators`)', () => {
|
||||||
it('should ignore param decorator elements that are not object literals', () => {
|
it('should ignore param decorator elements that are not object literals', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -1106,7 +1107,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore param decorator elements that have no `type` property', () => {
|
it('should ignore param decorator elements that have no `type` property', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -1118,7 +1119,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -1134,7 +1135,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
.and.returnValue(mockImportInfo);
|
.and.returnValue(mockImportInfo);
|
||||||
|
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode) !;
|
const parameters = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -1151,7 +1152,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('(returned parameters `decorators.args`)', () => {
|
describe('(returned parameters `decorators.args`)', () => {
|
||||||
it('should be an empty array if param decorator has no `args` property', () => {
|
it('should be an empty array if param decorator has no `args` property', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -1166,7 +1167,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if param decorator\'s `args` has no property assignment', () => {
|
it('should be an empty array if param decorator\'s `args` has no property assignment', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -1180,7 +1181,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if `args` property value is not an array literal', () => {
|
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||||
isNamedClassDeclaration);
|
isNamedClassDeclaration);
|
||||||
|
@ -1197,7 +1198,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getDefinitionOfFunction()', () => {
|
describe('getDefinitionOfFunction()', () => {
|
||||||
it('should return an object describing the function declaration passed as an argument', () => {
|
it('should return an object describing the function declaration passed as an argument', () => {
|
||||||
const program = makeTestProgram(FUNCTION_BODY_FILE);
|
const program = makeTestProgram(FUNCTION_BODY_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
|
|
||||||
const fooNode =
|
const fooNode =
|
||||||
getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !;
|
getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !;
|
||||||
|
@ -1259,7 +1260,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getImportOfIdentifier()', () => {
|
describe('getImportOfIdentifier()', () => {
|
||||||
it('should find the import of an identifier', () => {
|
it('should find the import of an identifier', () => {
|
||||||
const program = makeTestProgram(...IMPORTS_FILES);
|
const program = makeTestProgram(...IMPORTS_FILES);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const variableNode =
|
const variableNode =
|
||||||
getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration);
|
getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration);
|
||||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
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', () => {
|
it('should find the name by which the identifier was exported, not imported', () => {
|
||||||
const program = makeTestProgram(...IMPORTS_FILES);
|
const program = makeTestProgram(...IMPORTS_FILES);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const variableNode =
|
const variableNode =
|
||||||
getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration);
|
getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration);
|
||||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
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', () => {
|
it('should return null if the identifier was not imported', () => {
|
||||||
const program = makeTestProgram(...IMPORTS_FILES);
|
const program = makeTestProgram(...IMPORTS_FILES);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const variableNode =
|
const variableNode =
|
||||||
getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration);
|
getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration);
|
||||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||||
|
@ -1291,7 +1292,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getDeclarationOfIdentifier()', () => {
|
describe('getDeclarationOfIdentifier()', () => {
|
||||||
it('should return the declaration of a locally defined identifier', () => {
|
it('should return the declaration of a locally defined identifier', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -1311,7 +1312,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return the declaration of an externally defined identifier', () => {
|
it('should return the declaration of an externally defined identifier', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedClassDeclaration);
|
||||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -1331,7 +1332,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('getExportsOfModule()', () => {
|
describe('getExportsOfModule()', () => {
|
||||||
it('should return a map of all the exports from a given module', () => {
|
it('should return a map of all the exports from a given module', () => {
|
||||||
const program = makeTestProgram(...EXPORTS_FILES);
|
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 file = program.getSourceFile(EXPORTS_FILES[1].name) !;
|
||||||
const exportDeclarations = host.getExportsOfModule(file);
|
const exportDeclarations = host.getExportsOfModule(file);
|
||||||
expect(exportDeclarations).not.toBe(null);
|
expect(exportDeclarations).not.toBe(null);
|
||||||
|
@ -1366,7 +1367,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('isClass()', () => {
|
describe('isClass()', () => {
|
||||||
it('should return true if a given node is a TS class declaration', () => {
|
it('should return true if a given node is a TS class declaration', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const node =
|
const node =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||||
expect(host.isClass(node)).toBe(true);
|
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', () => {
|
it('should return false if a given node is a TS function declaration', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm2015ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const node =
|
const node =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
expect(host.isClass(node)).toBe(false);
|
expect(host.isClass(node)).toBe(false);
|
||||||
|
@ -1386,7 +1387,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const program = makeTestProgram(ARITY_CLASSES[0]);
|
const program = makeTestProgram(ARITY_CLASSES[0]);
|
||||||
const dtsProgram = makeTestProgram(ARITY_CLASSES[1]);
|
const dtsProgram = makeTestProgram(ARITY_CLASSES[1]);
|
||||||
const dts = makeTestBundleProgram([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 =
|
const noTypeParamClass =
|
||||||
getDeclaration(program, '/src/class.js', 'NoTypeParam', isNamedClassDeclaration);
|
getDeclaration(program, '/src/class.js', 'NoTypeParam', isNamedClassDeclaration);
|
||||||
expect(host.getGenericArityOfClass(noTypeParamClass)).toBe(0);
|
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',
|
it('should return a collection of all the switchable variable declarations in the given module',
|
||||||
() => {
|
() => {
|
||||||
const program = makeTestProgram(MARKER_FILE);
|
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 file = program.getSourceFile(MARKER_FILE.name) !;
|
||||||
const declarations = host.getSwitchableDeclarations(file);
|
const declarations = host.getSwitchableDeclarations(file);
|
||||||
expect(declarations.map(d => [d.name.getText(), d.initializer !.getText()])).toEqual([
|
expect(declarations.map(d => [d.name.getText(), d.initializer !.getText()])).toEqual([
|
||||||
|
@ -1415,7 +1417,7 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
describe('findDecoratedClasses()', () => {
|
describe('findDecoratedClasses()', () => {
|
||||||
it('should return an array of all decorated classes in the given source file', () => {
|
it('should return an array of all decorated classes in the given source file', () => {
|
||||||
const program = makeTestProgram(...DECORATED_FILES);
|
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 primaryFile = program.getSourceFile(DECORATED_FILES[0].name) !;
|
||||||
const secondaryFile = program.getSourceFile(DECORATED_FILES[1].name) !;
|
const secondaryFile = program.getSourceFile(DECORATED_FILES[1].name) !;
|
||||||
|
|
||||||
|
@ -1445,7 +1447,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const class1 =
|
const class1 =
|
||||||
getDeclaration(srcProgram, '/src/class1.js', 'Class1', isNamedClassDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
||||||
|
@ -1456,7 +1459,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const mooFn =
|
const mooFn =
|
||||||
getDeclaration(srcProgram, '/src/func1.js', 'mooFn', isNamedFunctionDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(mooFn);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/func1.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/func1.d.ts');
|
||||||
|
@ -1467,7 +1471,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const missingClass =
|
const missingClass =
|
||||||
getDeclaration(srcProgram, '/src/class1.js', 'MissingClass1', isNamedClassDeclaration);
|
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);
|
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||||
});
|
});
|
||||||
|
@ -1477,7 +1482,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const missingClass = getDeclaration(
|
const missingClass = getDeclaration(
|
||||||
srcProgram, '/src/missing-class.js', 'MissingClass2', isNamedClassDeclaration);
|
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);
|
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||||
});
|
});
|
||||||
|
@ -1488,7 +1494,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const class1 =
|
const class1 =
|
||||||
getDeclaration(srcProgram, '/src/flat-file.js', 'Class1', isNamedClassDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
||||||
|
@ -1499,7 +1506,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const class3 =
|
const class3 =
|
||||||
getDeclaration(srcProgram, '/src/flat-file.js', 'Class3', isNamedClassDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(class3);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class3.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class3.d.ts');
|
||||||
|
@ -1511,7 +1519,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const internalClass = getDeclaration(
|
const internalClass = getDeclaration(
|
||||||
srcProgram, '/src/internal.js', 'InternalClass', isNamedClassDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(internalClass);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/internal.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/internal.d.ts');
|
||||||
|
@ -1525,7 +1534,8 @@ describe('Esm2015ReflectionHost', () => {
|
||||||
getDeclaration(srcProgram, '/src/class2.js', 'Class2', isNamedClassDeclaration);
|
getDeclaration(srcProgram, '/src/class2.js', 'Class2', isNamedClassDeclaration);
|
||||||
const internalClass2 =
|
const internalClass2 =
|
||||||
getDeclaration(srcProgram, '/src/internal.js', 'Class2', isNamedClassDeclaration);
|
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);
|
const class2DtsDeclaration = host.getDtsDeclaration(class2);
|
||||||
expect(class2DtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class2.d.ts');
|
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',
|
it('should find every exported function that returns an object that looks like a ModuleWithProviders object',
|
||||||
() => {
|
() => {
|
||||||
const srcProgram = makeTestProgram(...MODULE_WITH_PROVIDERS_PROGRAM);
|
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 file = srcProgram.getSourceFile('/src/functions.js') !;
|
||||||
const fns = host.getModuleWithProvidersFunctions(file);
|
const fns = host.getModuleWithProvidersFunctions(file);
|
||||||
expect(fns.map(info => [info.declaration.name !.getText(), info.ngModule.text])).toEqual([
|
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',
|
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 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 file = srcProgram.getSourceFile('/src/methods.js') !;
|
||||||
const fn = host.getModuleWithProvidersFunctions(file);
|
const fn = host.getModuleWithProvidersFunctions(file);
|
||||||
expect(fn.map(fn => [fn.declaration.name !.getText(), fn.ngModule.text])).toEqual([
|
expect(fn.map(fn => [fn.declaration.name !.getText(), fn.ngModule.text])).toEqual([
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as ts from 'typescript';
|
||||||
|
|
||||||
import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||||
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';
|
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
import {expectTypeValueReferencesForParameters} from './util';
|
import {expectTypeValueReferencesForParameters} from './util';
|
||||||
|
@ -121,7 +122,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
describe('getDecoratorsOfDeclaration()', () => {
|
describe('getDecoratorsOfDeclaration()', () => {
|
||||||
it('should find the decorators on a class', () => {
|
it('should find the decorators on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -145,7 +146,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
{});
|
{});
|
||||||
|
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should support decorators being used inside @angular/core', () => {
|
it('should support decorators being used inside @angular/core', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[1]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -181,7 +182,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
describe('getMembersOfClass()', () => {
|
describe('getMembersOfClass()', () => {
|
||||||
it('should find decorated members on a class', () => {
|
it('should find decorated members on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -199,7 +200,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should find non decorated properties on a class', () => {
|
it('should find non decorated properties on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -213,7 +214,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should find static methods on a class', () => {
|
it('should find static methods on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -226,7 +227,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should find static properties on a class', () => {
|
it('should find static properties on a class', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -243,7 +244,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
spyOn(Esm5ReflectionHost.prototype, 'getImportOfIdentifier').and.returnValue({});
|
spyOn(Esm5ReflectionHost.prototype, 'getImportOfIdentifier').and.returnValue({});
|
||||||
|
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
|
|
||||||
|
@ -254,7 +255,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should support decorators being used inside @angular/core', () => {
|
it('should support decorators being used inside @angular/core', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[1]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
program, '/node_modules/@angular/core/some_directive.js', 'SomeDirective',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -270,7 +271,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
describe('getConstructorParameters', () => {
|
describe('getConstructorParameters', () => {
|
||||||
it('should find the decorated constructor parameters', () => {
|
it('should find the decorated constructor parameters', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -293,7 +294,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
.and.returnValue(mockImportInfo);
|
.and.returnValue(mockImportInfo);
|
||||||
|
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -311,7 +312,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
describe('findDecoratedClasses', () => {
|
describe('findDecoratedClasses', () => {
|
||||||
it('should return an array of all decorated classes in the given source file', () => {
|
it('should return an array of all decorated classes in the given source file', () => {
|
||||||
const program = makeTestProgram(...fileSystem.files);
|
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 ngModuleFile = program.getSourceFile('/ngmodule.js') !;
|
||||||
const ngModuleClasses = host.findDecoratedClasses(ngModuleFile);
|
const ngModuleClasses = host.findDecoratedClasses(ngModuleFile);
|
||||||
|
@ -332,7 +333,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
describe('getDeclarationOfIdentifier', () => {
|
describe('getDeclarationOfIdentifier', () => {
|
||||||
it('should return the declaration of a locally defined identifier', () => {
|
it('should return the declaration of a locally defined identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -352,7 +353,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
|
|
||||||
it('should return the declaration of an externally defined identifier', () => {
|
it('should return the declaration of an externally defined identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[0]);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
program, '/some_directive.js', 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
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', () => {
|
it('should find the "actual" declaration of an aliased variable identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const ngModuleRef = findIdentifier(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1',
|
program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1',
|
||||||
isNgModulePropertyAssignment);
|
isNgModulePropertyAssignment);
|
||||||
|
@ -389,7 +390,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
|
||||||
describe('getVariableValue', () => {
|
describe('getVariableValue', () => {
|
||||||
it('should find the "actual" declaration of an aliased variable identifier', () => {
|
it('should find the "actual" declaration of an aliased variable identifier', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const ngModuleRef = findVariableDeclaration(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'HttpClientXsrfModule_1');
|
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', () => {
|
it('should return undefined if the variable has no assignment', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const missingValue = findVariableDeclaration(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'missingValue');
|
program.getSourceFile(fileSystem.files[2].name) !, 'missingValue');
|
||||||
const value = host.getVariableValue(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', () => {
|
it('should return null if the variable is not assigned from a call to __decorate', () => {
|
||||||
const program = makeTestProgram(fileSystem.files[2]);
|
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(
|
const nonDecoratedVar = findVariableDeclaration(
|
||||||
program.getSourceFile(fileSystem.files[2].name) !, 'nonDecoratedVar');
|
program.getSourceFile(fileSystem.files[2].name) !, 'nonDecoratedVar');
|
||||||
const value = host.getVariableValue(nonDecoratedVar !);
|
const value = host.getVariableValue(nonDecoratedVar !);
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
|
|
||||||
import * as ts from 'typescript';
|
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 {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
import {Esm5ReflectionHost, getIifeBody} from '../../src/host/esm5_host';
|
import {Esm5ReflectionHost, getIifeBody} from '../../src/host/esm5_host';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';
|
||||||
|
|
||||||
import {expectTypeValueReferencesForParameters} from './util';
|
import {expectTypeValueReferencesForParameters} from './util';
|
||||||
|
@ -707,7 +708,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getDecoratorsOfDeclaration()', () => {
|
describe('getDecoratorsOfDeclaration()', () => {
|
||||||
it('should find the decorators on a class', () => {
|
it('should find the decorators on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -725,7 +726,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return null if the symbol is not a class', () => {
|
it('should return null if the symbol is not a class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const functionNode =
|
const functionNode =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
const decorators = host.getDecoratorsOfDeclaration(functionNode);
|
||||||
|
@ -734,7 +735,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return null if there are no decorators', () => {
|
it('should return null if there are no decorators', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||||
|
@ -743,7 +744,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore `decorators` if it is not an array literal', () => {
|
it('should ignore `decorators` if it is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NotArrayLiteral', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
const decorators = host.getDecoratorsOfDeclaration(classNode);
|
||||||
|
@ -752,18 +753,18 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore decorator elements that are not object literals', () => {
|
it('should ignore decorator elements that are not object literals', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NotObjectLiteral', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
|
||||||
expect(decorators.length).toBe(1);
|
expect(decorators.length).toBe(1);
|
||||||
expect(decorators[0]).toEqual(jasmine.objectContaining({name: 'Directive'}));
|
expect(decorators[0]).toEqual(jasmine.objectContaining<Decorator>({name: 'Directive'}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore decorator elements that have no `type` property', () => {
|
it('should ignore decorator elements that have no `type` property', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -774,7 +775,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
it('should ignore decorator elements whose `type` value is not an identifier', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration);
|
program, INVALID_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -789,7 +790,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
.and.returnValue(mockImportInfo);
|
.and.returnValue(mockImportInfo);
|
||||||
|
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -804,7 +805,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('(returned decorators `args`)', () => {
|
describe('(returned decorators `args`)', () => {
|
||||||
it('should be an empty array if decorator has no `args` property', () => {
|
it('should be an empty array if decorator has no `args` property', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -817,7 +818,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
it('should be an empty array if decorator\'s `args` has no property assignment', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
program, INVALID_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -830,7 +831,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if `args` property value is not an array literal', () => {
|
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
program, INVALID_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -846,7 +847,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getMembersOfClass()', () => {
|
describe('getMembersOfClass()', () => {
|
||||||
it('should find decorated members on a class', () => {
|
it('should find decorated members on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -864,7 +865,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find Object.defineProperty members on a class', () => {
|
it('should find Object.defineProperty members on a class', () => {
|
||||||
const program = makeTestProgram(ACCESSORS_FILE);
|
const program = makeTestProgram(ACCESSORS_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
getDeclaration(program, ACCESSORS_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -911,7 +912,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find non decorated properties on a class', () => {
|
it('should find non decorated properties on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -925,7 +926,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find static methods on a class', () => {
|
it('should find static methods on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -939,7 +940,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should find static properties on a class', () => {
|
it('should find static properties on a class', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -953,7 +954,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should throw if the symbol is not a class', () => {
|
it('should throw if the symbol is not a class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const functionNode =
|
const functionNode =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
expect(() => {
|
expect(() => {
|
||||||
|
@ -963,7 +964,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return an empty array if there are no prop decorators', () => {
|
it('should return an empty array if there are no prop decorators', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
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',
|
it('should not process decorated properties in `propDecorators` if it is not an object literal',
|
||||||
() => {
|
() => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -985,7 +986,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore prop decorator elements that are not object literals', () => {
|
it('should ignore prop decorator elements that are not object literals', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NotObjectLiteralProp',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -999,7 +1000,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore prop decorator elements that have no `type` property', () => {
|
it('should ignore prop decorator elements that have no `type` property', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration);
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NoTypeProperty', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -1012,7 +1013,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
it('should ignore prop decorator elements whose `type` value is not an identifier', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration);
|
program, INVALID_PROP_DECORATORS_FILE.name, 'NotIdentifier', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -1031,7 +1032,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -1047,7 +1048,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('(returned prop decorators `args`)', () => {
|
describe('(returned prop decorators `args`)', () => {
|
||||||
it('should be an empty array if prop decorator has no `args` property', () => {
|
it('should be an empty array if prop decorator has no `args` property', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1062,7 +1063,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if prop decorator\'s `args` has no property assignment', () => {
|
it('should be an empty array if prop decorator\'s `args` has no property assignment', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1077,7 +1078,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if `args` property value is not an array literal', () => {
|
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_PROP_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
program, INVALID_PROP_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1094,7 +1095,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
it('should ignore the prototype pseudo-static property on class imported from typings files',
|
it('should ignore the prototype pseudo-static property on class imported from typings files',
|
||||||
() => {
|
() => {
|
||||||
const program = makeTestProgram(UNWANTED_PROTOTYPE_EXPORT_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', isNamedClassDeclaration);
|
program, UNWANTED_PROTOTYPE_EXPORT_FILE.name, 'SomeParam', isNamedClassDeclaration);
|
||||||
const members = host.getMembersOfClass(classNode);
|
const members = host.getMembersOfClass(classNode);
|
||||||
|
@ -1105,7 +1106,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getConstructorParameters()', () => {
|
describe('getConstructorParameters()', () => {
|
||||||
it('should find the decorated constructor parameters', () => {
|
it('should find the decorated constructor parameters', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -1123,7 +1124,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should throw if the symbol is not a class', () => {
|
it('should throw if the symbol is not a class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const functionNode =
|
const functionNode =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
expect(() => { host.getConstructorParameters(functionNode); })
|
expect(() => { host.getConstructorParameters(functionNode); })
|
||||||
|
@ -1136,7 +1137,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return an array even if there are no decorators', () => {
|
it('should return an array even if there are no decorators', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass',
|
program, SIMPLE_CLASS_FILE.name, 'NoDecoratorConstructorClass',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1150,7 +1151,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return an empty array if there are no constructor parameters', () => {
|
it('should return an empty array if there are no constructor parameters', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration);
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoParameters', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -1163,7 +1164,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
it('should ignore `ctorParameters` if it does not return an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral',
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotArrayLiteral',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1179,7 +1180,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('(returned parameters `decorators`)', () => {
|
describe('(returned parameters `decorators`)', () => {
|
||||||
it('should ignore param decorator elements that are not object literals', () => {
|
it('should ignore param decorator elements that are not object literals', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotObjectLiteral',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1198,7 +1199,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore param decorator elements that have no `type` property', () => {
|
it('should ignore param decorator elements that have no `type` property', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty',
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NoTypeProperty',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1211,7 +1212,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
it('should ignore param decorator elements whose `type` value is not an identifier', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATORS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier',
|
program, INVALID_CTOR_DECORATORS_FILE.name, 'NotIdentifier',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1228,7 +1229,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
.and.returnValue(mockImportInfo);
|
.and.returnValue(mockImportInfo);
|
||||||
|
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const parameters = host.getConstructorParameters(classNode);
|
const parameters = host.getConstructorParameters(classNode);
|
||||||
|
@ -1256,7 +1257,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const program = makeTestProgram(file);
|
const program = makeTestProgram(file);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const classNode =
|
const classNode =
|
||||||
getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration);
|
getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||||
return host.getConstructorParameters(classNode);
|
return host.getConstructorParameters(classNode);
|
||||||
|
@ -1324,7 +1325,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('(returned parameters `decorators.args`)', () => {
|
describe('(returned parameters `decorators.args`)', () => {
|
||||||
it('should be an empty array if param decorator has no `args` property', () => {
|
it('should be an empty array if param decorator has no `args` property', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoArgsProperty',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1339,7 +1340,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if param decorator\'s `args` has no property assignment', () => {
|
it('should be an empty array if param decorator\'s `args` has no property assignment', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NoPropertyAssignment',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1353,7 +1354,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should be an empty array if `args` property value is not an array literal', () => {
|
it('should be an empty array if `args` property value is not an array literal', () => {
|
||||||
const program = makeTestProgram(INVALID_CTOR_DECORATOR_ARGS_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
program, INVALID_CTOR_DECORATOR_ARGS_FILE.name, 'NotArrayLiteral',
|
||||||
isNamedVariableDeclaration);
|
isNamedVariableDeclaration);
|
||||||
|
@ -1370,7 +1371,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getDefinitionOfFunction()', () => {
|
describe('getDefinitionOfFunction()', () => {
|
||||||
it('should return an object describing the function declaration passed as an argument', () => {
|
it('should return an object describing the function declaration passed as an argument', () => {
|
||||||
const program = makeTestProgram(FUNCTION_BODY_FILE);
|
const program = makeTestProgram(FUNCTION_BODY_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
|
|
||||||
const fooNode =
|
const fooNode =
|
||||||
getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !;
|
getDeclaration(program, FUNCTION_BODY_FILE.name, 'foo', isNamedFunctionDeclaration) !;
|
||||||
|
@ -1418,7 +1419,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getImportOfIdentifier()', () => {
|
describe('getImportOfIdentifier()', () => {
|
||||||
it('should find the import of an identifier', () => {
|
it('should find the import of an identifier', () => {
|
||||||
const program = makeTestProgram(...IMPORTS_FILES);
|
const program = makeTestProgram(...IMPORTS_FILES);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const variableNode =
|
const variableNode =
|
||||||
getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration);
|
getDeclaration(program, IMPORTS_FILES[1].name, 'b', isNamedVariableDeclaration);
|
||||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
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', () => {
|
it('should find the name by which the identifier was exported, not imported', () => {
|
||||||
const program = makeTestProgram(...IMPORTS_FILES);
|
const program = makeTestProgram(...IMPORTS_FILES);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const variableNode =
|
const variableNode =
|
||||||
getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration);
|
getDeclaration(program, IMPORTS_FILES[1].name, 'c', isNamedVariableDeclaration);
|
||||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
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', () => {
|
it('should return null if the identifier was not imported', () => {
|
||||||
const program = makeTestProgram(...IMPORTS_FILES);
|
const program = makeTestProgram(...IMPORTS_FILES);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const variableNode =
|
const variableNode =
|
||||||
getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration);
|
getDeclaration(program, IMPORTS_FILES[1].name, 'd', isNamedVariableDeclaration);
|
||||||
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
const importOfIdent = host.getImportOfIdentifier(variableNode.initializer as ts.Identifier);
|
||||||
|
@ -1450,7 +1451,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getDeclarationOfIdentifier()', () => {
|
describe('getDeclarationOfIdentifier()', () => {
|
||||||
it('should return the declaration of a locally defined identifier', () => {
|
it('should return the declaration of a locally defined identifier', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
||||||
|
@ -1470,7 +1471,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return the declaration of an externally defined identifier', () => {
|
it('should return the declaration of an externally defined identifier', () => {
|
||||||
const program = makeTestProgram(SOME_DIRECTIVE_FILE);
|
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(
|
const classNode = getDeclaration(
|
||||||
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||||
|
@ -1491,7 +1492,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const superGetDeclarationOfIdentifierSpy =
|
const superGetDeclarationOfIdentifierSpy =
|
||||||
spyOn(Esm2015ReflectionHost.prototype, 'getDeclarationOfIdentifier').and.callThrough();
|
spyOn(Esm2015ReflectionHost.prototype, 'getDeclarationOfIdentifier').and.callThrough();
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
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(
|
const outerDeclaration = getDeclaration(
|
||||||
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||||
|
@ -1518,7 +1519,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getExportsOfModule()', () => {
|
describe('getExportsOfModule()', () => {
|
||||||
it('should return a map of all the exports from a given module', () => {
|
it('should return a map of all the exports from a given module', () => {
|
||||||
const program = makeTestProgram(...EXPORTS_FILES);
|
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 file = program.getSourceFile(EXPORTS_FILES[1].name) !;
|
||||||
const exportDeclarations = host.getExportsOfModule(file);
|
const exportDeclarations = host.getExportsOfModule(file);
|
||||||
expect(exportDeclarations).not.toBe(null);
|
expect(exportDeclarations).not.toBe(null);
|
||||||
|
@ -1559,7 +1560,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('getClassSymbol()', () => {
|
describe('getClassSymbol()', () => {
|
||||||
it('should return the class symbol for an ES2015 class', () => {
|
it('should return the class symbol for an ES2015 class', () => {
|
||||||
const program = makeTestProgram(SIMPLE_ES2015_CLASS_FILE);
|
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(
|
const node = getDeclaration(
|
||||||
program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
program, SIMPLE_ES2015_CLASS_FILE.name, 'EmptyClass', isNamedClassDeclaration);
|
||||||
const classSymbol = host.getClassSymbol(node);
|
const classSymbol = host.getClassSymbol(node);
|
||||||
|
@ -1570,7 +1571,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return the class symbol for an ES5 class (outer variable declaration)', () => {
|
it('should return the class symbol for an ES5 class (outer variable declaration)', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const node =
|
const node =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||||
const classSymbol = host.getClassSymbol(node);
|
const classSymbol = host.getClassSymbol(node);
|
||||||
|
@ -1581,7 +1582,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return the class symbol for an ES5 class (inner function declaration)', () => {
|
it('should return the class symbol for an ES5 class (inner function declaration)', () => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const outerNode =
|
const outerNode =
|
||||||
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
getDeclaration(program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||||
const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
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',
|
it('should return the same class symbol (of the outer declaration) for outer and inner declarations',
|
||||||
() => {
|
() => {
|
||||||
const program = makeTestProgram(SIMPLE_CLASS_FILE);
|
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(
|
const outerNode = getDeclaration(
|
||||||
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
program, SIMPLE_CLASS_FILE.name, 'EmptyClass', isNamedVariableDeclaration);
|
||||||
const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
const innerNode = getIifeBody(outerNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||||
|
@ -1604,7 +1605,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
|
|
||||||
it('should return undefined if node is not an ES5 class', () => {
|
it('should return undefined if node is not an ES5 class', () => {
|
||||||
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
const program = makeTestProgram(FOO_FUNCTION_FILE);
|
||||||
const host = new Esm5ReflectionHost(false, program.getTypeChecker());
|
const host = new Esm5ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||||
const node =
|
const node =
|
||||||
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
getDeclaration(program, FOO_FUNCTION_FILE.name, 'foo', isNamedFunctionDeclaration);
|
||||||
const classSymbol = host.getClassSymbol(node);
|
const classSymbol = host.getClassSymbol(node);
|
||||||
|
@ -1620,7 +1621,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
let superGetClassDeclarationSpy: jasmine.Spy;
|
let superGetClassDeclarationSpy: jasmine.Spy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
host = new Esm5ReflectionHost(false, null as any);
|
host = new Esm5ReflectionHost(new MockLogger(), false, null as any);
|
||||||
mockNode = {} as any;
|
mockNode = {} as any;
|
||||||
|
|
||||||
getClassDeclarationSpy = spyOn(Esm5ReflectionHost.prototype, 'getClassDeclaration');
|
getClassDeclarationSpy = spyOn(Esm5ReflectionHost.prototype, 'getClassDeclaration');
|
||||||
|
@ -1659,7 +1660,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const program = makeTestProgram(file);
|
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);
|
const classNode = getDeclaration(program, file.name, 'TestClass', isNamedVariableDeclaration);
|
||||||
return host.hasBaseClass(classNode);
|
return host.hasBaseClass(classNode);
|
||||||
}
|
}
|
||||||
|
@ -1699,7 +1700,7 @@ describe('Esm5ReflectionHost', () => {
|
||||||
describe('findDecoratedClasses()', () => {
|
describe('findDecoratedClasses()', () => {
|
||||||
it('should return an array of all decorated classes in the given source file', () => {
|
it('should return an array of all decorated classes in the given source file', () => {
|
||||||
const program = makeTestProgram(...DECORATED_FILES);
|
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 primary = program.getSourceFile(DECORATED_FILES[0].name) !;
|
||||||
|
|
||||||
const primaryDecoratedClasses = host.findDecoratedClasses(primary);
|
const primaryDecoratedClasses = host.findDecoratedClasses(primary);
|
||||||
|
@ -1726,7 +1727,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const class1 =
|
const class1 =
|
||||||
getDeclaration(srcProgram, '/src/class1.js', 'Class1', ts.isVariableDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
||||||
|
@ -1736,7 +1738,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES);
|
const srcProgram = makeTestProgram(...TYPINGS_SRC_FILES);
|
||||||
const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dtsProgram = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const mooFn = getDeclaration(srcProgram, '/src/func1.js', 'mooFn', ts.isFunctionDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(mooFn);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/func1.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/func1.d.ts');
|
||||||
|
@ -1747,7 +1750,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const missingClass =
|
const missingClass =
|
||||||
getDeclaration(srcProgram, '/src/class1.js', 'MissingClass1', ts.isVariableDeclaration);
|
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);
|
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||||
});
|
});
|
||||||
|
@ -1757,7 +1761,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const missingClass = getDeclaration(
|
const missingClass = getDeclaration(
|
||||||
srcProgram, '/src/missing-class.js', 'MissingClass2', ts.isVariableDeclaration);
|
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);
|
expect(host.getDtsDeclaration(missingClass)).toBe(null);
|
||||||
});
|
});
|
||||||
|
@ -1768,7 +1773,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const class1 =
|
const class1 =
|
||||||
getDeclaration(srcProgram, '/src/flat-file.js', 'Class1', ts.isVariableDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(class1);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class1.d.ts');
|
||||||
|
@ -1779,7 +1785,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const class3 =
|
const class3 =
|
||||||
getDeclaration(srcProgram, '/src/flat-file.js', 'Class3', ts.isVariableDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(class3);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class3.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class3.d.ts');
|
||||||
|
@ -1791,7 +1798,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
const dts = makeTestBundleProgram(TYPINGS_DTS_FILES);
|
||||||
const internalClass = getDeclaration(
|
const internalClass = getDeclaration(
|
||||||
srcProgram, '/src/internal.js', 'InternalClass', ts.isVariableDeclaration);
|
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);
|
const dtsDeclaration = host.getDtsDeclaration(internalClass);
|
||||||
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/internal.d.ts');
|
expect(dtsDeclaration !.getSourceFile().fileName).toEqual('/typings/internal.d.ts');
|
||||||
|
@ -1805,7 +1813,8 @@ describe('Esm5ReflectionHost', () => {
|
||||||
getDeclaration(srcProgram, '/src/class2.js', 'Class2', ts.isVariableDeclaration);
|
getDeclaration(srcProgram, '/src/class2.js', 'Class2', ts.isVariableDeclaration);
|
||||||
const internalClass2 =
|
const internalClass2 =
|
||||||
getDeclaration(srcProgram, '/src/internal.js', 'Class2', ts.isVariableDeclaration);
|
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);
|
const class2DtsDeclaration = host.getDtsDeclaration(class2);
|
||||||
expect(class2DtsDeclaration !.getSourceFile().fileName).toEqual('/typings/class2.d.ts');
|
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',
|
it('should find every exported function that returns an object that looks like a ModuleWithProviders object',
|
||||||
() => {
|
() => {
|
||||||
const srcProgram = makeTestProgram(...MODULE_WITH_PROVIDERS_PROGRAM);
|
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 file = srcProgram.getSourceFile('/src/functions.js') !;
|
||||||
const fns = host.getModuleWithProvidersFunctions(file);
|
const fns = host.getModuleWithProvidersFunctions(file);
|
||||||
expect(fns.map(info => [info.declaration.name !.getText(), info.ngModule.text])).toEqual([
|
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',
|
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 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 file = srcProgram.getSourceFile('/src/methods.js') !;
|
||||||
const fn = host.getModuleWithProvidersFunctions(file);
|
const fn = host.getModuleWithProvidersFunctions(file);
|
||||||
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.text])).toEqual([
|
expect(fn.map(fn => [fn.declaration.getText(), fn.ngModule.text])).toEqual([
|
||||||
|
|
|
@ -14,6 +14,7 @@ const Module = require('module');
|
||||||
import {mainNgcc} from '../../src/main';
|
import {mainNgcc} from '../../src/main';
|
||||||
import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from '../../../test/runfile_helpers';
|
import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from '../../../test/runfile_helpers';
|
||||||
import {EntryPointPackageJson} from '../../src/packages/entry_point';
|
import {EntryPointPackageJson} from '../../src/packages/entry_point';
|
||||||
|
import {Logger} from '../../src/logging/logger';
|
||||||
|
|
||||||
describe('ngcc main()', () => {
|
describe('ngcc main()', () => {
|
||||||
beforeEach(createMockFileSystem);
|
beforeEach(createMockFileSystem);
|
||||||
|
@ -179,6 +180,21 @@ describe('ngcc main()', () => {
|
||||||
expect(existsSync(`/node_modules/@angular/common/common.d.ts.__ivy_ngcc_bak`)).toBe(true);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,13 +5,11 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {resolve} from 'canonical-path';
|
|
||||||
|
|
||||||
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
|
||||||
import {DependencyHost} from '../../src/packages/dependency_host';
|
import {DependencyHost} from '../../src/packages/dependency_host';
|
||||||
import {DependencyResolver, SortedEntryPointsInfo} from '../../src/packages/dependency_resolver';
|
import {DependencyResolver, SortedEntryPointsInfo} from '../../src/packages/dependency_resolver';
|
||||||
import {EntryPoint} from '../../src/packages/entry_point';
|
import {EntryPoint} from '../../src/packages/entry_point';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
const _ = AbsoluteFsPath.from;
|
const _ = AbsoluteFsPath.from;
|
||||||
|
|
||||||
|
@ -20,7 +18,7 @@ describe('DependencyResolver', () => {
|
||||||
let resolver: DependencyResolver;
|
let resolver: DependencyResolver;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
host = new DependencyHost();
|
host = new DependencyHost();
|
||||||
resolver = new DependencyResolver(host);
|
resolver = new DependencyResolver(new MockLogger(), host);
|
||||||
});
|
});
|
||||||
describe('sortEntryPointsByDependency()', () => {
|
describe('sortEntryPointsByDependency()', () => {
|
||||||
const first = { path: _('/first'), packageJson: {esm5: 'index.ts'} } as EntryPoint;
|
const first = { path: _('/first'), packageJson: {esm5: 'index.ts'} } as EntryPoint;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {DependencyHost} from '../../src/packages/dependency_host';
|
||||||
import {DependencyResolver} from '../../src/packages/dependency_resolver';
|
import {DependencyResolver} from '../../src/packages/dependency_resolver';
|
||||||
import {EntryPoint} from '../../src/packages/entry_point';
|
import {EntryPoint} from '../../src/packages/entry_point';
|
||||||
import {EntryPointFinder} from '../../src/packages/entry_point_finder';
|
import {EntryPointFinder} from '../../src/packages/entry_point_finder';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
const _ = AbsoluteFsPath.from;
|
const _ = AbsoluteFsPath.from;
|
||||||
|
|
||||||
|
@ -20,11 +21,11 @@ describe('findEntryPoints()', () => {
|
||||||
let resolver: DependencyResolver;
|
let resolver: DependencyResolver;
|
||||||
let finder: EntryPointFinder;
|
let finder: EntryPointFinder;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resolver = new DependencyResolver(new DependencyHost());
|
resolver = new DependencyResolver(new MockLogger(), new DependencyHost());
|
||||||
spyOn(resolver, 'sortEntryPointsByDependency').and.callFake((entryPoints: EntryPoint[]) => {
|
spyOn(resolver, 'sortEntryPointsByDependency').and.callFake((entryPoints: EntryPoint[]) => {
|
||||||
return {entryPoints, ignoredEntryPoints: [], ignoredDependencies: []};
|
return {entryPoints, ignoredEntryPoints: [], ignoredDependencies: []};
|
||||||
});
|
});
|
||||||
finder = new EntryPointFinder(resolver);
|
finder = new EntryPointFinder(new MockLogger(), resolver);
|
||||||
});
|
});
|
||||||
beforeEach(createMockFileSystem);
|
beforeEach(createMockFileSystem);
|
||||||
afterEach(restoreRealFileSystem);
|
afterEach(restoreRealFileSystem);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {readFileSync} from 'fs';
|
||||||
import * as mockFs from 'mock-fs';
|
import * as mockFs from 'mock-fs';
|
||||||
|
|
||||||
import {getEntryPointInfo} from '../../src/packages/entry_point';
|
import {getEntryPointInfo} from '../../src/packages/entry_point';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
describe('getEntryPointInfo()', () => {
|
describe('getEntryPointInfo()', () => {
|
||||||
beforeEach(createMockFileSystem);
|
beforeEach(createMockFileSystem);
|
||||||
|
@ -21,7 +22,8 @@ describe('getEntryPointInfo()', () => {
|
||||||
|
|
||||||
it('should return an object containing absolute paths to the formats of the specified entry-point',
|
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({
|
expect(entryPoint).toEqual({
|
||||||
name: 'some-package/valid_entry_point',
|
name: 'some-package/valid_entry_point',
|
||||||
package: SOME_PACKAGE,
|
package: SOME_PACKAGE,
|
||||||
|
@ -32,28 +34,32 @@ describe('getEntryPointInfo()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if there is no package.json at the entry-point path', () => {
|
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);
|
expect(entryPoint).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if there is no typings or types field in the package.json', () => {
|
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);
|
expect(entryPoint).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if there is no esm2015 nor fesm2015 field in the package.json', () => {
|
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);
|
expect(entryPoint).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if there is no metadata.json file next to the typing file', () => {
|
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);
|
expect(entryPoint).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work if the typings field is named `types', () => {
|
it('should work if the typings field is named `types', () => {
|
||||||
const entryPoint =
|
const entryPoint = getEntryPointInfo(
|
||||||
getEntryPointInfo(SOME_PACKAGE, _('/some_package/types_rather_than_typings'));
|
new MockLogger(), SOME_PACKAGE, _('/some_package/types_rather_than_typings'));
|
||||||
expect(entryPoint).toEqual({
|
expect(entryPoint).toEqual({
|
||||||
name: 'some-package/types_rather_than_typings',
|
name: 'some-package/types_rather_than_typings',
|
||||||
package: SOME_PACKAGE,
|
package: SOME_PACKAGE,
|
||||||
|
@ -64,7 +70,8 @@ describe('getEntryPointInfo()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with Angular Material style package.json', () => {
|
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({
|
expect(entryPoint).toEqual({
|
||||||
name: 'some_package/material_style',
|
name: 'some_package/material_style',
|
||||||
package: SOME_PACKAGE,
|
package: SOME_PACKAGE,
|
||||||
|
@ -75,7 +82,8 @@ describe('getEntryPointInfo()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if the package.json is not valid JSON', () => {
|
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);
|
expect(entryPoint).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,12 +15,14 @@ import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
import {EsmRenderer} from '../../src/rendering/esm_renderer';
|
import {EsmRenderer} from '../../src/rendering/esm_renderer';
|
||||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
function setup(file: {name: string, contents: string}) {
|
function setup(file: {name: string, contents: string}) {
|
||||||
|
const logger = new MockLogger();
|
||||||
const dir = dirname(file.name);
|
const dir = dirname(file.name);
|
||||||
const bundle = makeTestEntryPointBundle('es2015', 'esm2015', false, [file]) !;
|
const bundle = makeTestEntryPointBundle('es2015', 'esm2015', false, [file]) !;
|
||||||
const typeChecker = bundle.src.program.getTypeChecker();
|
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 referencesRegistry = new NgccReferencesRegistry(host);
|
||||||
const decorationAnalyses =
|
const decorationAnalyses =
|
||||||
new DecorationAnalyzer(
|
new DecorationAnalyzer(
|
||||||
|
@ -28,7 +30,7 @@ function setup(file: {name: string, contents: string}) {
|
||||||
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
|
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
|
||||||
.analyzeProgram();
|
.analyzeProgram();
|
||||||
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
|
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 {
|
return {
|
||||||
host,
|
host,
|
||||||
program: bundle.src.program,
|
program: bundle.src.program,
|
||||||
|
|
|
@ -15,12 +15,14 @@ import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||||
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
||||||
import {Esm5Renderer} from '../../src/rendering/esm5_renderer';
|
import {Esm5Renderer} from '../../src/rendering/esm5_renderer';
|
||||||
import {makeTestEntryPointBundle, getDeclaration} from '../helpers/utils';
|
import {makeTestEntryPointBundle, getDeclaration} from '../helpers/utils';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
function setup(file: {name: string, contents: string}) {
|
function setup(file: {name: string, contents: string}) {
|
||||||
|
const logger = new MockLogger();
|
||||||
const dir = dirname(file.name);
|
const dir = dirname(file.name);
|
||||||
const bundle = makeTestEntryPointBundle('module', 'esm5', false, [file]);
|
const bundle = makeTestEntryPointBundle('module', 'esm5', false, [file]);
|
||||||
const typeChecker = bundle.src.program.getTypeChecker();
|
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 referencesRegistry = new NgccReferencesRegistry(host);
|
||||||
const decorationAnalyses =
|
const decorationAnalyses =
|
||||||
new DecorationAnalyzer(
|
new DecorationAnalyzer(
|
||||||
|
@ -28,7 +30,7 @@ function setup(file: {name: string, contents: string}) {
|
||||||
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
|
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
|
||||||
.analyzeProgram();
|
.analyzeProgram();
|
||||||
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
|
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 {
|
return {
|
||||||
host,
|
host,
|
||||||
program: bundle.src.program,
|
program: bundle.src.program,
|
||||||
|
|
|
@ -18,10 +18,13 @@ import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||||
import {RedundantDecoratorMap, Renderer} from '../../src/rendering/renderer';
|
import {RedundantDecoratorMap, Renderer} from '../../src/rendering/renderer';
|
||||||
import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
|
import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
|
||||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||||
|
import {Logger} from '../../src/logging/logger';
|
||||||
|
import {MockLogger} from '../helpers/mock_logger';
|
||||||
|
|
||||||
class TestRenderer extends Renderer {
|
class TestRenderer extends Renderer {
|
||||||
constructor(host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
|
constructor(
|
||||||
super(host, isCore, bundle, '/src');
|
logger: Logger, host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
|
||||||
|
super(logger, host, isCore, bundle, '/src');
|
||||||
}
|
}
|
||||||
addImports(output: MagicString, imports: {specifier: string, qualifier: string}[]) {
|
addImports(output: MagicString, imports: {specifier: string, qualifier: string}[]) {
|
||||||
output.prepend('\n// ADD IMPORTS\n');
|
output.prepend('\n// ADD IMPORTS\n');
|
||||||
|
@ -49,10 +52,11 @@ class TestRenderer extends Renderer {
|
||||||
function createTestRenderer(
|
function createTestRenderer(
|
||||||
packageName: string, files: {name: string, contents: string}[],
|
packageName: string, files: {name: string, contents: string}[],
|
||||||
dtsFiles?: {name: string, contents: string}[]) {
|
dtsFiles?: {name: string, contents: string}[]) {
|
||||||
|
const logger = new MockLogger();
|
||||||
const isCore = packageName === '@angular/core';
|
const isCore = packageName === '@angular/core';
|
||||||
const bundle = makeTestEntryPointBundle('es2015', 'esm2015', isCore, files, dtsFiles);
|
const bundle = makeTestEntryPointBundle('es2015', 'esm2015', isCore, files, dtsFiles);
|
||||||
const typeChecker = bundle.src.program.getTypeChecker();
|
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 referencesRegistry = new NgccReferencesRegistry(host);
|
||||||
const decorationAnalyses = new DecorationAnalyzer(
|
const decorationAnalyses = new DecorationAnalyzer(
|
||||||
bundle.src.program, bundle.src.options, bundle.src.host,
|
bundle.src.program, bundle.src.options, bundle.src.host,
|
||||||
|
@ -63,7 +67,7 @@ function createTestRenderer(
|
||||||
new ModuleWithProvidersAnalyzer(host, referencesRegistry).analyzeProgram(bundle.src.program);
|
new ModuleWithProvidersAnalyzer(host, referencesRegistry).analyzeProgram(bundle.src.program);
|
||||||
const privateDeclarationsAnalyses =
|
const privateDeclarationsAnalyses =
|
||||||
new PrivateDeclarationsAnalyzer(host, referencesRegistry).analyzeProgram(bundle.src.program);
|
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, 'addImports').and.callThrough();
|
||||||
spyOn(renderer, 'addDefinitions').and.callThrough();
|
spyOn(renderer, 'addDefinitions').and.callThrough();
|
||||||
spyOn(renderer, 'removeDecorators').and.callThrough();
|
spyOn(renderer, 'removeDecorators').and.callThrough();
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {EntryPoint, EntryPointFormat, EntryPointJsonProperty, getEntryPointInfo}
|
||||||
import {EntryPointBundle, makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
import {EntryPointBundle, makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
||||||
import {FileWriter} from '../../src/writing/file_writer';
|
import {FileWriter} from '../../src/writing/file_writer';
|
||||||
import {NewEntryPointFileWriter} from '../../src/writing/new_entry_point_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';
|
import {loadPackageJson} from '../packages/entry_point_spec';
|
||||||
|
|
||||||
const _ = AbsoluteFsPath.from;
|
const _ = AbsoluteFsPath.from;
|
||||||
|
@ -79,7 +80,8 @@ describe('NewEntryPointFileWriter', () => {
|
||||||
describe('writeBundle() [primary entry-point]', () => {
|
describe('writeBundle() [primary entry-point]', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fileWriter = new NewEntryPointFileWriter();
|
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');
|
esm5bundle = makeTestBundle(entryPoint, 'module', 'esm5');
|
||||||
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
|
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
|
||||||
});
|
});
|
||||||
|
@ -155,7 +157,8 @@ describe('NewEntryPointFileWriter', () => {
|
||||||
describe('writeBundle() [secondary entry-point]', () => {
|
describe('writeBundle() [secondary entry-point]', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fileWriter = new NewEntryPointFileWriter();
|
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');
|
esm5bundle = makeTestBundle(entryPoint, 'module', 'esm5');
|
||||||
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
|
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
|
||||||
});
|
});
|
||||||
|
@ -219,7 +222,8 @@ describe('NewEntryPointFileWriter', () => {
|
||||||
describe('writeBundle() [entry-point (with files placed outside entry-point folder)]', () => {
|
describe('writeBundle() [entry-point (with files placed outside entry-point folder)]', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fileWriter = new NewEntryPointFileWriter();
|
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');
|
esm5bundle = makeTestBundle(entryPoint, 'module', 'esm5');
|
||||||
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
|
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue