style(ngcc): reformat of ngcc after clang update (#36447)
PR Close #36447
This commit is contained in:
parent
c8bef1259c
commit
8be8466a00
|
@ -7,9 +7,10 @@
|
|||
*/
|
||||
import {CachedFileSystem, NodeJSFileSystem, setFileSystem} from '../src/ngtsc/file_system';
|
||||
|
||||
import {AsyncNgccOptions, NgccOptions, SyncNgccOptions, mainNgcc} from './src/main';
|
||||
import {AsyncNgccOptions, mainNgcc, NgccOptions, SyncNgccOptions} from './src/main';
|
||||
|
||||
export {ConsoleLogger} from './src/logging/console_logger';
|
||||
export {LogLevel, Logger} from './src/logging/logger';
|
||||
export {Logger, LogLevel} from './src/logging/logger';
|
||||
export {AsyncNgccOptions, NgccOptions, SyncNgccOptions} from './src/main';
|
||||
export {PathMappings} from './src/utils';
|
||||
|
||||
|
|
|
@ -137,7 +137,10 @@ if (require.main === module) {
|
|||
createNewEntryPointFormats,
|
||||
logger,
|
||||
enableI18nLegacyMessageIdFormat,
|
||||
async: options['async'], invalidateEntryPointManifest, errorOnFailedEntryPoint, tsConfigPath
|
||||
async: options['async'],
|
||||
invalidateEntryPointManifest,
|
||||
errorOnFailedEntryPoint,
|
||||
tsConfigPath
|
||||
});
|
||||
|
||||
if (logger) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import {ParsedConfiguration} from '../../..';
|
|||
import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../src/ngtsc/annotations';
|
||||
import {CycleAnalyzer, ImportGraph} from '../../../src/ngtsc/cycles';
|
||||
import {isFatalDiagnosticError} from '../../../src/ngtsc/diagnostics';
|
||||
import {FileSystem, LogicalFileSystem, absoluteFrom, dirname, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, dirname, FileSystem, LogicalFileSystem, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, PrivateExportAliasingHost, Reexport, ReferenceEmitter} from '../../../src/ngtsc/imports';
|
||||
import {CompoundMetadataReader, CompoundMetadataRegistry, DtsMetadataReader, InjectableClassRegistry, LocalMetadataRegistry} from '../../../src/ngtsc/metadata';
|
||||
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
|
||||
|
@ -28,7 +28,7 @@ import {EntryPointBundle} from '../packages/entry_point_bundle';
|
|||
import {DefaultMigrationHost} from './migration_host';
|
||||
import {NgccTraitCompiler} from './ngcc_trait_compiler';
|
||||
import {CompiledClass, CompiledFile, DecorationAnalyses} from './types';
|
||||
import {NOOP_DEPENDENCY_TRACKER, isWithinPackage} from './util';
|
||||
import {isWithinPackage, NOOP_DEPENDENCY_TRACKER} from './util';
|
||||
|
||||
|
||||
|
||||
|
@ -38,8 +38,12 @@ import {NOOP_DEPENDENCY_TRACKER, isWithinPackage} from './util';
|
|||
class NgccResourceLoader implements ResourceLoader {
|
||||
constructor(private fs: FileSystem) {}
|
||||
canPreload = false;
|
||||
preload(): undefined|Promise<void> { throw new Error('Not implemented.'); }
|
||||
load(url: string): string { return this.fs.readFile(resolve(url)); }
|
||||
preload(): undefined|Promise<void> {
|
||||
throw new Error('Not implemented.');
|
||||
}
|
||||
load(url: string): string {
|
||||
return this.fs.readFile(resolve(url));
|
||||
}
|
||||
resolve(url: string, containingFile: string): string {
|
||||
return resolve(dirname(absoluteFrom(containingFile)), url);
|
||||
}
|
||||
|
@ -74,7 +78,8 @@ export class DecorationAnalyzer {
|
|||
new LogicalProjectStrategy(this.reflectionHost, new LogicalFileSystem(this.rootDirs)),
|
||||
]);
|
||||
aliasingHost = this.bundle.entryPoint.generateDeepReexports ?
|
||||
new PrivateExportAliasingHost(this.reflectionHost): null;
|
||||
new PrivateExportAliasingHost(this.reflectionHost) :
|
||||
null;
|
||||
dtsModuleScopeResolver =
|
||||
new MetadataDtsModuleScopeResolver(this.dtsMetaReader, this.aliasingHost);
|
||||
scopeRegistry = new LocalModuleScopeRegistry(
|
||||
|
@ -191,7 +196,9 @@ export class DecorationAnalyzer {
|
|||
});
|
||||
}
|
||||
|
||||
protected reportDiagnostics() { this.compiler.diagnostics.forEach(this.diagnosticHandler); }
|
||||
protected reportDiagnostics() {
|
||||
this.compiler.diagnostics.forEach(this.diagnosticHandler);
|
||||
}
|
||||
|
||||
protected compileFile(sourceFile: ts.SourceFile): CompiledFile {
|
||||
const constantPool = new ConstantPool();
|
||||
|
@ -211,7 +218,8 @@ export class DecorationAnalyzer {
|
|||
compiledClasses.push({
|
||||
name: record.node.name.text,
|
||||
decorators: this.compiler.getAllDecorators(record.node),
|
||||
declaration: record.node, compilation
|
||||
declaration: record.node,
|
||||
compilation
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,7 @@ export class ModuleWithProvidersAnalyzer {
|
|||
const dtsClass = this.host.getDtsDeclaration(containerClass.declaration.valueDeclaration);
|
||||
// Get the declaration of the matching static method
|
||||
dtsFn = dtsClass && ts.isClassDeclaration(dtsClass) ?
|
||||
dtsClass.members
|
||||
.find(
|
||||
dtsClass.members.find(
|
||||
member => ts.isMethodDeclaration(member) && ts.isIdentifier(member.name) &&
|
||||
member.name.text === fn.name) as ts.Declaration :
|
||||
null;
|
||||
|
@ -87,8 +86,8 @@ export class ModuleWithProvidersAnalyzer {
|
|||
throw new Error(`Matching type declaration for ${fn.declaration.getText()} is missing`);
|
||||
}
|
||||
if (!isFunctionOrMethod(dtsFn)) {
|
||||
throw new Error(
|
||||
`Matching type declaration for ${fn.declaration.getText()} is not a function: ${dtsFn.getText()}`);
|
||||
throw new Error(`Matching type declaration for ${
|
||||
fn.declaration.getText()} is not a function: ${dtsFn.getText()}`);
|
||||
}
|
||||
return dtsFn;
|
||||
}
|
||||
|
@ -106,12 +105,14 @@ export class ModuleWithProvidersAnalyzer {
|
|||
// to its type declaration.
|
||||
const dtsNgModule = this.host.getDtsDeclaration(ngModule.node);
|
||||
if (!dtsNgModule) {
|
||||
throw new Error(
|
||||
`No typings declaration can be found for the referenced NgModule class in ${fn.declaration.getText()}.`);
|
||||
throw new Error(`No typings declaration can be found for the referenced NgModule class in ${
|
||||
fn.declaration.getText()}.`);
|
||||
}
|
||||
if (!ts.isClassDeclaration(dtsNgModule) || !hasNameIdentifier(dtsNgModule)) {
|
||||
throw new Error(
|
||||
`The referenced NgModule in ${fn.declaration.getText()} is not a named class declaration in the typings program; instead we get ${dtsNgModule.getText()}`);
|
||||
throw new Error(`The referenced NgModule in ${
|
||||
fn.declaration
|
||||
.getText()} is not a named class declaration in the typings program; instead we get ${
|
||||
dtsNgModule.getText()}`);
|
||||
}
|
||||
|
||||
return {node: dtsNgModule, known: null, viaModule: null};
|
||||
|
|
|
@ -45,5 +45,7 @@ export class NgccReferencesRegistry implements ReferencesRegistry {
|
|||
* Create and return a mapping for the registered resolved references.
|
||||
* @returns A map of reference identifiers to reference declarations.
|
||||
*/
|
||||
getDeclarationMap(): Map<ts.Identifier, ConcreteDeclaration> { return this.map; }
|
||||
getDeclarationMap(): Map<ts.Identifier, ConcreteDeclaration> {
|
||||
return this.map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,9 @@ export class NgccTraitCompiler extends TraitCompiler {
|
|||
/* compileNonExportedClasses */ true, new DtsTransformRegistry());
|
||||
}
|
||||
|
||||
get analyzedFiles(): ts.SourceFile[] { return Array.from(this.fileToClasses.keys()); }
|
||||
get analyzedFiles(): ts.SourceFile[] {
|
||||
return Array.from(this.fileToClasses.keys());
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes the source file in search for classes to process. For any class that is found in the
|
||||
|
@ -81,5 +83,7 @@ export class NgccTraitCompiler extends TraitCompiler {
|
|||
}
|
||||
|
||||
class NoIncrementalBuild implements IncrementalBuild<any> {
|
||||
priorWorkFor(sf: ts.SourceFile): any[]|null { return null; }
|
||||
priorWorkFor(sf: ts.SourceFile): any[]|null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,11 @@
|
|||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFromSourceFile} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFromSourceFile, AbsoluteFsPath} from '../../../src/ngtsc/file_system';
|
||||
import {ConcreteDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {NgccReflectionHost} from '../host/ngcc_host';
|
||||
import {hasNameIdentifier, isDefined} from '../utils';
|
||||
|
||||
import {NgccReferencesRegistry} from './ngcc_references_registry';
|
||||
|
||||
export interface ExportInfo {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFromSourceFile, relative} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFromSourceFile, AbsoluteFsPath, relative} from '../../../src/ngtsc/file_system';
|
||||
import {DependencyTracker} from '../../../src/ngtsc/incremental/api';
|
||||
|
||||
export function isWithinPackage(packagePath: AbsoluteFsPath, sourceFile: ts.SourceFile): boolean {
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath} from '../../../src/ngtsc/file_system';
|
||||
import {RequireCall, isReexportStatement, isRequireCall} from '../host/commonjs_umd_utils';
|
||||
import {isReexportStatement, isRequireCall, RequireCall} from '../host/commonjs_umd_utils';
|
||||
|
||||
import {DependencyHostBase} from './dependency_host';
|
||||
import {ResolvedDeepImport, ResolvedRelativeModule} from './module_resolver';
|
||||
|
||||
|
@ -120,5 +122,7 @@ export class CommonJsDependencyHost extends DependencyHostBase {
|
|||
* @returns false if there are definitely no require calls
|
||||
* in this file, true otherwise.
|
||||
*/
|
||||
private hasRequireCalls(source: string): boolean { return /require\(['"]/.test(source); }
|
||||
private hasRequireCalls(source: string): boolean {
|
||||
return /require\(['"]/.test(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
*/
|
||||
|
||||
import {DepGraph} from 'dependency-graph';
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {NgccConfiguration} from '../packages/configuration';
|
||||
import {EntryPoint, EntryPointFormat, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat} from '../packages/entry_point';
|
||||
import {EntryPoint, EntryPointFormat, getEntryPointFormat, SUPPORTED_FORMAT_PROPERTIES} from '../packages/entry_point';
|
||||
import {PartiallyOrderedList} from '../utils';
|
||||
import {DependencyHost, DependencyInfo, createDependencyInfo} from './dependency_host';
|
||||
|
||||
import {createDependencyInfo, DependencyHost, DependencyInfo} from './dependency_host';
|
||||
|
||||
const builtinNodeJsModules = new Set<string>(require('module').builtinModules);
|
||||
|
||||
|
@ -123,7 +125,8 @@ export class DependencyResolver {
|
|||
const host = this.hosts[formatInfo.format];
|
||||
if (!host) {
|
||||
throw new Error(
|
||||
`Could not find a suitable format for computing dependencies of entry-point: '${entryPoint.path}'.`);
|
||||
`Could not find a suitable format for computing dependencies of entry-point: '${
|
||||
entryPoint.path}'.`);
|
||||
}
|
||||
const depInfo = createDependencyInfo();
|
||||
host.collectDependencies(formatInfo.path, depInfo);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 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 {AbsoluteFsPath, FileSystem, absoluteFrom, dirname, isRoot, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {PathMappings, isRelativePath, resolveFileWithPostfixes} from '../utils';
|
||||
import {absoluteFrom, AbsoluteFsPath, dirname, FileSystem, isRoot, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {isRelativePath, PathMappings, resolveFileWithPostfixes} from '../utils';
|
||||
|
||||
/**
|
||||
* This is a very cut-down implementation of the TypeScript module resolution strategy.
|
||||
|
|
|
@ -84,5 +84,7 @@ export class UmdDependencyHost extends DependencyHostBase {
|
|||
* @returns false if there are definitely no require calls
|
||||
* in this file, true otherwise.
|
||||
*/
|
||||
private hasRequireCalls(source: string): boolean { return /require\(['"]/.test(source); }
|
||||
private hasRequireCalls(source: string): boolean {
|
||||
return /require\(['"]/.test(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ import {AbsoluteFsPath, FileSystem, PathSegment} from '../../../src/ngtsc/file_s
|
|||
import {DependencyResolver, SortedEntryPointsInfo} from '../dependencies/dependency_resolver';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {NgccConfiguration} from '../packages/configuration';
|
||||
import {EntryPoint, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, getEntryPointInfo} from '../packages/entry_point';
|
||||
import {EntryPoint, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../packages/entry_point';
|
||||
import {EntryPointManifest} from '../packages/entry_point_manifest';
|
||||
import {PathMappings} from '../utils';
|
||||
import {NGCC_DIRECTORY} from '../writing/new_entry_point_file_writer';
|
||||
|
||||
import {EntryPointFinder} from './interface';
|
||||
import {getBasePaths, trackDuration} from './utils';
|
||||
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
* 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 {AbsoluteFsPath, FileSystem, PathSegment, join, relative, relativeFrom} from '../../../src/ngtsc/file_system';
|
||||
import {AbsoluteFsPath, FileSystem, join, PathSegment, relative, relativeFrom} from '../../../src/ngtsc/file_system';
|
||||
import {DependencyResolver, SortedEntryPointsInfo} from '../dependencies/dependency_resolver';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {hasBeenProcessed} from '../packages/build_marker';
|
||||
import {NgccConfiguration} from '../packages/configuration';
|
||||
import {EntryPoint, EntryPointJsonProperty, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, getEntryPointInfo} from '../packages/entry_point';
|
||||
import {EntryPoint, EntryPointJsonProperty, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../packages/entry_point';
|
||||
import {PathMappings} from '../utils';
|
||||
|
||||
import {EntryPointFinder} from './interface';
|
||||
import {getBasePaths} from './utils';
|
||||
|
||||
|
|
|
@ -51,7 +51,8 @@ export function getBasePaths(
|
|||
basePaths.push(basePath);
|
||||
} else {
|
||||
logger.warn(
|
||||
`The basePath "${basePath}" computed from baseUrl "${baseUrl}" and path mapping "${path}" does not exist in the file-system.\n` +
|
||||
`The basePath "${basePath}" computed from baseUrl "${baseUrl}" and path mapping "${
|
||||
path}" does not exist in the file-system.\n` +
|
||||
`It will not be scanned for entry-points.`);
|
||||
}
|
||||
}));
|
||||
|
@ -109,8 +110,8 @@ function removeContainedPaths(value: AbsoluteFsPath, index: number, array: Absol
|
|||
* @param log The function to call with the duration of the task
|
||||
* @returns The result of calling `task`.
|
||||
*/
|
||||
export function trackDuration<T = void>(
|
||||
task: () => T extends Promise<unknown>? never : T, log: (duration: number) => void): T {
|
||||
export function trackDuration<T = void>(task: () => T extends Promise<unknown>? never : T,
|
||||
log: (duration: number) => void): T {
|
||||
const startTime = Date.now();
|
||||
const result = task();
|
||||
const duration = Math.round((Date.now() - startTime) / 100) / 10;
|
||||
|
|
|
@ -35,8 +35,8 @@ export class ClusterExecutor implements Executor {
|
|||
if (cluster.isMaster) {
|
||||
// This process is the cluster master.
|
||||
return this.lockFile.lock(() => {
|
||||
this.logger.debug(
|
||||
`Running ngcc on ${this.constructor.name} (using ${this.workerCount} worker processes).`);
|
||||
this.logger.debug(`Running ngcc on ${this.constructor.name} (using ${
|
||||
this.workerCount} worker processes).`);
|
||||
const master = new ClusterMaster(
|
||||
this.workerCount, this.logger, this.pkgJsonUpdater, analyzeEntryPoints,
|
||||
this.createTaskCompletedCallback);
|
||||
|
|
|
@ -12,7 +12,7 @@ import * as cluster from 'cluster';
|
|||
|
||||
import {AbsoluteFsPath} from '../../../../src/ngtsc/file_system';
|
||||
import {JsonObject} from '../../packages/entry_point';
|
||||
import {PackageJsonChange, PackageJsonUpdate, PackageJsonUpdater, applyChange} from '../../writing/package_json_updater';
|
||||
import {applyChange, PackageJsonChange, PackageJsonUpdate, PackageJsonUpdater} from '../../writing/package_json_updater';
|
||||
|
||||
import {sendMessageToMaster} from './utils';
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
import {FileSystem, resolve} from '../../../../src/ngtsc/file_system';
|
||||
import {Logger} from '../../logging/logger';
|
||||
import {markAsProcessed} from '../../packages/build_marker';
|
||||
import {PackageJsonFormatProperties, getEntryPointFormat} from '../../packages/entry_point';
|
||||
import {getEntryPointFormat, PackageJsonFormatProperties} from '../../packages/entry_point';
|
||||
import {PackageJsonUpdater} from '../../writing/package_json_updater';
|
||||
|
||||
import {Task, TaskCompletedCallback, TaskProcessingOutcome, TaskQueue} from './api';
|
||||
|
||||
/**
|
||||
|
@ -33,8 +34,8 @@ export function composeTaskCompletedCallbacks(
|
|||
return (task: Task, outcome: TaskProcessingOutcome, message: string|null): void => {
|
||||
const callback = callbacks[outcome];
|
||||
if (callback === undefined) {
|
||||
throw new Error(
|
||||
`Unknown task outcome: "${outcome}" - supported outcomes: ${JSON.stringify(Object.keys(callbacks))}`);
|
||||
throw new Error(`Unknown task outcome: "${outcome}" - supported outcomes: ${
|
||||
JSON.stringify(Object.keys(callbacks))}`);
|
||||
}
|
||||
callback(task, message);
|
||||
};
|
||||
|
@ -67,7 +68,8 @@ export function createThrowErrorHandler(fs: FileSystem): TaskCompletedHandler {
|
|||
return (task: Task, message: string|null): void => {
|
||||
const format = getEntryPointFormat(fs, task.entryPoint, task.formatProperty);
|
||||
throw new Error(
|
||||
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${format})` +
|
||||
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${
|
||||
format})` +
|
||||
(message !== null ? ` due to ${message}` : ''));
|
||||
};
|
||||
}
|
||||
|
@ -81,7 +83,8 @@ export function createLogErrorHandler(
|
|||
taskQueue.markAsFailed(task);
|
||||
const format = getEntryPointFormat(fs, task.entryPoint, task.formatProperty);
|
||||
logger.error(
|
||||
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${format})` +
|
||||
`Failed to compile entry-point ${task.entryPoint.name} (${task.formatProperty} as ${
|
||||
format})` +
|
||||
(message !== null ? ` due to ${message}` : ''));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ export abstract class BaseTaskQueue implements TaskQueue {
|
|||
// We are skipping this task so mark it as complete
|
||||
this.markTaskCompleted(nextTask);
|
||||
const failedTask = this.tasksToSkip.get(nextTask)!;
|
||||
this.logger.warn(
|
||||
`Skipping processing of ${nextTask.entryPoint.name} because its dependency ${failedTask.entryPoint.name} failed to compile.`);
|
||||
this.logger.warn(`Skipping processing of ${nextTask.entryPoint.name} because its dependency ${
|
||||
failedTask.entryPoint.name} failed to compile.`);
|
||||
nextTask = this.computeNextTask();
|
||||
}
|
||||
return nextTask;
|
||||
|
|
|
@ -10,8 +10,8 @@ import {EntryPoint} from '../../packages/entry_point';
|
|||
import {PartiallyOrderedTasks, Task, TaskDependencies} from './api';
|
||||
|
||||
/** Stringify a task for debugging purposes. */
|
||||
export const stringifyTask = (task: Task): string =>
|
||||
`{entryPoint: ${task.entryPoint.name}, formatProperty: ${task.formatProperty}, processDts: ${task.processDts}}`;
|
||||
export const stringifyTask = (task: Task): string => `{entryPoint: ${
|
||||
task.entryPoint.name}, formatProperty: ${task.formatProperty}, processDts: ${task.processDts}}`;
|
||||
|
||||
/**
|
||||
* Compute a mapping of tasks to the tasks that are dependent on them (if any).
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {Declaration, Import} from '../../../src/ngtsc/reflection';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {BundleProgram} from '../packages/bundle_program';
|
||||
import {FactoryMap, getTsHelperFnFromIdentifier, isDefined, stripExtension} from '../utils';
|
||||
|
||||
import {ExportDeclaration, ExportStatement, ReexportStatement, RequireCall, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isReexportStatement, isRequireCall} from './commonjs_umd_utils';
|
||||
import {ExportDeclaration, ExportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isReexportStatement, isRequireCall, ReexportStatement, RequireCall} from './commonjs_umd_utils';
|
||||
import {Esm5ReflectionHost} from './esm5_host';
|
||||
import {NgccClassSymbol} from './ngcc_host';
|
||||
|
||||
|
|
|
@ -16,7 +16,12 @@ export interface ExportDeclaration {
|
|||
}
|
||||
|
||||
export interface ExportStatement extends ts.ExpressionStatement {
|
||||
expression: ts.BinaryExpression&{left: ts.PropertyAccessExpression & {expression: ts.Identifier}};
|
||||
expression: ts.BinaryExpression&{
|
||||
left: ts.PropertyAccessExpression &
|
||||
{
|
||||
expression: ts.Identifier
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +39,9 @@ export interface ExportStatement extends ts.ExpressionStatement {
|
|||
* expression and can be either a `require('...')` call or an identifier (initialized via a
|
||||
* `require('...')` call).
|
||||
*/
|
||||
export interface ReexportStatement extends ts.ExpressionStatement { expression: ts.CallExpression; }
|
||||
export interface ReexportStatement extends ts.ExpressionStatement {
|
||||
expression: ts.CallExpression;
|
||||
}
|
||||
|
||||
export interface RequireCall extends ts.CallExpression {
|
||||
arguments: ts.CallExpression['arguments']&[ts.StringLiteral];
|
||||
|
|
|
@ -13,7 +13,8 @@ import {Declaration, Import} from '../../../src/ngtsc/reflection';
|
|||
import {Logger} from '../logging/logger';
|
||||
import {BundleProgram} from '../packages/bundle_program';
|
||||
import {FactoryMap, getTsHelperFnFromIdentifier, stripExtension} from '../utils';
|
||||
import {ExportDeclaration, ExportStatement, ReexportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isReexportStatement, isRequireCall} from './commonjs_umd_utils';
|
||||
|
||||
import {ExportDeclaration, ExportStatement, findNamespaceOfIdentifier, findRequireCallReference, isExportStatement, isReexportStatement, isRequireCall, ReexportStatement} from './commonjs_umd_utils';
|
||||
import {Esm5ReflectionHost, stripParentheses} from './esm5_host';
|
||||
|
||||
export class UmdReflectionHost extends Esm5ReflectionHost {
|
||||
|
@ -61,7 +62,8 @@ export class UmdReflectionHost extends Esm5ReflectionHost {
|
|||
return this.umdImportPaths.get(importParameter);
|
||||
}
|
||||
|
||||
/** Get the top level statements for a module.
|
||||
/**
|
||||
* Get the top level statements for a module.
|
||||
*
|
||||
* In UMD modules these are the body of the UMD factory function.
|
||||
*
|
||||
|
|
|
@ -60,7 +60,10 @@ export class AsyncLocker {
|
|||
}
|
||||
// If we fall out of the loop then we ran out of rety attempts
|
||||
throw new Error(
|
||||
`Timed out waiting ${this.retryAttempts * this.retryDelay/1000}s for another ngcc process, with id ${pid}, to complete.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${this.lockFile.path}.)`);
|
||||
`Timed out waiting ${
|
||||
this.retryAttempts * this.retryDelay /
|
||||
1000}s for another ngcc process, with id ${pid}, to complete.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${
|
||||
this.lockFile.path}.)`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
import {ChildProcess, fork} from 'child_process';
|
||||
|
||||
import {AbsoluteFsPath, CachedFileSystem, FileSystem} from '../../../../src/ngtsc/file_system';
|
||||
import {LogLevel, Logger} from '../../logging/logger';
|
||||
import {LockFile, getLockFilePath} from '../lock_file';
|
||||
import {Logger, LogLevel} from '../../logging/logger';
|
||||
import {getLockFilePath, LockFile} from '../lock_file';
|
||||
|
||||
import {removeLockFile} from './util';
|
||||
|
||||
|
|
|
@ -36,4 +36,6 @@ logger.debug(`The lock-file path is ${lockFilePath}`);
|
|||
* When the parent process exits (for whatever reason) remove the loc-file if it exists and as long
|
||||
* as it was one that was created by the parent process.
|
||||
*/
|
||||
process.on('disconnect', () => { removeLockFile(fs, logger, lockFilePath, ppid); });
|
||||
process.on('disconnect', () => {
|
||||
removeLockFile(fs, logger, lockFilePath, ppid);
|
||||
});
|
||||
|
|
|
@ -57,6 +57,7 @@ export class SyncLocker {
|
|||
`ngcc is already running at process with id ${pid}.\n` +
|
||||
`If you are running multiple builds in parallel then you should pre-process your node_modules via the command line ngcc tool before starting the builds;\n` +
|
||||
`See https://v9.angular.io/guide/ivy#speeding-up-ngcc-compilation.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${this.lockFile.path}.)`);
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${
|
||||
this.lockFile.path}.)`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 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 {LogLevel, Logger} from './logger';
|
||||
import {Logger, LogLevel} from './logger';
|
||||
|
||||
const RESET = '\x1b[0m';
|
||||
const RED = '\x1b[31m';
|
||||
|
|
|
@ -14,7 +14,7 @@ import * as ts from 'typescript';
|
|||
|
||||
import {readConfiguration} from '../..';
|
||||
import {replaceTsWithNgInErrors} from '../../src/ngtsc/diagnostics';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, dirname, getFileSystem, resolve} from '../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, dirname, FileSystem, getFileSystem, resolve} from '../../src/ngtsc/file_system';
|
||||
|
||||
import {CommonJsDependencyHost} from './dependencies/commonjs_dependency_host';
|
||||
import {DependencyResolver, InvalidEntryPoint} from './dependencies/dependency_resolver';
|
||||
|
@ -38,10 +38,10 @@ import {AsyncLocker} from './locking/async_locker';
|
|||
import {LockFileWithChildProcess} from './locking/lock_file_with_child_process';
|
||||
import {SyncLocker} from './locking/sync_locker';
|
||||
import {ConsoleLogger} from './logging/console_logger';
|
||||
import {LogLevel, Logger} from './logging/logger';
|
||||
import {Logger, LogLevel} from './logging/logger';
|
||||
import {hasBeenProcessed} from './packages/build_marker';
|
||||
import {NgccConfiguration} from './packages/configuration';
|
||||
import {EntryPoint, EntryPointJsonProperty, EntryPointPackageJson, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat} from './packages/entry_point';
|
||||
import {EntryPoint, EntryPointJsonProperty, EntryPointPackageJson, getEntryPointFormat, SUPPORTED_FORMAT_PROPERTIES} from './packages/entry_point';
|
||||
import {makeEntryPointBundle} from './packages/entry_point_bundle';
|
||||
import {EntryPointManifest, InvalidatingEntryPointManifest} from './packages/entry_point_manifest';
|
||||
import {Transformer} from './packages/transformer';
|
||||
|
@ -181,12 +181,20 @@ export type NgccOptions = AsyncNgccOptions | SyncNgccOptions;
|
|||
*/
|
||||
export function mainNgcc(options: AsyncNgccOptions): Promise<void>;
|
||||
export function mainNgcc(options: SyncNgccOptions): void;
|
||||
export function mainNgcc(
|
||||
{basePath, targetEntryPointPath, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
|
||||
compileAllFormats = true, createNewEntryPointFormats = false,
|
||||
logger = new ConsoleLogger(LogLevel.info), pathMappings, async = false,
|
||||
errorOnFailedEntryPoint = false, enableI18nLegacyMessageIdFormat = true,
|
||||
invalidateEntryPointManifest = false, tsConfigPath}: NgccOptions): void|Promise<void> {
|
||||
export function mainNgcc({
|
||||
basePath,
|
||||
targetEntryPointPath,
|
||||
propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
|
||||
compileAllFormats = true,
|
||||
createNewEntryPointFormats = false,
|
||||
logger = new ConsoleLogger(LogLevel.info),
|
||||
pathMappings,
|
||||
async = false,
|
||||
errorOnFailedEntryPoint = false,
|
||||
enableI18nLegacyMessageIdFormat = true,
|
||||
invalidateEntryPointManifest = false,
|
||||
tsConfigPath
|
||||
}: NgccOptions): void|Promise<void> {
|
||||
if (!!targetEntryPointPath) {
|
||||
// targetEntryPointPath forces us to error if an entry-point fails.
|
||||
errorOnFailedEntryPoint = true;
|
||||
|
|
|
@ -60,7 +60,8 @@ export function createDirectiveDecorator(
|
|||
identifier: null,
|
||||
import: {name: 'Directive', from: '@angular/core'},
|
||||
node: null,
|
||||
synthesizedFor: clazz.name, args,
|
||||
synthesizedFor: clazz.name,
|
||||
args,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, FileSystem, dirname, resolve} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {AbsoluteFsPath, dirname, FileSystem, resolve} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {patchTsGetExpandoInitializer, restoreGetExpandoInitializer} from './patch_ts_expando_initializer';
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
import {createHash} from 'crypto';
|
||||
import {satisfies} from 'semver';
|
||||
import * as vm from 'vm';
|
||||
import {AbsoluteFsPath, FileSystem, dirname, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {AbsoluteFsPath, dirname, FileSystem, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {PackageJsonFormatPropertiesMap} from './entry_point';
|
||||
|
||||
/**
|
||||
|
@ -256,7 +258,8 @@ export class NgccConfiguration {
|
|||
const theExports = {};
|
||||
const sandbox = {
|
||||
module: {exports: theExports},
|
||||
exports: theExports, require,
|
||||
exports: theExports,
|
||||
require,
|
||||
__dirname: dirname(srcPath),
|
||||
__filename: srcPath
|
||||
};
|
||||
|
@ -292,9 +295,8 @@ export class NgccConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
function findSatisfactoryVersion(
|
||||
configs: VersionedPackageConfig[] | undefined, version: string | null): VersionedPackageConfig|
|
||||
null {
|
||||
function findSatisfactoryVersion(configs: VersionedPackageConfig[]|undefined, version: string|null):
|
||||
VersionedPackageConfig|null {
|
||||
if (configs === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,9 @@ export interface EntryPoint extends JsonObject {
|
|||
export type JsonPrimitive = string|number|boolean|null;
|
||||
export type JsonValue = JsonPrimitive|JsonArray|JsonObject|undefined;
|
||||
export interface JsonArray extends Array<JsonValue> {}
|
||||
export interface JsonObject { [key: string]: JsonValue; }
|
||||
export interface JsonObject {
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
|
||||
export interface PackageJsonFormatPropertiesMap {
|
||||
fesm2015?: string;
|
||||
|
@ -97,8 +99,7 @@ export const INCOMPATIBLE_ENTRY_POINT = 'incompatible-entry-point';
|
|||
* * INCOMPATIBLE_ENTRY_POINT - the path was a non-processable entry-point that should be searched
|
||||
* for sub-entry-points
|
||||
*/
|
||||
export type GetEntryPointResult =
|
||||
EntryPoint | typeof INCOMPATIBLE_ENTRY_POINT | typeof NO_ENTRY_POINT;
|
||||
export type GetEntryPointResult = EntryPoint|typeof INCOMPATIBLE_ENTRY_POINT|typeof NO_ENTRY_POINT;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -161,7 +162,8 @@ export function getEntryPointInfo(
|
|||
packageJson: entryPointPackageJson,
|
||||
package: packagePath,
|
||||
path: entryPointPath,
|
||||
typings: resolve(entryPointPath, typings), compiledByAngular,
|
||||
typings: resolve(entryPointPath, typings),
|
||||
compiledByAngular,
|
||||
ignoreMissingDependencies:
|
||||
entryPointConfig !== undefined ? !!entryPointConfig.ignoreMissingDependencies : false,
|
||||
generateDeepReexports:
|
||||
|
|
|
@ -48,10 +48,8 @@ export function makeEntryPointBundle(
|
|||
enableI18nLegacyMessageIdFormat: boolean = true): EntryPointBundle {
|
||||
// Create the TS program and necessary helpers.
|
||||
const rootDir = entryPoint.package;
|
||||
const options: ts.CompilerOptions = {
|
||||
allowJs: true,
|
||||
maxNodeModuleJsDepth: Infinity, rootDir, ...pathMappings
|
||||
};
|
||||
const options: ts
|
||||
.CompilerOptions = {allowJs: true, maxNodeModuleJsDepth: Infinity, rootDir, ...pathMappings};
|
||||
const srcHost = new NgccSourcesCompilerHost(fs, options, entryPoint.path);
|
||||
const dtsHost = new NgtscCompilerHost(fs, options);
|
||||
|
||||
|
@ -72,7 +70,12 @@ export function makeEntryPointBundle(
|
|||
return {
|
||||
entryPoint,
|
||||
format,
|
||||
rootDirs: [rootDir], isCore, isFlatCore, src, dts, enableI18nLegacyMessageIdFormat
|
||||
rootDirs: [rootDir],
|
||||
isCore,
|
||||
isFlatCore,
|
||||
src,
|
||||
dts,
|
||||
enableI18nLegacyMessageIdFormat
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import {Logger} from '../logging/logger';
|
|||
|
||||
import {NGCC_VERSION} from './build_marker';
|
||||
import {NgccConfiguration} from './configuration';
|
||||
import {EntryPoint, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, getEntryPointInfo} from './entry_point';
|
||||
import {EntryPoint, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from './entry_point';
|
||||
|
||||
/**
|
||||
* Manages reading and writing a manifest file that contains a list of all the entry-points that
|
||||
|
@ -63,8 +63,8 @@ export class EntryPointManifest {
|
|||
return null;
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
`Entry-point manifest found for ${basePath} so loading entry-point information directly.`);
|
||||
this.logger.debug(`Entry-point manifest found for ${
|
||||
basePath} so loading entry-point information directly.`);
|
||||
const startTime = Date.now();
|
||||
|
||||
const entryPoints: EntryPoint[] = [];
|
||||
|
@ -72,8 +72,9 @@ export class EntryPointManifest {
|
|||
const result =
|
||||
getEntryPointInfo(this.fs, this.config, this.logger, packagePath, entryPointPath);
|
||||
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
|
||||
throw new Error(
|
||||
`The entry-point manifest at ${manifestPath} contained an invalid pair of package paths: [${packagePath}, ${entryPointPath}]`);
|
||||
throw new Error(`The entry-point manifest at ${
|
||||
manifestPath} contained an invalid pair of package paths: [${packagePath}, ${
|
||||
entryPointPath}]`);
|
||||
} else {
|
||||
entryPoints.push(result);
|
||||
}
|
||||
|
@ -142,7 +143,9 @@ export class EntryPointManifest {
|
|||
* called.
|
||||
*/
|
||||
export class InvalidatingEntryPointManifest extends EntryPointManifest {
|
||||
readEntryPointsUsingManifest(basePath: AbsoluteFsPath): EntryPoint[]|null { return null; }
|
||||
readEntryPointsUsingManifest(basePath: AbsoluteFsPath): EntryPoint[]|null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,13 +58,12 @@ export function patchTsGetExpandoInitializer(): unknown {
|
|||
}
|
||||
|
||||
// Override the function to add support for recognizing the IIFE structure used in ES5 bundles.
|
||||
(ts as any).getExpandoInitializer =
|
||||
(initializer: ts.Node, isPrototypeAssignment: boolean): ts.Expression | undefined => {
|
||||
(ts as any).getExpandoInitializer = (initializer: ts.Node,
|
||||
isPrototypeAssignment: boolean): ts.Expression|undefined => {
|
||||
// If the initializer is a call expression within parenthesis, unwrap the parenthesis
|
||||
// upfront such that unsupported IIFE syntax `(function(){}())` becomes `function(){}()`,
|
||||
// which is supported.
|
||||
if (ts.isParenthesizedExpression(initializer) &&
|
||||
ts.isCallExpression(initializer.expression)) {
|
||||
if (ts.isParenthesizedExpression(initializer) && ts.isCallExpression(initializer.expression)) {
|
||||
initializer = initializer.expression;
|
||||
}
|
||||
return originalGetExpandoInitializer(initializer, isPrototypeAssignment);
|
||||
|
@ -125,16 +124,36 @@ function checkIfExpandoPropertyIsPresent(): boolean {
|
|||
const sourceFile =
|
||||
ts.createSourceFile('test.js', sourceText, ts.ScriptTarget.ES5, true, ts.ScriptKind.JS);
|
||||
const host: ts.CompilerHost = {
|
||||
getSourceFile(): ts.SourceFile | undefined{return sourceFile;},
|
||||
fileExists(): boolean{return true;},
|
||||
readFile(): string | undefined{return '';},
|
||||
getSourceFile(): ts.SourceFile |
|
||||
undefined {
|
||||
return sourceFile;
|
||||
},
|
||||
fileExists(): boolean {
|
||||
return true;
|
||||
},
|
||||
readFile(): string |
|
||||
undefined {
|
||||
return '';
|
||||
},
|
||||
writeFile() {},
|
||||
getDefaultLibFileName(): string{return '';},
|
||||
getCurrentDirectory(): string{return '';},
|
||||
getDirectories(): string[]{return [];},
|
||||
getCanonicalFileName(fileName: string): string{return fileName;},
|
||||
useCaseSensitiveFileNames(): boolean{return true;},
|
||||
getNewLine(): string{return '\n';},
|
||||
getDefaultLibFileName(): string {
|
||||
return '';
|
||||
},
|
||||
getCurrentDirectory(): string {
|
||||
return '';
|
||||
},
|
||||
getDirectories(): string[] {
|
||||
return [];
|
||||
},
|
||||
getCanonicalFileName(fileName: string): string {
|
||||
return fileName;
|
||||
},
|
||||
useCaseSensitiveFileNames(): boolean {
|
||||
return true;
|
||||
},
|
||||
getNewLine(): string {
|
||||
return '\n';
|
||||
},
|
||||
};
|
||||
const options = {noResolve: true, noLib: true, noEmit: true, allowJs: true};
|
||||
const program = ts.createProgram(['test.js'], options, host);
|
||||
|
|
|
@ -36,8 +36,7 @@ import {EntryPointBundle} from './entry_point_bundle';
|
|||
|
||||
export type TransformResult = {
|
||||
success: true; diagnostics: ts.Diagnostic[]; transformedFiles: FileToWrite[];
|
||||
} |
|
||||
{
|
||||
}|{
|
||||
success: false;
|
||||
diagnostics: ts.Diagnostic[];
|
||||
};
|
||||
|
@ -79,8 +78,13 @@ export class Transformer {
|
|||
const reflectionHost = new DelegatingReflectionHost(tsReflectionHost, ngccReflectionHost);
|
||||
|
||||
// Parse and analyze the files.
|
||||
const {decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses, diagnostics} = this.analyzeProgram(reflectionHost, bundle);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses,
|
||||
diagnostics
|
||||
} = this.analyzeProgram(reflectionHost, bundle);
|
||||
|
||||
// Bail if the analysis produced any errors.
|
||||
if (hasErrors(diagnostics)) {
|
||||
|
@ -162,8 +166,13 @@ export class Transformer {
|
|||
const privateDeclarationsAnalyses =
|
||||
privateDeclarationsAnalyzer.analyzeProgram(bundle.src.program);
|
||||
|
||||
return {decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses, diagnostics};
|
||||
return {
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses,
|
||||
diagnostics
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,15 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {dirname, relative} from 'canonical-path';
|
||||
import * as ts from 'typescript';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
import {Import, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||
import {isRequireCall} from '../host/commonjs_umd_utils';
|
||||
import {NgccReflectionHost} from '../host/ngcc_host';
|
||||
|
||||
import {Esm5RenderingFormatter} from './esm5_rendering_formatter';
|
||||
import {stripExtension} from './utils';
|
||||
|
||||
|
|
|
@ -7,20 +7,22 @@
|
|||
*/
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {FileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
import {CompileResult} from '../../../src/ngtsc/transform';
|
||||
import {translateType, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {ImportManager, translateType} from '../../../src/ngtsc/translator';
|
||||
import {ModuleWithProvidersAnalyses, ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer';
|
||||
import {ExportInfo, PrivateDeclarationsAnalyses} from '../analysis/private_declarations_analyzer';
|
||||
import {DecorationAnalyses} from '../analysis/types';
|
||||
import {ModuleWithProvidersInfo, ModuleWithProvidersAnalyses} from '../analysis/module_with_providers_analyzer';
|
||||
import {PrivateDeclarationsAnalyses, ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||
import {IMPORT_PREFIX} from '../constants';
|
||||
import {NgccReflectionHost} from '../host/ngcc_host';
|
||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {FileToWrite, getImportRewriter} from './utils';
|
||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||
|
||||
import {RenderingFormatter} from './rendering_formatter';
|
||||
import {renderSourceAndMap} from './source_maps';
|
||||
import {FileToWrite, getImportRewriter} from './utils';
|
||||
|
||||
/**
|
||||
* A structure that captures information about what needs to be rendered
|
||||
|
|
|
@ -25,14 +25,14 @@ export class Esm5RenderingFormatter extends EsmRenderingFormatter {
|
|||
addDefinitions(output: MagicString, compiledClass: CompiledClass, definitions: string): void {
|
||||
const iifeBody = getIifeBody(compiledClass.declaration);
|
||||
if (!iifeBody) {
|
||||
throw new Error(
|
||||
`Compiled class declaration is not inside an IIFE: ${compiledClass.name} in ${compiledClass.declaration.getSourceFile().fileName}`);
|
||||
throw new Error(`Compiled class declaration is not inside an IIFE: ${compiledClass.name} in ${
|
||||
compiledClass.declaration.getSourceFile().fileName}`);
|
||||
}
|
||||
|
||||
const returnStatement = iifeBody.statements.find(ts.isReturnStatement);
|
||||
if (!returnStatement) {
|
||||
throw new Error(
|
||||
`Compiled class wrapper IIFE does not have a return statement: ${compiledClass.name} in ${compiledClass.declaration.getSourceFile().fileName}`);
|
||||
throw new Error(`Compiled class wrapper IIFE does not have a return statement: ${
|
||||
compiledClass.name} in ${compiledClass.declaration.getSourceFile().fileName}`);
|
||||
}
|
||||
|
||||
const insertionPoint = returnStatement.getFullStart();
|
||||
|
|
|
@ -8,17 +8,19 @@
|
|||
import {Statement} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {relative, dirname, AbsoluteFsPath, absoluteFromSourceFile} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {absoluteFromSourceFile, AbsoluteFsPath, dirname, relative} from '../../../src/ngtsc/file_system';
|
||||
import {NOOP_DEFAULT_IMPORT_RECORDER, Reexport} from '../../../src/ngtsc/imports';
|
||||
import {Import, ImportManager, translateStatement} from '../../../src/ngtsc/translator';
|
||||
import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
|
||||
import {CompiledClass} from '../analysis/types';
|
||||
import {NgccReflectionHost, POST_R3_MARKER, PRE_R3_MARKER, SwitchableVariableDeclaration} from '../host/ngcc_host';
|
||||
import {ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer';
|
||||
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||
import {RenderingFormatter, RedundantDecoratorMap} from './rendering_formatter';
|
||||
import {stripExtension} from './utils';
|
||||
import {CompiledClass} from '../analysis/types';
|
||||
import {isAssignment} from '../host/esm2015_host';
|
||||
import {NgccReflectionHost, POST_R3_MARKER, PRE_R3_MARKER, SwitchableVariableDeclaration} from '../host/ngcc_host';
|
||||
|
||||
import {RedundantDecoratorMap, RenderingFormatter} from './rendering_formatter';
|
||||
import {stripExtension} from './utils';
|
||||
|
||||
/**
|
||||
* A RenderingFormatter that works with ECMAScript Module import and export statements.
|
||||
|
@ -226,7 +228,8 @@ export class EsmRenderingFormatter implements RenderingFormatter {
|
|||
info.declaration.getEnd();
|
||||
outputText.appendLeft(
|
||||
insertPoint,
|
||||
`: ${generateImportString(importManager, '@angular/core', 'ModuleWithProviders')}<${ngModule}>`);
|
||||
`: ${generateImportString(importManager, '@angular/core', 'ModuleWithProviders')}<${
|
||||
ngModule}>`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,16 +8,18 @@
|
|||
import {ConstantPool, Expression, Statement, WrappedNodeExpr, WritePropExpr} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {FileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {CompiledClass, CompiledFile, DecorationAnalyses} from '../analysis/types';
|
||||
import {PrivateDeclarationsAnalyses} from '../analysis/private_declarations_analyzer';
|
||||
import {SwitchMarkerAnalyses, SwitchMarkerAnalysis} from '../analysis/switch_marker_analyzer';
|
||||
import {CompiledClass, CompiledFile, DecorationAnalyses} from '../analysis/types';
|
||||
import {IMPORT_PREFIX} from '../constants';
|
||||
import {FileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {NgccReflectionHost} from '../host/ngcc_host';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||
import {RenderingFormatter, RedundantDecoratorMap} from './rendering_formatter';
|
||||
|
||||
import {RedundantDecoratorMap, RenderingFormatter} from './rendering_formatter';
|
||||
import {renderSourceAndMap} from './source_maps';
|
||||
import {FileToWrite, getImportRewriter, stripExtension} from './utils';
|
||||
|
||||
|
@ -160,8 +162,9 @@ export class Renderer {
|
|||
private renderDefinitions(
|
||||
sourceFile: ts.SourceFile, compiledClass: CompiledClass, imports: ImportManager): string {
|
||||
const name = this.host.getInternalNameOfClass(compiledClass.declaration);
|
||||
const statements: Statement[] = compiledClass.compilation.map(
|
||||
c => { return createAssignmentStatement(name, c.name, c.initializer); });
|
||||
const statements: Statement[] = compiledClass.compilation.map(c => {
|
||||
return createAssignmentStatement(name, c.name, c.initializer);
|
||||
});
|
||||
return this.renderStatements(sourceFile, statements, imports);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
import {Statement} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
import {Import, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer';
|
||||
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||
import {CompiledClass} from '../analysis/types';
|
||||
import {SwitchableVariableDeclaration} from '../host/ngcc_host';
|
||||
import {ModuleWithProvidersInfo} from '../analysis/module_with_providers_analyzer';
|
||||
|
||||
/**
|
||||
* The collected decorators that have become redundant after the compilation
|
||||
|
|
|
@ -5,14 +5,16 @@
|
|||
* 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 {SourceMapConverter, fromObject, generateMapFileComment} from 'convert-source-map';
|
||||
import {fromObject, generateMapFileComment, SourceMapConverter} from 'convert-source-map';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {FileSystem, absoluteFromSourceFile, basename, absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {FileToWrite} from './utils';
|
||||
import {SourceFileLoader} from '../sourcemaps/source_file_loader';
|
||||
import {RawSourceMap} from '../sourcemaps/raw_source_map';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, basename, FileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {RawSourceMap} from '../sourcemaps/raw_source_map';
|
||||
import {SourceFileLoader} from '../sourcemaps/source_file_loader';
|
||||
|
||||
import {FileToWrite} from './utils';
|
||||
|
||||
export interface SourceMapInfo {
|
||||
source: string;
|
||||
|
@ -53,8 +55,8 @@ export function renderSourceAndMap(
|
|||
];
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
`Error when flattening the source-map "${generatedMapPath}" for "${generatedPath}": ${e.toString()}`);
|
||||
logger.error(`Error when flattening the source-map "${generatedMapPath}" for "${
|
||||
generatedPath}": ${e.toString()}`);
|
||||
return [
|
||||
{path: generatedPath, contents: generatedContent},
|
||||
{path: generatedMapPath, contents: fromObject(generatedMap).toJSON()},
|
||||
|
|
|
@ -6,14 +6,16 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {dirname, relative} from 'canonical-path';
|
||||
import * as ts from 'typescript';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
import {Import, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {ExportInfo} from '../analysis/private_declarations_analyzer';
|
||||
import {UmdReflectionHost} from '../host/umd_host';
|
||||
|
||||
import {Esm5RenderingFormatter} from './esm5_rendering_formatter';
|
||||
import {stripExtension} from './utils';
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
|
||||
type CommonJsConditional = ts.ConditionalExpression&{whenTrue: ts.CallExpression};
|
||||
type AmdConditional = ts.ConditionalExpression&{whenTrue: ts.CallExpression};
|
||||
|
@ -24,7 +26,9 @@ type AmdConditional = ts.ConditionalExpression & {whenTrue: ts.CallExpression};
|
|||
* wrapper function for AMD, CommonJS and global module formats.
|
||||
*/
|
||||
export class UmdRenderingFormatter extends Esm5RenderingFormatter {
|
||||
constructor(protected umdHost: UmdReflectionHost, isCore: boolean) { super(umdHost, isCore); }
|
||||
constructor(protected umdHost: UmdReflectionHost, isCore: boolean) {
|
||||
super(umdHost, isCore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the imports to the UMD module IIFE.
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {removeComments, removeMapFileComments} from 'convert-source-map';
|
||||
import {SourceMapMappings, SourceMapSegment, decode, encode} from 'sourcemap-codec';
|
||||
import {decode, encode, SourceMapMappings, SourceMapSegment} from 'sourcemap-codec';
|
||||
|
||||
import {AbsoluteFsPath, dirname, relative} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {RawSourceMap} from './raw_source_map';
|
||||
import {SegmentMarker, compareSegments, offsetSegment} from './segment_marker';
|
||||
import {compareSegments, offsetSegment, SegmentMarker} from './segment_marker';
|
||||
|
||||
export function removeSourceMapComments(contents: string): string {
|
||||
return removeMapFileComments(removeComments(contents)).replace(/\n\n$/, '\n');
|
||||
|
@ -77,7 +79,8 @@ export class SourceFile {
|
|||
const sourceMap: RawSourceMap = {
|
||||
version: 3,
|
||||
file: relative(sourcePathDir, this.sourcePath),
|
||||
sources: sources.map(sf => relative(sourcePathDir, sf.sourcePath)), names,
|
||||
sources: sources.map(sf => relative(sourcePathDir, sf.sourcePath)),
|
||||
names,
|
||||
mappings: encode(mappings),
|
||||
sourcesContent: sources.map(sf => sf.contents),
|
||||
};
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {commentRegex, fromComment, mapFileCommentRegex} from 'convert-source-map';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system';
|
||||
|
||||
import {RawSourceMap} from './raw_source_map';
|
||||
import {SourceFile} from './source_file';
|
||||
|
||||
|
@ -51,8 +53,8 @@ export class SourceFileLoader {
|
|||
// Track source file paths if we have loaded them from disk so that we don't get into an
|
||||
// infinite recursion
|
||||
if (previousPaths.includes(sourcePath)) {
|
||||
throw new Error(
|
||||
`Circular source file mapping dependency: ${previousPaths.join(' -> ')} -> ${sourcePath}`);
|
||||
throw new Error(`Circular source file mapping dependency: ${
|
||||
previousPaths.join(' -> ')} -> ${sourcePath}`);
|
||||
}
|
||||
previousPaths = previousPaths.concat([sourcePath]);
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom} from '../../src/ngtsc/file_system';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../src/ngtsc/file_system';
|
||||
import {KnownDeclaration} from '../../src/ngtsc/reflection';
|
||||
|
||||
/**
|
||||
|
@ -114,7 +115,9 @@ export class FactoryMap<K, V> {
|
|||
return this.internalMap.get(key)!;
|
||||
}
|
||||
|
||||
set(key: K, value: V): void { this.internalMap.set(key, value); }
|
||||
set(key: K, value: V): void {
|
||||
this.internalMap.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {AbsoluteFsPath, FileSystem, PathSegment, absoluteFrom} from '../../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, PathSegment} from '../../../../src/ngtsc/file_system';
|
||||
import {cleanPackageJson} from '../../packages/build_marker';
|
||||
import {NGCC_BACKUP_EXTENSION} from '../in_place_file_writer';
|
||||
import {NGCC_DIRECTORY} from '../new_entry_point_file_writer';
|
||||
|
||||
import {isLocalDirectory} from './utils';
|
||||
|
||||
/**
|
||||
|
@ -44,7 +45,9 @@ export class NgccDirectoryCleaner implements CleaningStrategy {
|
|||
canClean(path: AbsoluteFsPath, basename: PathSegment): boolean {
|
||||
return basename === NGCC_DIRECTORY && isLocalDirectory(this.fs, path);
|
||||
}
|
||||
clean(path: AbsoluteFsPath, _basename: PathSegment): void { this.fs.removeDeep(path); }
|
||||
clean(path: AbsoluteFsPath, _basename: PathSegment): void {
|
||||
this.fs.removeDeep(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
* 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 {FileSystem, absoluteFrom, dirname} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, dirname, FileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {EntryPointJsonProperty} from '../packages/entry_point';
|
||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||
import {FileToWrite} from '../rendering/utils';
|
||||
|
||||
import {FileWriter} from './file_writer';
|
||||
|
||||
export const NGCC_BACKUP_EXTENSION = '.__ivy_ngcc_bak';
|
||||
|
@ -37,7 +38,9 @@ export class InPlaceFileWriter implements FileWriter {
|
|||
`Tried to overwrite ${backPath} with an ngcc back up file, which is disallowed.`);
|
||||
} else {
|
||||
this.logger.error(
|
||||
`Tried to write ${backPath} with an ngcc back up file but it already exists so not writing, nor backing up, ${file.path}.\n` +
|
||||
`Tried to write ${
|
||||
backPath} with an ngcc back up file but it already exists so not writing, nor backing up, ${
|
||||
file.path}.\n` +
|
||||
`This error may be because two or more entry-points overlap and ngcc has been asked to process some files more than once.\n` +
|
||||
`You should check other entry-points in this package and set up a config to ignore any that you are not using.`);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* 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 {AbsoluteFsPath, FileSystem, absoluteFromSourceFile, dirname, join, relative} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFromSourceFile, AbsoluteFsPath, dirname, FileSystem, join, relative} from '../../../src/ngtsc/file_system';
|
||||
import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
|
||||
import {Logger} from '../logging/logger';
|
||||
import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, dirname} from '../../../src/ngtsc/file_system';
|
||||
import {AbsoluteFsPath, dirname, FileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {JsonObject, JsonValue} from '../packages/entry_point';
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import * as ts from 'typescript';
|
|||
|
||||
import {FatalDiagnosticError, makeDiagnostic} from '../../../src/ngtsc/diagnostics';
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassDeclaration, Decorator} from '../../../src/ngtsc/reflection';
|
||||
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
|
@ -29,7 +29,9 @@ runInEachFileSystem(() => {
|
|||
describe('DecorationAnalyzer', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
beforeEach(() => { _ = absoluteFrom; });
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
});
|
||||
|
||||
describe('analyzeProgram()', () => {
|
||||
let logs: string[];
|
||||
|
@ -94,17 +96,17 @@ runInEachFileSystem(() => {
|
|||
// The "test" compilation result is just the name of the decorator being compiled
|
||||
// (suffixed with `(compiled)`)
|
||||
handler.compile.and.callFake((decl: ts.Declaration, analysis: any) => {
|
||||
logs.push(
|
||||
`compile: ${(decl as any).name.text}@${analysis.decoratorName} (resolved: ${analysis.resolved})`);
|
||||
logs.push(`compile: ${(decl as any).name.text}@${analysis.decoratorName} (resolved: ${
|
||||
analysis.resolved})`);
|
||||
return `@${analysis.decoratorName} (compiled)`;
|
||||
});
|
||||
return handler;
|
||||
};
|
||||
|
||||
function setUpAnalyzer(
|
||||
testFiles: TestFile[],
|
||||
options: {analyzeError: boolean,
|
||||
resolveError: boolean} = {analyzeError: false, resolveError: false}) {
|
||||
function setUpAnalyzer(testFiles: TestFile[], options: {
|
||||
analyzeError: boolean,
|
||||
resolveError: boolean
|
||||
} = {analyzeError: false, resolveError: false}) {
|
||||
logs = [];
|
||||
loadTestFiles(testFiles);
|
||||
loadFakeCore(getFileSystem());
|
||||
|
@ -195,17 +197,20 @@ runInEachFileSystem(() => {
|
|||
const compiledFile1 = result.get(file1)!;
|
||||
expect(compiledFile1.compiledClasses.length).toEqual(2);
|
||||
expect(compiledFile1.compiledClasses[0]).toEqual(jasmine.objectContaining({
|
||||
name: 'MyComponent', compilation: ['@Component (compiled)'],
|
||||
name: 'MyComponent',
|
||||
compilation: ['@Component (compiled)'],
|
||||
} as unknown as CompiledClass));
|
||||
expect(compiledFile1.compiledClasses[1]).toEqual(jasmine.objectContaining({
|
||||
name: 'MyDirective', compilation: ['@Directive (compiled)'],
|
||||
name: 'MyDirective',
|
||||
compilation: ['@Directive (compiled)'],
|
||||
} as unknown as CompiledClass));
|
||||
|
||||
const file2 = getSourceFileOrError(program, _('/node_modules/test-package/other.js'));
|
||||
const compiledFile2 = result.get(file2)!;
|
||||
expect(compiledFile2.compiledClasses.length).toEqual(1);
|
||||
expect(compiledFile2.compiledClasses[0]).toEqual(jasmine.objectContaining({
|
||||
name: 'MyOtherComponent', compilation: ['@Component (compiled)'],
|
||||
name: 'MyOtherComponent',
|
||||
compilation: ['@Component (compiled)'],
|
||||
} as unknown as CompiledClass));
|
||||
});
|
||||
|
||||
|
@ -427,11 +432,15 @@ runInEachFileSystem(() => {
|
|||
name = 'FakeDecoratorHandler';
|
||||
precedence = HandlerPrecedence.PRIMARY;
|
||||
|
||||
detect(): undefined { throw new Error('detect should not have been called'); }
|
||||
detect(): undefined {
|
||||
throw new Error('detect should not have been called');
|
||||
}
|
||||
analyze(): AnalysisOutput<unknown> {
|
||||
throw new Error('analyze should not have been called');
|
||||
}
|
||||
compile(): CompileResult { throw new Error('compile should not have been called'); }
|
||||
compile(): CompileResult {
|
||||
throw new Error('compile should not have been called');
|
||||
}
|
||||
}
|
||||
|
||||
const analyzer = setUpAnalyzer([{
|
||||
|
|
|
@ -183,9 +183,13 @@ class DetectDecoratorHandler implements DecoratorHandler<unknown, unknown, unkno
|
|||
return {trigger: node, decorator, metadata: {}};
|
||||
}
|
||||
|
||||
analyze(node: ClassDeclaration): AnalysisOutput<unknown> { return {}; }
|
||||
analyze(node: ClassDeclaration): AnalysisOutput<unknown> {
|
||||
return {};
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] { return []; }
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class DiagnosticProducingHandler implements DecoratorHandler<unknown, unknown, unknown> {
|
||||
|
@ -201,5 +205,7 @@ class DiagnosticProducingHandler implements DecoratorHandler<unknown, unknown, u
|
|||
return {diagnostics: [makeDiagnostic(9999, node, 'test diagnostic')]};
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] { return []; }
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFrom, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {ModuleWithProvidersAnalyses, ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer';
|
||||
|
@ -414,8 +414,7 @@ runInEachFileSystem(() => {
|
|||
analyses: ModuleWithProvidersAnalyses, fileName: AbsoluteFsPath) {
|
||||
const file = getSourceFileOrError(dtsProgram.program, fileName);
|
||||
const analysis = analyses.get(file);
|
||||
return analysis ?
|
||||
analysis.map(
|
||||
return analysis ? analysis.map(
|
||||
info =>
|
||||
[info.declaration.name!.getText(),
|
||||
(info.ngModule.node as ts.ClassDeclaration).name!.getText(),
|
||||
|
|
|
@ -218,8 +218,7 @@ runInEachFileSystem(() => {
|
|||
expect(record).toBeDefined();
|
||||
expect(record.metaDiagnostics).toBeDefined();
|
||||
expect(record.metaDiagnostics!.length).toBe(1);
|
||||
expect(record.metaDiagnostics ![0].code)
|
||||
.toBe(ngErrorCode(ErrorCode.DECORATOR_COLLISION));
|
||||
expect(record.metaDiagnostics![0].code).toBe(ngErrorCode(ErrorCode.DECORATOR_COLLISION));
|
||||
expect(record.traits.length).toBe(0);
|
||||
});
|
||||
|
||||
|
@ -292,7 +291,6 @@ runInEachFileSystem(() => {
|
|||
expect(decorators[1].name).toBe('InjectedDecorator');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {Reference} from '../../../src/ngtsc/imports';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers/src/mock_file_loading';
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {Reference} from '../../../src/ngtsc/imports';
|
||||
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
|
||||
import {TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {absoluteFrom, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
|
@ -15,7 +15,6 @@ import {makeTestEntryPointBundle} from '../helpers/utils';
|
|||
|
||||
runInEachFileSystem(() => {
|
||||
describe('SwitchMarkerAnalyzer', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let TEST_PROGRAM: TestFile[];
|
||||
|
||||
|
|
|
@ -414,8 +414,9 @@ runInEachFileSystem(() => {
|
|||
} = importsPerType;
|
||||
|
||||
// var foo = require('...');
|
||||
importsOfTypeVarDeclaration.forEach(
|
||||
p => { importStatements.push(`var ${pathToVarName(p)} = require('${p}');`); });
|
||||
importsOfTypeVarDeclaration.forEach(p => {
|
||||
importStatements.push(`var ${pathToVarName(p)} = require('${p}');`);
|
||||
});
|
||||
|
||||
// var foo = require('...'), bar = require('...');
|
||||
importsOfTypeVarDeclarations.forEach(pp => {
|
||||
|
@ -424,8 +425,9 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
// exports.foo = require('...');
|
||||
importsOfTypePropAssignment.forEach(
|
||||
p => { importStatements.push(`exports.${pathToVarName(p)} = require('${p}');`); });
|
||||
importsOfTypePropAssignment.forEach(p => {
|
||||
importStatements.push(`exports.${pathToVarName(p)} = require('${p}');`);
|
||||
});
|
||||
|
||||
// module.exports = {foo: require('...')};
|
||||
const propAssignments =
|
||||
|
@ -434,15 +436,19 @@ runInEachFileSystem(() => {
|
|||
importStatements.push(`module.exports = {${propAssignments}\n};`);
|
||||
|
||||
// require('...');
|
||||
importsOfTypeForSideEffects.forEach(p => { importStatements.push(`require('${p}');`); });
|
||||
importsOfTypeForSideEffects.forEach(p => {
|
||||
importStatements.push(`require('${p}');`);
|
||||
});
|
||||
|
||||
// __export(require('...'));
|
||||
importsOfTypeReExportsWithEmittedHelper.forEach(
|
||||
p => { importStatements.push(`__export(require('${p}'));`); });
|
||||
importsOfTypeReExportsWithEmittedHelper.forEach(p => {
|
||||
importStatements.push(`__export(require('${p}'));`);
|
||||
});
|
||||
|
||||
// tslib_1.__exportStar(require('...'), exports);
|
||||
importsOfTypeReExportsWithImportedHelper.forEach(
|
||||
p => { importStatements.push(`tslib_1.__exportStar(require('${p}'), exports);`); });
|
||||
importsOfTypeReExportsWithImportedHelper.forEach(p => {
|
||||
importStatements.push(`tslib_1.__exportStar(require('${p}'), exports);`);
|
||||
});
|
||||
|
||||
// var foo = require('...');
|
||||
// __export(foo);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {DepGraph} from 'dependency-graph';
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, relativeFrom} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relativeFrom} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {DependencyInfo} from '../../src/dependencies/dependency_host';
|
||||
import {DependencyResolver, SortedEntryPointsInfo} from '../../src/dependencies/dependency_resolver';
|
||||
|
@ -254,7 +254,8 @@ runInEachFileSystem(() => {
|
|||
const result = resolver.sortEntryPointsByDependency([first]);
|
||||
expect(result.entryPoints).toEqual([first]);
|
||||
expect(logger.logs.warn).toEqual([[
|
||||
`Entry point 'first' contains deep imports into '${_('/deep/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
`Entry point 'first' contains deep imports into '${
|
||||
_('/deep/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
]]);
|
||||
});
|
||||
|
||||
|
@ -292,9 +293,9 @@ runInEachFileSystem(() => {
|
|||
const result = resolver.sortEntryPointsByDependency([testEntryPoint]);
|
||||
expect(result.entryPoints).toEqual([testEntryPoint]);
|
||||
expect(logger.logs.warn).toEqual([[
|
||||
`Entry point 'test-package' contains deep imports into '${_('/project/node_modules/deeper/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
`Entry point 'test-package' contains deep imports into '${
|
||||
_('/project/node_modules/deeper/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
]]);
|
||||
|
||||
});
|
||||
|
||||
it('should error if the entry point does not have a suitable format', () => {
|
||||
|
@ -307,7 +308,8 @@ runInEachFileSystem(() => {
|
|||
resolver = new DependencyResolver(fs, new MockLogger(), config, {esm2015: host}, host);
|
||||
expect(() => resolver.sortEntryPointsByDependency([first]))
|
||||
.toThrowError(
|
||||
`Could not find a suitable format for computing dependencies of entry-point: '${first.path}'.`);
|
||||
`Could not find a suitable format for computing dependencies of entry-point: '${
|
||||
first.path}'.`);
|
||||
});
|
||||
|
||||
it('should capture any dependencies that were ignored', () => {
|
||||
|
|
|
@ -14,7 +14,6 @@ import {createDependencyInfo} from '../../src/dependencies/dependency_host';
|
|||
import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
||||
describe('DtsDependencyHost', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
let host: DtsDependencyHost;
|
||||
|
|
|
@ -16,7 +16,6 @@ import {EsmDependencyHost, hasImportOrReexportStatements, isStringImportOrReexpo
|
|||
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
||||
describe('EsmDependencyHost', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
let host: EsmDependencyHost;
|
||||
|
|
|
@ -251,8 +251,10 @@ runInEachFileSystem(() => {
|
|||
exportNames.map(e => ` exports.${e.replace(/.+\./, '')} = ${e};`).join('\n');
|
||||
return `
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports${commonJsRequires}) :
|
||||
typeof define === 'function' && define.amd ? define('${moduleName}', ['exports'${amdDeps}], factory) :
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports${
|
||||
commonJsRequires}) :
|
||||
typeof define === 'function' && define.amd ? define('${moduleName}', ['exports'${
|
||||
amdDeps}], factory) :
|
||||
(factory(global.${moduleName}${globalParams}));
|
||||
}(this, (function (exports${params}) { 'use strict';
|
||||
${exportStatements}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 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 {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DependencyResolver} from '../../src/dependencies/dependency_resolver';
|
||||
import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* 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 {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DependencyResolver} from '../../src/dependencies/dependency_resolver';
|
||||
import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
|
@ -365,7 +365,6 @@ runInEachFileSystem(() => {
|
|||
basePath: AbsoluteFsPath, entryPoints: EntryPoint[]): [string, string][] {
|
||||
return entryPoints.map(x => [relative(basePath, x.package), relative(basePath, x.path)]);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
describe('targetNeedsProcessingOrCleaning()', () => {
|
||||
|
|
|
@ -132,9 +132,12 @@ runInEachFileSystem(() => {
|
|||
fs.resolve(projectDirectory, 'dist-1'),
|
||||
]);
|
||||
expect(logger.logs.warn).toEqual([
|
||||
[`The basePath "${fs.resolve(projectDirectory, 'sub-folder/dist-2')}" computed from baseUrl "${projectDirectory}" and path mapping "sub-folder/dist-2" does not exist in the file-system.\n` +
|
||||
[`The basePath "${
|
||||
fs.resolve(projectDirectory, 'sub-folder/dist-2')}" computed from baseUrl "${
|
||||
projectDirectory}" and path mapping "sub-folder/dist-2" does not exist in the file-system.\n` +
|
||||
`It will not be scanned for entry-points.`],
|
||||
[`The basePath "${fs.resolve(projectDirectory, 'libs')}" computed from baseUrl "${projectDirectory}" and path mapping "libs/*" does not exist in the file-system.\n` +
|
||||
[`The basePath "${fs.resolve(projectDirectory, 'libs')}" computed from baseUrl "${
|
||||
projectDirectory}" and path mapping "libs/*" does not exist in the file-system.\n` +
|
||||
`It will not be scanned for entry-points.`],
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -39,8 +39,9 @@ runInEachFileSystem(() => {
|
|||
isMaster => describe(`(on cluster ${isMaster ? 'master' : 'worker'})`, () => {
|
||||
beforeEach(() => runAsClusterMaster(isMaster));
|
||||
|
||||
it('should return a `PackageJsonUpdate` instance',
|
||||
() => { expect(updater.createUpdate()).toEqual(jasmine.any(PackageJsonUpdate)); });
|
||||
it('should return a `PackageJsonUpdate` instance', () => {
|
||||
expect(updater.createUpdate()).toEqual(jasmine.any(PackageJsonUpdate));
|
||||
});
|
||||
|
||||
it('should wire up the `PackageJsonUpdate` with its `writeChanges()` method', () => {
|
||||
const writeChangesSpy = spyOn(updater, 'writeChanges');
|
||||
|
|
|
@ -60,11 +60,9 @@ describe('ClusterWorker', () => {
|
|||
|
||||
onTaskCompleted(null as any, TaskProcessingOutcome.Processed, null);
|
||||
expect(processSendSpy).toHaveBeenCalledTimes(1);
|
||||
expect(processSendSpy).toHaveBeenCalledWith({
|
||||
type: 'task-completed',
|
||||
outcome: TaskProcessingOutcome.Processed,
|
||||
message: null
|
||||
});
|
||||
expect(processSendSpy)
|
||||
.toHaveBeenCalledWith(
|
||||
{type: 'task-completed', outcome: TaskProcessingOutcome.Processed, message: null});
|
||||
|
||||
processSendSpy.calls.reset();
|
||||
|
||||
|
@ -137,7 +135,9 @@ describe('ClusterWorker', () => {
|
|||
} as unknown as Task;
|
||||
|
||||
let err: string|Error;
|
||||
compileFnSpy.and.callFake(() => { throw err; });
|
||||
compileFnSpy.and.callFake(() => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
worker.run();
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ import {EntryPoint} from '../../src/packages/entry_point';
|
|||
*
|
||||
* NOTE 1: The first task for each entry-point generates typings (which is similar to what happens
|
||||
* in the actual code).
|
||||
* NOTE 2: The `computeTaskDependencies()` implementation relies on the fact that tasks are sorted in such
|
||||
* a way that a task can only depend upon earlier tasks (i.e. dependencies always come
|
||||
* NOTE 2: The `computeTaskDependencies()` implementation relies on the fact that tasks are sorted
|
||||
* in such a way that a task can only depend upon earlier tasks (i.e. dependencies always come
|
||||
* before dependents in the list of tasks).
|
||||
* To preserve this attribute, you need to ensure that entry-points will only depend on
|
||||
* entry-points with a lower index. Take this into account when defining `entryPointDeps`.
|
||||
|
|
|
@ -37,7 +37,9 @@ describe('SingleProcessExecutor', () => {
|
|||
const oneTask = () => {
|
||||
let tasksCount = 1;
|
||||
return <TaskQueue>{
|
||||
get allTasksCompleted() { return tasksCount === 0; },
|
||||
get allTasksCompleted() {
|
||||
return tasksCount === 0;
|
||||
},
|
||||
getNextTask() {
|
||||
tasksCount--;
|
||||
return {};
|
||||
|
@ -55,7 +57,9 @@ describe('SingleProcessExecutor', () => {
|
|||
});
|
||||
|
||||
it('should call LockFile.write() and LockFile.remove() if `analyzeEntryPoints` fails', () => {
|
||||
const errorFn: () => never = () => { throw new Error('analyze error'); };
|
||||
const errorFn: () => never = () => {
|
||||
throw new Error('analyze error');
|
||||
};
|
||||
const createCompileFn: () => any = () => undefined;
|
||||
let error: string = '';
|
||||
try {
|
||||
|
@ -68,7 +72,9 @@ describe('SingleProcessExecutor', () => {
|
|||
});
|
||||
|
||||
it('should call LockFile.write() and LockFile.remove() if `createCompileFn` fails', () => {
|
||||
const createErrorCompileFn: () => any = () => { throw new Error('compile error'); };
|
||||
const createErrorCompileFn: () => any = () => {
|
||||
throw new Error('compile error');
|
||||
};
|
||||
let error: string = '';
|
||||
try {
|
||||
executor.execute(oneTask, createErrorCompileFn);
|
||||
|
@ -85,7 +91,9 @@ describe('SingleProcessExecutor', () => {
|
|||
throw new Error('LockFile.write() error');
|
||||
});
|
||||
|
||||
const analyzeFn: () => any = () => { lockFileLog.push('analyzeFn'); };
|
||||
const analyzeFn: () => any = () => {
|
||||
lockFileLog.push('analyzeFn');
|
||||
};
|
||||
const anyFn: () => any = () => undefined;
|
||||
executor = new SingleProcessExecutorSync(mockLogger, locker, createTaskCompletedCallback);
|
||||
let error = '';
|
||||
|
|
|
@ -30,10 +30,8 @@ describe('SerialTaskQueue', () => {
|
|||
const tasks: PartiallyOrderedTasks = [] as any;
|
||||
const graph = new DepGraph<EntryPoint>();
|
||||
for (let i = 0; i < taskCount; i++) {
|
||||
const entryPoint = {
|
||||
name: `entry-point-${i}`,
|
||||
path: `/path/to/entry/point/${i}`
|
||||
} as EntryPoint;
|
||||
const entryPoint = {name: `entry-point-${i}`, path: `/path/to/entry/point/${i}`} as
|
||||
EntryPoint;
|
||||
tasks.push(
|
||||
{entryPoint: entryPoint, formatProperty: `prop-${i}`, processDts: i % 2 === 0} as Task);
|
||||
graph.addNode(entryPoint.path);
|
||||
|
|
|
@ -15,10 +15,14 @@ export class MockLockFile implements LockFile {
|
|||
constructor(
|
||||
fs: FileSystem, private log: string[] = [], public path = fs.resolve('/lockfile'),
|
||||
private pid = '1234') {}
|
||||
write() { this.log.push('write()'); }
|
||||
write() {
|
||||
this.log.push('write()');
|
||||
}
|
||||
read(): string {
|
||||
this.log.push('read()');
|
||||
return this.pid;
|
||||
}
|
||||
remove() { this.log.push('remove()'); }
|
||||
remove() {
|
||||
this.log.push('remove()');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {LogLevel, Logger} from '../../src/logging/logger';
|
||||
import {Logger, LogLevel} from '../../src/logging/logger';
|
||||
|
||||
export class MockLogger implements Logger {
|
||||
constructor(public level = LogLevel.info) {}
|
||||
|
@ -17,8 +17,16 @@ export class MockLogger implements Logger {
|
|||
warn: [],
|
||||
error: [],
|
||||
};
|
||||
debug(...args: string[]) { this.logs.debug.push(args); }
|
||||
info(...args: string[]) { this.logs.info.push(args); }
|
||||
warn(...args: string[]) { this.logs.warn.push(args); }
|
||||
error(...args: string[]) { this.logs.error.push(args); }
|
||||
debug(...args: string[]) {
|
||||
this.logs.debug.push(args);
|
||||
}
|
||||
info(...args: string[]) {
|
||||
this.logs.info.push(args);
|
||||
}
|
||||
warn(...args: string[]) {
|
||||
this.logs.warn.push(args);
|
||||
}
|
||||
error(...args: string[]) {
|
||||
this.logs.error.push(args);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, getFileSystem, NgtscCompilerHost} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {BundleProgram, makeBundleProgram} from '../../src/packages/bundle_program';
|
||||
import {NgccEntryPointConfig} from '../../src/packages/configuration';
|
||||
|
@ -49,7 +49,12 @@ export function makeTestEntryPointBundle(
|
|||
return {
|
||||
entryPoint,
|
||||
format,
|
||||
rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore, enableI18nLegacyMessageIdFormat
|
||||
rootDirs: [absoluteFrom('/')],
|
||||
src,
|
||||
dts,
|
||||
isCore,
|
||||
isFlatCore,
|
||||
enableI18nLegacyMessageIdFormat
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles, loadTsLib} from '../../../test/helpers';
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles, loadTsLib} from '../../../test/helpers';
|
||||
|
@ -239,7 +239,6 @@ export { AliasedDirective$1 };
|
|||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('should find the decorators on a minified class', () => {
|
||||
|
@ -260,7 +259,6 @@ export { AliasedDirective$1 };
|
|||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('should find the decorators on an aliased class', () => {
|
||||
|
@ -333,8 +331,7 @@ export { AliasedDirective$1 };
|
|||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_minified_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const innerNode =
|
||||
getIifeBody(classNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||
const innerNode = getIifeBody(classNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
const classSymbol = host.getClassSymbol(classNode);
|
||||
|
||||
expect(classSymbol).toBeDefined();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
|
|
|
@ -14,8 +14,7 @@ import {CtorParameter} from '../../../src/ngtsc/reflection';
|
|||
* names.
|
||||
*/
|
||||
export function expectTypeValueReferencesForParameters(
|
||||
parameters: CtorParameter[], expectedParams: (string | null)[],
|
||||
fromModule: string | null = null) {
|
||||
parameters: CtorParameter[], expectedParams: (string|null)[], fromModule: string|null = null) {
|
||||
parameters!.forEach((param, idx) => {
|
||||
const expected = expectedParams[idx];
|
||||
if (expected !== null) {
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
/// <reference types="node" />
|
||||
import * as os from 'os';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, join} from '../../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem, TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, join} from '../../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem, runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadStandardTestFiles, loadTestFiles} from '../../../test/helpers';
|
||||
import {getLockFilePath} from '../../src/locking/lock_file';
|
||||
import {mainNgcc} from '../../src/main';
|
||||
|
@ -19,6 +20,7 @@ import {EntryPointManifestFile} from '../../src/packages/entry_point_manifest';
|
|||
import {Transformer} from '../../src/packages/transformer';
|
||||
import {DirectPackageJsonUpdater, PackageJsonUpdater} from '../../src/writing/package_json_updater';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
import {compileIntoApf, compileIntoFlatEs5Package} from './util';
|
||||
|
||||
const testFiles = loadStandardTestFiles({fakeCore: false, rxjs: true});
|
||||
|
@ -145,7 +147,8 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
['esm5', 'esm2015'].forEach(target => {
|
||||
it(`should be able to process spread operator inside objects for ${target} format (imported helpers)`,
|
||||
it(`should be able to process spread operator inside objects for ${
|
||||
target} format (imported helpers)`,
|
||||
() => {
|
||||
compileIntoApf(
|
||||
'test-package', {
|
||||
|
@ -184,7 +187,8 @@ runInEachFileSystem(() => {
|
|||
expect(jsContents).toContain('ngcc0.ɵɵclassProp("a", true)("b", true)("c", false)');
|
||||
});
|
||||
|
||||
it(`should be able to process emitted spread operator inside objects for ${target} format (emitted helpers)`,
|
||||
it(`should be able to process emitted spread operator inside objects for ${
|
||||
target} format (emitted helpers)`,
|
||||
() => {
|
||||
compileIntoApf(
|
||||
'test-package', {
|
||||
|
@ -651,7 +655,8 @@ runInEachFileSystem(() => {
|
|||
markPropertiesAsProcessed('@angular/common/http/testing', SUPPORTED_FORMAT_PROPERTIES);
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing', logger,
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.debug).toContain([
|
||||
'The target entry-point has already been processed'
|
||||
|
@ -665,7 +670,8 @@ runInEachFileSystem(() => {
|
|||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
propertiesToConsider: ['fesm2015', 'esm5', 'esm2015'], logger,
|
||||
propertiesToConsider: ['fesm2015', 'esm5', 'esm2015'],
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.debug).not.toContain([
|
||||
'The target entry-point has already been processed'
|
||||
|
@ -682,7 +688,8 @@ runInEachFileSystem(() => {
|
|||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
propertiesToConsider: ['esm5', 'esm2015'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).not.toContain([
|
||||
|
@ -699,7 +706,8 @@ runInEachFileSystem(() => {
|
|||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
// Simulate a property that does not exist on the package.json and will be ignored.
|
||||
propertiesToConsider: ['missing', 'esm2015', 'esm5'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).toContain([
|
||||
|
@ -717,7 +725,8 @@ runInEachFileSystem(() => {
|
|||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
// Simulate a property that does not exist on the package.json and will be ignored.
|
||||
propertiesToConsider: ['missing', 'esm2015', 'esm5'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).toContain([
|
||||
|
@ -838,7 +847,8 @@ runInEachFileSystem(() => {
|
|||
// `fesm2015` and `es2015` map to the same file: `./fesm2015/common.js`
|
||||
mainNgcc({
|
||||
basePath: '/node_modules/@angular/common',
|
||||
propertiesToConsider: ['fesm2015'], logger,
|
||||
propertiesToConsider: ['fesm2015'],
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logs).not.toContain(['Skipping @angular/common : es2015 (already compiled).']);
|
||||
|
@ -851,7 +861,8 @@ runInEachFileSystem(() => {
|
|||
// Now, compiling `es2015` should be a no-op.
|
||||
mainNgcc({
|
||||
basePath: '/node_modules/@angular/common',
|
||||
propertiesToConsider: ['es2015'], logger,
|
||||
propertiesToConsider: ['es2015'],
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logs).toContain(['Skipping @angular/common : es2015 (already compiled).']);
|
||||
|
@ -1034,7 +1045,8 @@ runInEachFileSystem(() => {
|
|||
expect(obj.hasOwnProperty(prop))
|
||||
.toBe(
|
||||
false,
|
||||
`Expected object not to have property '${prop}': ${JSON.stringify(obj, null, 2)}`);
|
||||
`Expected object not to have property '${prop}': ${
|
||||
JSON.stringify(obj, null, 2)}`);
|
||||
}
|
||||
|
||||
function expectToHaveProp(obj: object, prop: string) {
|
||||
|
@ -1053,7 +1065,9 @@ runInEachFileSystem(() => {
|
|||
return loadPackage('@angular/core');
|
||||
}
|
||||
|
||||
function stringifyKeys(obj: object) { return `|${Object.keys(obj).join('|')}|`; }
|
||||
function stringifyKeys(obj: object) {
|
||||
return `|${Object.keys(obj).join('|')}|`;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1206,7 +1220,8 @@ runInEachFileSystem(() => {
|
|||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['es2015'],
|
||||
errorOnFailedEntryPoint: false, logger,
|
||||
errorOnFailedEntryPoint: false,
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.error.length).toEqual(1);
|
||||
const message = logger.logs.error[0][0];
|
||||
|
@ -1236,7 +1251,8 @@ runInEachFileSystem(() => {
|
|||
const logger = new MockLogger();
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['esm2015'], logger,
|
||||
propertiesToConsider: ['esm2015'],
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.info).toContain(['Compiling @angular/common/http : esm2015 as esm2015']);
|
||||
});
|
||||
|
@ -1281,7 +1297,8 @@ runInEachFileSystem(() => {
|
|||
mainNgcc({
|
||||
basePath: '/dist',
|
||||
propertiesToConsider: ['es2015'],
|
||||
tsConfigPath: _('/tsconfig.app.json'), logger
|
||||
tsConfigPath: _('/tsconfig.app.json'),
|
||||
logger
|
||||
});
|
||||
expect(loadPackage('local-package', _('/dist')).__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
|
@ -1316,7 +1333,8 @@ runInEachFileSystem(() => {
|
|||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['es2015'],
|
||||
pathMappings: {paths: {'*': ['dist/*']}, baseUrl: '/'}, logger
|
||||
pathMappings: {paths: {'*': ['dist/*']}, baseUrl: '/'},
|
||||
logger
|
||||
});
|
||||
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
|
@ -1356,7 +1374,8 @@ runInEachFileSystem(() => {
|
|||
mainNgcc({
|
||||
basePath: '/dist',
|
||||
propertiesToConsider: ['es2015'],
|
||||
tsConfigPath: null, logger,
|
||||
tsConfigPath: null,
|
||||
logger,
|
||||
});
|
||||
expect(loadPackage('local-package', _('/dist')).__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
|
|
|
@ -234,11 +234,21 @@ class MockCompilerHost implements ts.CompilerHost {
|
|||
this.fs.writeFile(this.fs.resolve(fileName), data);
|
||||
}
|
||||
|
||||
getCurrentDirectory(): string { return this.fs.pwd(); }
|
||||
getCanonicalFileName(fileName: string): string { return fileName; }
|
||||
useCaseSensitiveFileNames(): boolean { return true; }
|
||||
getNewLine(): string { return '\n'; }
|
||||
fileExists(fileName: string): boolean { return this.fs.exists(this.fs.resolve(fileName)); }
|
||||
getCurrentDirectory(): string {
|
||||
return this.fs.pwd();
|
||||
}
|
||||
getCanonicalFileName(fileName: string): string {
|
||||
return fileName;
|
||||
}
|
||||
useCaseSensitiveFileNames(): boolean {
|
||||
return true;
|
||||
}
|
||||
getNewLine(): string {
|
||||
return '\n';
|
||||
}
|
||||
fileExists(fileName: string): boolean {
|
||||
return this.fs.exists(this.fs.resolve(fileName));
|
||||
}
|
||||
readFile(fileName: string): string|undefined {
|
||||
const abs = this.fs.resolve(fileName);
|
||||
return this.fs.exists(abs) ? this.fs.readFile(abs) : undefined;
|
||||
|
|
|
@ -162,7 +162,8 @@ runInEachFileSystem(() => {
|
|||
expect(error!.message)
|
||||
.toEqual(
|
||||
`Timed out waiting 0.2s for another ngcc process, with id 188, to complete.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${lockFile.path}.)`);
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${
|
||||
lockFile.path}.)`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -47,7 +47,11 @@ runInEachFileSystem(() => {
|
|||
const log = this.log;
|
||||
// Normally this would fork a child process and return it.
|
||||
// But we don't want to do that in these tests.
|
||||
return <any>{disconnect() { log.push('unlocker.disconnect()'); }};
|
||||
return <any>{
|
||||
disconnect() {
|
||||
log.push('unlocker.disconnect()');
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 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 {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem} from '../../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../../src/ngtsc/file_system/testing';
|
||||
import {removeLockFile} from '../../../src/locking/lock_file_with_child_process/util';
|
||||
import {MockLogger} from '../../helpers/mock_logger';
|
||||
|
@ -24,8 +24,9 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
describe('removeLockFile()', () => {
|
||||
it('should do nothing if there is no file to remove',
|
||||
() => { removeLockFile(fs, logger, absoluteFrom('/lockfile/path'), '1234'); });
|
||||
it('should do nothing if there is no file to remove', () => {
|
||||
removeLockFile(fs, logger, absoluteFrom('/lockfile/path'), '1234');
|
||||
});
|
||||
|
||||
it('should do nothing if the pid does not match', () => {
|
||||
fs.writeFile(lockFilePath, '888');
|
||||
|
|
|
@ -50,7 +50,9 @@ runInEachFileSystem(() => {
|
|||
const lockFile = new MockLockFile(fs, log);
|
||||
const locker = new SyncLocker(lockFile);
|
||||
|
||||
spyOn(lockFile, 'write').and.callFake(() => { throw {code: 'EEXIST'}; });
|
||||
spyOn(lockFile, 'write').and.callFake(() => {
|
||||
throw {code: 'EEXIST'};
|
||||
});
|
||||
spyOn(lockFile, 'read').and.returnValue('188');
|
||||
|
||||
expect(() => locker.lock(() => {}))
|
||||
|
@ -58,7 +60,8 @@ runInEachFileSystem(() => {
|
|||
`ngcc is already running at process with id 188.\n` +
|
||||
`If you are running multiple builds in parallel then you should pre-process your node_modules via the command line ngcc tool before starting the builds;\n` +
|
||||
`See https://v9.angular.io/guide/ivy#speeding-up-ngcc-compilation.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${lockFile.path}.)`);
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${
|
||||
lockFile.path}.)`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {DecorationAnalyses} from '../../src/analysis/types';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {MissingInjectableMigration, getAngularCoreDecoratorName} from '../../src/migrations/missing_injectable_migration';
|
||||
import {getAngularCoreDecoratorName, MissingInjectableMigration} from '../../src/migrations/missing_injectable_migration';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
|
@ -121,7 +121,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: forwardRef(() => MyService) }]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: forwardRef(() => MyService) }]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
@ -140,7 +141,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: MyService, useValue: null }]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: MyService, useValue: null }]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
@ -159,7 +161,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: MyService, useFactory: () => null }]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: MyService, useFactory: () => null }]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
@ -206,7 +209,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: MyToken, useClass: MyService}]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: MyToken, useClass: MyService}]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NGCC_VERSION, cleanPackageJson, hasBeenProcessed, markAsProcessed, needsCleaning} from '../../src/packages/build_marker';
|
||||
import {cleanPackageJson, hasBeenProcessed, markAsProcessed, needsCleaning, NGCC_VERSION} from '../../src/packages/build_marker';
|
||||
import {EntryPointPackageJson} from '../../src/packages/entry_point';
|
||||
import {DirectPackageJsonUpdater} from '../../src/writing/package_json_updater';
|
||||
|
||||
|
@ -192,8 +192,9 @@ runInEachFileSystem(() => {
|
|||
.toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if no markers exist',
|
||||
() => { expect(hasBeenProcessed({name: 'test'}, 'module')).toBe(false); });
|
||||
it('should return false if no markers exist', () => {
|
||||
expect(hasBeenProcessed({name: 'test'}, 'module')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('needsCleaning()', () => {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
import {createHash} from 'crypto';
|
||||
|
||||
import {FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DEFAULT_NGCC_CONFIG, NgccConfiguration} from '../../src/packages/configuration';
|
||||
|
@ -27,8 +27,8 @@ runInEachFileSystem(() => {
|
|||
it('should error if a project level config file is badly formatted', () => {
|
||||
loadTestFiles([{name: _Abs('/project-1/ngcc.config.js'), contents: `bad js code`}]);
|
||||
expect(() => new NgccConfiguration(fs, _Abs('/project-1')))
|
||||
.toThrowError(
|
||||
`Invalid project configuration file at "${_Abs('/project-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
.toThrowError(`Invalid project configuration file at "${
|
||||
_Abs('/project-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,8 +50,8 @@ runInEachFileSystem(() => {
|
|||
};`
|
||||
}]);
|
||||
const project1Conf = new NgccConfiguration(fs, project1);
|
||||
const expectedProject1Config =
|
||||
`{"packages":{"${project1Package1}":[{"entryPoints":{"${project1Package1EntryPoint1}":{}},"versionRange":"*"}]}}`;
|
||||
const expectedProject1Config = `{"packages":{"${project1Package1}":[{"entryPoints":{"${
|
||||
project1Package1EntryPoint1}":{}},"versionRange":"*"}]}}`;
|
||||
expect(project1Conf.hash)
|
||||
.toEqual(createHash('md5').update(expectedProject1Config).digest('hex'));
|
||||
|
||||
|
@ -71,8 +71,8 @@ runInEachFileSystem(() => {
|
|||
};`
|
||||
}]);
|
||||
const project2Conf = new NgccConfiguration(fs, project2);
|
||||
const expectedProject2Config =
|
||||
`{"packages":{"${project2Package1}":[{"entryPoints":{"${project2Package1EntryPoint1}":{"ignore":true}},"versionRange":"*"}]}}`;
|
||||
const expectedProject2Config = `{"packages":{"${project2Package1}":[{"entryPoints":{"${
|
||||
project2Package1EntryPoint1}":{"ignore":true}},"versionRange":"*"}]}}`;
|
||||
expect(project2Conf.hash)
|
||||
.toEqual(createHash('md5').update(expectedProject2Config).digest('hex'));
|
||||
});
|
||||
|
@ -136,8 +136,9 @@ runInEachFileSystem(() => {
|
|||
}]);
|
||||
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
|
||||
expect(() => configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0'))
|
||||
.toThrowError(
|
||||
`Invalid package configuration file at "${_Abs('/project-1/node_modules/package-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
.toThrowError(`Invalid package configuration file at "${
|
||||
_Abs(
|
||||
'/project-1/node_modules/package-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -343,7 +344,6 @@ runInEachFileSystem(() => {
|
|||
versionRange: '*',
|
||||
entryPoints: {[_Abs('/project-1/node_modules/@angular/common')]: {}}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should override package level config with project level config per package', () => {
|
||||
|
@ -412,8 +412,7 @@ runInEachFileSystem(() => {
|
|||
configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0');
|
||||
expect(config).toEqual({
|
||||
versionRange: '*',
|
||||
entryPoints:
|
||||
{[_Abs('/project-1/node_modules/package-1/default-level-entry-point')]: {}}
|
||||
entryPoints: {[_Abs('/project-1/node_modules/package-1/default-level-entry-point')]: {}}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -427,8 +426,7 @@ runInEachFileSystem(() => {
|
|||
// merge entry-points.
|
||||
expect(config).toEqual({
|
||||
versionRange: '1.0.0',
|
||||
entryPoints:
|
||||
{[_Abs('/project-1/node_modules/package-1/package-level-entry-point')]: {}}
|
||||
entryPoints: {[_Abs('/project-1/node_modules/package-1/package-level-entry-point')]: {}}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -465,8 +463,7 @@ runInEachFileSystem(() => {
|
|||
// merge entry-points.
|
||||
expect(config).toEqual({
|
||||
versionRange: '*',
|
||||
entryPoints:
|
||||
{[_Abs('/project-1/node_modules/package-1/project-level-entry-point')]: {}}
|
||||
entryPoints: {[_Abs('/project-1/node_modules/package-1/project-level-entry-point')]: {}}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import {makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
|||
|
||||
runInEachFileSystem(() => {
|
||||
describe('entry point bundle', () => {
|
||||
|
||||
function setupMockFileSystem(): void {
|
||||
const _ = absoluteFrom;
|
||||
loadTestFiles([
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
import {createHash} from 'crypto';
|
||||
|
||||
import {FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NGCC_VERSION} from '../../src/packages/build_marker';
|
||||
|
@ -135,12 +135,14 @@ runInEachFileSystem(() => {
|
|||
_Abs('/project/node_modules/__ngcc_entry_points__.json'), JSON.stringify(manifestFile));
|
||||
const entryPoints = manifest.readEntryPointsUsingManifest(_Abs('/project/node_modules'));
|
||||
expect(entryPoints).toEqual([{
|
||||
name: 'some_package/valid_entry_point', packageJson: jasmine.any(Object),
|
||||
name: 'some_package/valid_entry_point',
|
||||
packageJson: jasmine.any(Object),
|
||||
package: _Abs('/project/node_modules/some_package'),
|
||||
path: _Abs('/project/node_modules/some_package/valid_entry_point'),
|
||||
typings: _Abs(
|
||||
'/project/node_modules/some_package/valid_entry_point/valid_entry_point.d.ts'),
|
||||
compiledByAngular: true, ignoreMissingDependencies: false,
|
||||
typings:
|
||||
_Abs('/project/node_modules/some_package/valid_entry_point/valid_entry_point.d.ts'),
|
||||
compiledByAngular: true,
|
||||
ignoreMissingDependencies: false,
|
||||
generateDeepReexports: false,
|
||||
} as any]);
|
||||
});
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||
import {EntryPoint, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat, getEntryPointInfo} from '../../src/packages/entry_point';
|
||||
import {EntryPoint, getEntryPointFormat, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, SUPPORTED_FORMAT_PROPERTIES} from '../../src/packages/entry_point';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
@ -69,8 +69,7 @@ runInEachFileSystem(() => {
|
|||
]);
|
||||
const config = new NgccConfiguration(fs, _('/project'));
|
||||
spyOn(config, 'getConfig').and.returnValue({
|
||||
entryPoints:
|
||||
{[_('/project/node_modules/some_package/valid_entry_point')]: {ignore: true}}
|
||||
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {ignore: true}}
|
||||
});
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
|
@ -103,7 +102,8 @@ runInEachFileSystem(() => {
|
|||
_('/project/node_modules/some_package/valid_entry_point'));
|
||||
const overriddenPackageJson = {
|
||||
...loadPackageJson(fs, '/project/node_modules/some_package/valid_entry_point'),
|
||||
...override};
|
||||
...override
|
||||
};
|
||||
expect(entryPoint).toEqual({
|
||||
name: 'some_package/valid_entry_point',
|
||||
package: SOME_PACKAGE,
|
||||
|
@ -145,8 +145,7 @@ runInEachFileSystem(() => {
|
|||
const override =
|
||||
JSON.parse(createPackageJson('missing_package_json', {excludes: ['name']}));
|
||||
spyOn(config, 'getConfig').and.returnValue({
|
||||
entryPoints:
|
||||
{[_('/project/node_modules/some_package/missing_package_json')]: {override}}
|
||||
entryPoints: {[_('/project/node_modules/some_package/missing_package_json')]: {override}}
|
||||
});
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
|
@ -211,15 +210,16 @@ runInEachFileSystem(() => {
|
|||
// Let's give 'module' a specific path, otherwise compute it based on the property.
|
||||
const typingsPath = prop === 'module' ? 'index' : `${prop}/missing_typings`;
|
||||
|
||||
it(`should return an object if it can guess the typings path from the "${prop}" field`, () => {
|
||||
it(`should return an object if it can guess the typings path from the "${prop}" field`,
|
||||
() => {
|
||||
loadTestFiles([
|
||||
{
|
||||
name: _('/project/node_modules/some_package/missing_typings/package.json'),
|
||||
contents: createPackageJson('missing_typings', {excludes: ['typings']}),
|
||||
},
|
||||
{
|
||||
name: _(
|
||||
`/project/node_modules/some_package/missing_typings/${typingsPath}.metadata.json`),
|
||||
name: _(`/project/node_modules/some_package/missing_typings/${
|
||||
typingsPath}.metadata.json`),
|
||||
contents: 'some meta data',
|
||||
},
|
||||
{
|
||||
|
@ -401,23 +401,29 @@ runInEachFileSystem(() => {
|
|||
entryPoint = result;
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `fesm2015` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'fesm2015')).toBe('esm2015'); });
|
||||
it('should return `esm2015` format for `fesm2015` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'fesm2015')).toBe('esm2015');
|
||||
});
|
||||
|
||||
it('should return `esm5` format for `fesm5` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'fesm5')).toBe('esm5'); });
|
||||
it('should return `esm5` format for `fesm5` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'fesm5')).toBe('esm5');
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `es2015` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'es2015')).toBe('esm2015'); });
|
||||
it('should return `esm2015` format for `es2015` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'es2015')).toBe('esm2015');
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `esm2015` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'esm2015')).toBe('esm2015'); });
|
||||
it('should return `esm2015` format for `esm2015` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'esm2015')).toBe('esm2015');
|
||||
});
|
||||
|
||||
it('should return `esm5` format for `esm5` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'esm5')).toBe('esm5'); });
|
||||
it('should return `esm5` format for `esm5` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'esm5')).toBe('esm5');
|
||||
});
|
||||
|
||||
it('should return `esm5` format for `module` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'module')).toBe('esm5'); });
|
||||
it('should return `esm5` format for `module` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'module')).toBe('esm5');
|
||||
});
|
||||
|
||||
it('should return `umd` for `main` if the file contains a UMD wrapper function', () => {
|
||||
loadTestFiles([{
|
||||
|
|
|
@ -8,19 +8,20 @@
|
|||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, AbsoluteFsPath, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {AbsoluteFsPath, getFileSystem, getSourceFileOrError, absoluteFrom, absoluteFromSourceFile} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {CommonJsReflectionHost} from '../../src/host/commonjs_host';
|
||||
import {CommonJsRenderingFormatter} from '../../src/rendering/commonjs_rendering_formatter';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('CommonJsRenderingFormatter', () => {
|
||||
|
@ -314,15 +315,16 @@ SOME DEFINITION TEXT
|
|||
program, absoluteFromSourceFile(sourceFile), 'NoIife', ts.isFunctionDeclaration);
|
||||
const mockNoIifeClass: any = {declaration: noIifeDeclaration, name: 'NoIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockNoIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class declaration is not inside an IIFE: NoIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
.toThrowError(`Compiled class declaration is not inside an IIFE: NoIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
|
||||
const badIifeDeclaration = getDeclaration(
|
||||
program, absoluteFromSourceFile(sourceFile), 'BadIife', ts.isVariableDeclaration);
|
||||
const mockBadIifeClass: any = {declaration: badIifeDeclaration, name: 'BadIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockBadIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -377,7 +379,6 @@ SOME DEFINITION TEXT
|
|||
});
|
||||
|
||||
describe('removeDecorators', () => {
|
||||
|
||||
it('should delete the decorator (and following comma) that was matched in the analysis',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
|
@ -441,7 +442,6 @@ SOME DEFINITION TEXT
|
|||
.toContain(`function C() {}\nSOME DEFINITION TEXT\n return C;`);
|
||||
expect(output.toString()).not.toContain(`C.decorators`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('[__decorate declarations]', () => {
|
||||
|
|
|
@ -7,21 +7,22 @@
|
|||
*/
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {Import, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ModuleWithProvidersAnalyzer, ModuleWithProvidersInfo} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {PrivateDeclarationsAnalyzer, ExportInfo} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ExportInfo, PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {RenderingFormatter, RedundantDecoratorMap} from '../../src/rendering/rendering_formatter';
|
||||
import {DtsRenderer} from '../../src/rendering/dts_renderer';
|
||||
import {RedundantDecoratorMap, RenderingFormatter} from '../../src/rendering/rendering_formatter';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle, getRootFiles} from '../helpers/utils';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
class TestRenderingFormatter implements RenderingFormatter {
|
||||
addImports(output: MagicString, imports: Import[], sf: ts.SourceFile) {
|
||||
|
@ -53,7 +54,9 @@ class TestRenderingFormatter implements RenderingFormatter {
|
|||
importManager: ImportManager): void {
|
||||
output.prepend('\n// ADD MODUlE WITH PROVIDERS PARAMS\n');
|
||||
}
|
||||
printStatement(): string { return 'IGNORED'; }
|
||||
printStatement(): string {
|
||||
return 'IGNORED';
|
||||
}
|
||||
}
|
||||
|
||||
function createTestRenderer(
|
||||
|
@ -92,12 +95,14 @@ function createTestRenderer(
|
|||
|
||||
const renderer = new DtsRenderer(testFormatter, fs, logger, host, bundle);
|
||||
|
||||
return {renderer,
|
||||
return {
|
||||
renderer,
|
||||
testFormatter,
|
||||
decorationAnalyses,
|
||||
moduleWithProvidersAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
bundle};
|
||||
bundle
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
@ -120,9 +125,12 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
it('should render extract types into typings files', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
||||
|
@ -134,9 +142,12 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
it('should render imports into typings files', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
||||
|
@ -146,9 +157,12 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
it('should render exports into typings files', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
|
||||
// Add a mock export to trigger export rendering
|
||||
privateDeclarationsAnalyses.push({
|
||||
|
@ -166,9 +180,12 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
|
||||
it('should render ModuleWithProviders type params', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
|
|
@ -8,20 +8,21 @@
|
|||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, AbsoluteFsPath, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {AbsoluteFsPath, absoluteFrom, absoluteFromSourceFile, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {IMPORT_PREFIX} from '../../src/constants';
|
||||
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
||||
import {Esm5RenderingFormatter} from '../../src/rendering/esm5_rendering_formatter';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
function setup(file: {name: AbsoluteFsPath, contents: string}) {
|
||||
loadTestFiles([file]);
|
||||
|
@ -39,13 +40,16 @@ function setup(file: {name: AbsoluteFsPath, contents: string}) {
|
|||
return {
|
||||
host,
|
||||
program: bundle.src.program,
|
||||
sourceFile: bundle.src.file, renderer, decorationAnalyses, switchMarkerAnalyses, importManager
|
||||
sourceFile: bundle.src.file,
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
importManager
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('Esm5RenderingFormatter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let PROGRAM: TestFile;
|
||||
let PROGRAM_DECORATE_HELPER: TestFile;
|
||||
|
@ -317,15 +321,16 @@ SOME DEFINITION TEXT
|
|||
program, absoluteFromSourceFile(sourceFile), 'NoIife', ts.isFunctionDeclaration);
|
||||
const mockNoIifeClass: any = {declaration: noIifeDeclaration, name: 'NoIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockNoIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class declaration is not inside an IIFE: NoIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
.toThrowError(`Compiled class declaration is not inside an IIFE: NoIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
|
||||
const badIifeDeclaration = getDeclaration(
|
||||
program, absoluteFromSourceFile(sourceFile), 'BadIife', ts.isVariableDeclaration);
|
||||
const mockBadIifeClass: any = {declaration: badIifeDeclaration, name: 'BadIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockBadIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -381,7 +386,6 @@ SOME DEFINITION TEXT
|
|||
|
||||
|
||||
describe('removeDecorators', () => {
|
||||
|
||||
it('should delete the decorator (and following comma) that was matched in the analysis',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
|
|
|
@ -8,20 +8,21 @@
|
|||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {loadTestFiles, loadFakeCore} from '../../../test/helpers';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {IMPORT_PREFIX} from '../../src/constants';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {EsmRenderingFormatter} from '../../src/rendering/esm_rendering_formatter';
|
||||
import {makeTestEntryPointBundle, getRootFiles} from '../helpers/utils';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
function setup(files: TestFile[], dtsFiles?: TestFile[]) {
|
||||
const fs = getFileSystem();
|
||||
|
@ -45,13 +46,16 @@ function setup(files: TestFile[], dtsFiles?: TestFile[]) {
|
|||
host,
|
||||
bundle,
|
||||
program: bundle.src.program,
|
||||
sourceFile: bundle.src.file, renderer, decorationAnalyses, switchMarkerAnalyses, importManager,
|
||||
sourceFile: bundle.src.file,
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
importManager,
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('EsmRenderingFormatter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let PROGRAM: TestFile;
|
||||
|
||||
|
|
|
@ -6,27 +6,28 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {Statement} from '@angular/compiler';
|
||||
import {SourceMapMappings, encode} from 'sourcemap-codec';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {fromObject, generateMapFileComment, SourceMapConverter} from 'convert-source-map';
|
||||
import MagicString from 'magic-string';
|
||||
import {encode, SourceMapMappings} from 'sourcemap-codec';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NOOP_DEFAULT_IMPORT_RECORDER, Reexport} from '../../../src/ngtsc/imports';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {Import, ImportManager, translateStatement} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ModuleWithProvidersInfo} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {PrivateDeclarationsAnalyzer, ExportInfo} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ExportInfo, PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
||||
import {Renderer} from '../../src/rendering/renderer';
|
||||
import {RedundantDecoratorMap, RenderingFormatter} from '../../src/rendering/rendering_formatter';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {RenderingFormatter, RedundantDecoratorMap} from '../../src/rendering/rendering_formatter';
|
||||
import {makeTestEntryPointBundle, getRootFiles} from '../helpers/utils';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
class TestRenderingFormatter implements RenderingFormatter {
|
||||
private printer = ts.createPrinter({newLine: ts.NewLineKind.LineFeed});
|
||||
|
@ -106,12 +107,14 @@ function createTestRenderer(
|
|||
|
||||
const renderer = new Renderer(host, testFormatter, fs, logger, bundle);
|
||||
|
||||
return {renderer,
|
||||
return {
|
||||
renderer,
|
||||
testFormatter,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
bundle};
|
||||
bundle
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
@ -227,8 +230,13 @@ runInEachFileSystem(() => {
|
|||
|
||||
|
||||
it('should render as JavaScript', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [COMPONENT_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [COMPONENT_PROGRAM]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
|
@ -253,8 +261,13 @@ A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, v
|
|||
describe('calling RenderingFormatter methods', () => {
|
||||
it('should call addImports with the source code and info about the core Angular library.',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addImportsSpy = testFormatter.addImports as jasmine.Spy;
|
||||
|
@ -266,8 +279,13 @@ A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, v
|
|||
|
||||
it('should call addDefinitions with the source code, the analyzed class and the rendered definitions.',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
|
@ -284,8 +302,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
|
||||
it('should call addAdjacentStatements with the source code, the analyzed class and the rendered statements',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
|
@ -303,8 +326,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
|
||||
it('should call removeDecorators with the source code, a map of class decorators that have been analyzed',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const removeDecoratorsSpy = testFormatter.removeDecorators as jasmine.Spy;
|
||||
|
@ -326,8 +354,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render definitions as static fields', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
|
@ -337,8 +370,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render adjacent statements', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
|
@ -347,8 +385,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render directives using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
|
@ -379,8 +422,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render injectables using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
|
@ -411,8 +459,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render ng-modules using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
|
@ -448,8 +501,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render pipes using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
|
@ -479,9 +537,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
|||
});
|
||||
|
||||
it('should render classes without decorators if class fields are decorated', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
createTestRenderer('test-package', [{
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
contents: `
|
||||
import { Directive, ViewChild } from '@angular/core';
|
||||
|
@ -514,8 +576,13 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
|||
|
||||
it('should call renderImports after other abstract methods', () => {
|
||||
// This allows the other methods to add additional imports if necessary
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const addExportsSpy = testFormatter.addExports as jasmine.Spy;
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
|
@ -537,8 +604,12 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
|||
name: JS_CONTENT.name,
|
||||
contents: JS_CONTENT.contents + '\n' + JS_CONTENT_MAP.toComment()
|
||||
}];
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses} = createTestRenderer('test-package', sourceFiles);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses
|
||||
} = createTestRenderer('test-package', sourceFiles);
|
||||
const [sourceFile, mapFile] = renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js'));
|
||||
|
@ -555,9 +626,12 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
|||
}];
|
||||
const mappingFiles: TestFile[] =
|
||||
[{name: _(JS_CONTENT.name + '.map'), contents: JS_CONTENT_MAP.toJSON()}];
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses} =
|
||||
createTestRenderer('test-package', sourceFiles, undefined, mappingFiles);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses
|
||||
} = createTestRenderer('test-package', sourceFiles, undefined, mappingFiles);
|
||||
const [sourceFile, mapFile] = renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js'));
|
||||
|
@ -582,8 +656,13 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
|||
contents: `export const NgModule = () => null;`
|
||||
};
|
||||
// The package name of `@angular/core` indicates that we are compiling the core library.
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('@angular/core', [CORE_FILE, R3_SYMBOLS_FILE]);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('@angular/core', [CORE_FILE, R3_SYMBOLS_FILE]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
|
@ -602,8 +681,13 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
|||
export class MyModule {}\nMyModule.decorators = [\n { type: NgModule, args: [] }\n];\n`
|
||||
};
|
||||
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('@angular/core', [CORE_FILE]);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('@angular/core', [CORE_FILE]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
|
|
|
@ -8,16 +8,17 @@
|
|||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {UmdReflectionHost} from '../../src/host/umd_host';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {UmdRenderingFormatter} from '../../src/rendering/umd_rendering_formatter';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
@ -40,14 +41,15 @@ function setup(file: TestFile) {
|
|||
decorationAnalyses,
|
||||
host,
|
||||
importManager,
|
||||
program: src.program, renderer,
|
||||
sourceFile: src.file, switchMarkerAnalyses
|
||||
program: src.program,
|
||||
renderer,
|
||||
sourceFile: src.file,
|
||||
switchMarkerAnalyses
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('UmdRenderingFormatter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let PROGRAM: TestFile;
|
||||
let PROGRAM_DECORATE_HELPER: TestFile;
|
||||
|
@ -479,15 +481,16 @@ SOME DEFINITION TEXT
|
|||
program, absoluteFromSourceFile(sourceFile), 'NoIife', ts.isFunctionDeclaration);
|
||||
const mockNoIifeClass: any = {declaration: noIifeDeclaration, name: 'NoIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockNoIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class declaration is not inside an IIFE: NoIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
.toThrowError(`Compiled class declaration is not inside an IIFE: NoIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
|
||||
const badIifeDeclaration = getDeclaration(
|
||||
program, absoluteFromSourceFile(sourceFile), 'BadIife', ts.isVariableDeclaration);
|
||||
const mockBadIifeClass: any = {declaration: badIifeDeclaration, name: 'BadIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockBadIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -548,7 +551,6 @@ SOME DEFINITION TEXT
|
|||
});
|
||||
|
||||
describe('removeDecorators', () => {
|
||||
|
||||
it('should delete the decorator (and following comma) that was matched in the analysis',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
|
@ -610,7 +612,6 @@ SOME DEFINITION TEXT
|
|||
expect(output.toString()).toContain(`{ type: OtherB }`);
|
||||
expect(output.toString()).not.toContain(`C.decorators`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('[__decorate declarations]', () => {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 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 {FileSystem, absoluteFrom, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
import {fromObject} from 'convert-source-map';
|
||||
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
|
@ -75,7 +75,8 @@ runInEachFileSystem(() => {
|
|||
const encodedSourceMap = Buffer.from(JSON.stringify(sourceMap)).toString('base64');
|
||||
const sourceFile = registry.loadSourceFile(
|
||||
_('/foo/src/index.js'),
|
||||
`some inline content\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${encodedSourceMap}`);
|
||||
`some inline content\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${
|
||||
encodedSourceMap}`);
|
||||
if (sourceFile === null) {
|
||||
return fail('Expected source file to be defined');
|
||||
}
|
||||
|
@ -186,22 +187,25 @@ runInEachFileSystem(() => {
|
|||
|
||||
const aPath = _('/foo/src/a.js');
|
||||
fs.writeFile(
|
||||
aPath, 'a content\n' +
|
||||
aPath,
|
||||
'a content\n' +
|
||||
fromObject(createRawSourceMap({file: 'a.js', sources: ['b.js']})).toComment());
|
||||
|
||||
const bPath = _('/foo/src/b.js');
|
||||
fs.writeFile(
|
||||
bPath, 'b content\n' +
|
||||
bPath,
|
||||
'b content\n' +
|
||||
fromObject(createRawSourceMap({file: 'b.js', sources: ['c.js']})).toComment());
|
||||
|
||||
const cPath = _('/foo/src/c.js');
|
||||
fs.writeFile(
|
||||
cPath, 'c content\n' +
|
||||
cPath,
|
||||
'c content\n' +
|
||||
fromObject(createRawSourceMap({file: 'c.js', sources: ['a.js']})).toComment());
|
||||
|
||||
expect(() => registry.loadSourceFile(aPath))
|
||||
.toThrowError(
|
||||
`Circular source file mapping dependency: ${aPath} -> ${bPath} -> ${cPath} -> ${aPath}`);
|
||||
.toThrowError(`Circular source file mapping dependency: ${aPath} -> ${bPath} -> ${
|
||||
cPath} -> ${aPath}`);
|
||||
});
|
||||
|
||||
it('should not fail if there is a cyclic dependency in filenames of inline sources', () => {
|
||||
|
@ -209,7 +213,8 @@ runInEachFileSystem(() => {
|
|||
|
||||
const aPath = _('/foo/src/a.js');
|
||||
fs.writeFile(
|
||||
aPath, 'a content\n' +
|
||||
aPath,
|
||||
'a content\n' +
|
||||
fromObject(createRawSourceMap({file: 'a.js', sources: ['b.js']})).toComment());
|
||||
|
||||
const bPath = _('/foo/src/b.js');
|
||||
|
@ -238,6 +243,7 @@ function createRawSourceMap(custom: Partial<RawSourceMap>): RawSourceMap {
|
|||
'sources': [],
|
||||
'sourcesContent': [],
|
||||
'names': [],
|
||||
'mappings': '', ...custom
|
||||
'mappings': '',
|
||||
...custom
|
||||
};
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue