Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(ngcc): reformat of ngcc after clang update #36447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/compiler-cli/ngcc/index.ts
Expand Up @@ -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';

Expand Down
7 changes: 5 additions & 2 deletions packages/compiler-cli/ngcc/main-ngcc.ts
Expand Up @@ -125,7 +125,7 @@ if (require.main === module) {
// And we have to convert the option to a string to handle `no-tsconfig`, which will be `false`.
const tsConfigPath = `${options['tsconfig']}` === 'false' ? null : options['tsconfig'];

(async() => {
(async () => {
try {
const logger = logLevel && new ConsoleLogger(LogLevel[logLevel]);

Expand All @@ -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) {
Expand Down
28 changes: 18 additions & 10 deletions packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts
Expand Up @@ -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';
Expand All @@ -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';



Expand All @@ -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);
}
Expand All @@ -56,7 +60,7 @@ export class DecorationAnalyzer {
private rootDirs = this.bundle.rootDirs;
private packagePath = this.bundle.entryPoint.package;
private isCore = this.bundle.isCore;
private compilerOptions = this.tsConfig !== null? this.tsConfig.options: {};
private compilerOptions = this.tsConfig !== null ? this.tsConfig.options : {};

moduleResolver =
new ModuleResolver(this.program, this.options, this.host, /* moduleResolutionCache */ null);
Expand All @@ -73,8 +77,9 @@ export class DecorationAnalyzer {
// based on whether a bestGuessOwningModule is present in the Reference.
new LogicalProjectStrategy(this.reflectionHost, new LogicalFileSystem(this.rootDirs)),
]);
aliasingHost = this.bundle.entryPoint.generateDeepReexports?
new PrivateExportAliasingHost(this.reflectionHost): null;
aliasingHost = this.bundle.entryPoint.generateDeepReexports ?
new PrivateExportAliasingHost(this.reflectionHost) :
null;
dtsModuleScopeResolver =
new MetadataDtsModuleScopeResolver(this.dtsMetaReader, this.aliasingHost);
scopeRegistry = new LocalModuleScopeRegistry(
Expand Down Expand Up @@ -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();
Expand All @@ -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
});
}

Expand All @@ -224,7 +232,7 @@ export class DecorationAnalyzer {
if (!exportStatements.has(sf.fileName)) {
return [];
}
const exports = exportStatements.get(sf.fileName) !;
const exports = exportStatements.get(sf.fileName)!;

const reexports: Reexport[] = [];
exports.forEach(([fromModule, symbolName], asAlias) => {
Expand Down
Expand Up @@ -75,10 +75,9 @@ 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(
member => ts.isMethodDeclaration(member) && ts.isIdentifier(member.name) &&
member.name.text === fn.name) as ts.Declaration :
dtsClass.members.find(
member => ts.isMethodDeclaration(member) && ts.isIdentifier(member.name) &&
member.name.text === fn.name) as ts.Declaration :
null;
} else {
dtsFn = this.host.getDtsDeclaration(fn.declaration);
Expand All @@ -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;
}
Expand All @@ -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};
Expand Down
Expand Up @@ -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;
}
}
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,7 +49,7 @@ export class PrivateDeclarationsAnalyzer {
exports.forEach((declaration, exportedName) => {
if (declaration.node !== null && hasNameIdentifier(declaration.node)) {
if (privateDeclarations.has(declaration.node.name)) {
const privateDeclaration = privateDeclarations.get(declaration.node.name) !;
const privateDeclaration = privateDeclarations.get(declaration.node.name)!;
if (privateDeclaration.node !== declaration.node) {
throw new Error(`${declaration.node.name.text} is declared multiple times.`);
}
Expand All @@ -62,7 +63,7 @@ export class PrivateDeclarationsAnalyzer {

return Array.from(privateDeclarations.keys()).map(id => {
const from = absoluteFromSourceFile(id.getSourceFile());
const declaration = privateDeclarations.get(id) !;
const declaration = privateDeclarations.get(id)!;
const dtsDeclaration = this.host.getDtsDeclaration(declaration.node);
const dtsFrom = dtsDeclaration && absoluteFromSourceFile(dtsDeclaration.getSourceFile());

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/ngcc/src/analysis/util.ts
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}
}
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -222,7 +222,7 @@ export class ModuleResolver {
}

/** The result of resolving an import to a module. */
export type ResolvedModule = ResolvedExternalModule | ResolvedRelativeModule | ResolvedDeepImport;
export type ResolvedModule = ResolvedExternalModule|ResolvedRelativeModule|ResolvedDeepImport;

/**
* A module that is external to the package doing the importing.
Expand Down
Expand Up @@ -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);
}
}
Expand Up @@ -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';

Expand Down
Expand Up @@ -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';

Expand Down Expand Up @@ -76,7 +77,7 @@ export class TargetedEntryPointFinder implements EntryPointFinder {
}

private processNextPath(): void {
const path = this.unprocessedPaths.shift() !;
const path = this.unprocessedPaths.shift()!;
const entryPoint = this.getEntryPoint(path);
if (entryPoint === null || !entryPoint.compiledByAngular) {
return;
Expand Down Expand Up @@ -130,7 +131,7 @@ export class TargetedEntryPointFinder implements EntryPointFinder {
// Start the search at the deepest nested `node_modules` folder that is below the `basePath`
// but above the `entryPointPath`, if there are any.
while (nodeModulesIndex >= 0) {
packagePath = join(packagePath, segments.shift() !);
packagePath = join(packagePath, segments.shift()!);
nodeModulesIndex--;
}

Expand Down
9 changes: 5 additions & 4 deletions packages/compiler-cli/ngcc/src/entry_point_finder/utils.ts
Expand Up @@ -30,7 +30,7 @@ import {PathMappings} from '../utils';
*/
export function getBasePaths(
logger: Logger, sourceDirectory: AbsoluteFsPath,
pathMappings: PathMappings | undefined): AbsoluteFsPath[] {
pathMappings: PathMappings|undefined): AbsoluteFsPath[] {
const fs = getFileSystem();
const basePaths = [sourceDirectory];
if (pathMappings) {
Expand All @@ -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.`);
}
}));
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/ngcc/src/execution/cluster/api.ts
Expand Up @@ -44,7 +44,7 @@ export interface UpdatePackageJsonMessage extends JsonObject {
}

/** The type of messages sent from cluster workers to the cluster master. */
export type MessageFromWorker = ErrorMessage | TaskCompletedMessage | UpdatePackageJsonMessage;
export type MessageFromWorker = ErrorMessage|TaskCompletedMessage|UpdatePackageJsonMessage;

/** The type of messages sent from the cluster master to cluster workers. */
export type MessageToWorker = ProcessTaskMessage;