Skip to content

Commit

Permalink
style(core): reformat all of packages/core with new clang format version
Browse files Browse the repository at this point in the history
This commit updates the formatting of all packages/core/*
files at once to comply with the new version of clang.
Doing it all at once this way will cause some short-term
rebasing of existing core PRs, but will prevent head-
aches when reviewing PRs down the line (because we
will not have to filter out the noise of unrelated
formatting changes as these files are touched in the
future).
  • Loading branch information
kara committed Apr 9, 2020
1 parent 2e4244d commit 1e4c605
Show file tree
Hide file tree
Showing 383 changed files with 14,629 additions and 11,917 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Rule extends Rules.TypedRule {
const typeChecker = program.getTypeChecker();
const queryVisitor = new NgQueryResolveVisitor(program.getTypeChecker());
const templateVisitor = new NgComponentTemplateVisitor(typeChecker);
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !);
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f)!);
const printer = ts.createPrinter();
const failures: RuleFailure[] = [];

Expand All @@ -44,7 +44,7 @@ export class Rule extends Rules.TypedRule {
// check component templates for static query usage.
templateVisitor.resolvedTemplates.forEach(template => {
if (classMetadata.has(template.container)) {
classMetadata.get(template.container) !.template = template;
classMetadata.get(template.container)!.template = template;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ export class Rule extends Rules.TypedRule {
transformer.recordChanges();

if (updateRecorders.has(sourceFile)) {
failures.push(...updateRecorders.get(sourceFile) !.failures);
failures.push(...updateRecorders.get(sourceFile)!.failures);
}

return failures;

/** Gets the update recorder for the specified source file. */
function getUpdateRecorder(sourceFile: ts.SourceFile): TslintUpdateRecorder {
if (updateRecorders.has(sourceFile)) {
return updateRecorders.get(sourceFile) !;
return updateRecorders.get(sourceFile)!;
}
const recorder = new TslintUpdateRecorder(ruleName, sourceFile);
updateRecorders.set(sourceFile, recorder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {Replacement, RuleFailure, Rules} from 'tslint';
import * as ts from 'typescript';

import {HelperFunction, getHelper} from '../renderer-to-renderer2/helpers';
import {getHelper, HelperFunction} from '../renderer-to-renderer2/helpers';
import {migrateExpression, replaceImport} from '../renderer-to-renderer2/migration';
import {findCoreImport, findRendererReferences} from '../renderer-to-renderer2/util';

Expand Down Expand Up @@ -75,7 +75,7 @@ export class Rule extends Rules.TypedRule {
private _getTypedNodeFailure(
node: ts.ParameterDeclaration|ts.PropertyDeclaration|ts.AsExpression,
sourceFile: ts.SourceFile): RuleFailure {
const type = node.type !;
const type = node.type!;

return new RuleFailure(
sourceFile, type.getStart(), type.getEnd(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export class Rule extends Rules.TypedRule {
transform.recordChanges();

if (updateRecorders.has(sourceFile)) {
return updateRecorders.get(sourceFile) !.failures;
return updateRecorders.get(sourceFile)!.failures;
}
return [];

/** Gets the update recorder for the specified source file. */
function getUpdateRecorder(sourceFile: ts.SourceFile): TslintUpdateRecorder {
if (updateRecorders.has(sourceFile)) {
return updateRecorders.get(sourceFile) !;
return updateRecorders.get(sourceFile)!;
}
const recorder = new TslintUpdateRecorder(ruleName, sourceFile);
updateRecorders.set(sourceFile, recorder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as ts from 'typescript';

import {NgDecorator, getAngularDecorators} from '../../utils/ng_decorators';
import {getAngularDecorators, NgDecorator} from '../../utils/ng_decorators';
import {getPropertyNameText} from '../../utils/typescript/property_name';

export interface ResolvedNgModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class TslintUpdateRecorder implements UpdateRecorder {
// are handled in reverse and in case a decorator and import are inserted at
// the start of the file, the class decorator should come after the import.
this.failures.unshift(new RuleFailure(
this.sourceFile, node.getStart(), 0, `Class needs to be decorated with ` +
this.sourceFile, node.getStart(), 0,
`Class needs to be decorated with ` +
`"${decoratorText}" because it has been provided by "${className}".`,
this.ruleName, Replacement.appendText(node.getStart(), `${decoratorText}\n`)));
}
Expand Down
23 changes: 13 additions & 10 deletions packages/core/schematics/migrations/missing-injectable/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class MissingInjectableTransform {
new TypeScriptReflectionHost(typeChecker), typeChecker, /* dependencyTracker */ null);
}

recordChanges() { this.importManager.recordChanges(); }
recordChanges() {
this.importManager.recordChanges();
}

/**
* Migrates all specified NgModule's by walking through referenced providers
Expand Down Expand Up @@ -76,10 +78,9 @@ export class MissingInjectableTransform {
this._migrateLiteralProviders(literals);

if (!Array.isArray(resolvedValue)) {
return [{
node: module.providersExpr,
message: 'Providers of module are not statically analyzable.'
}];
return [
{node: module.providersExpr, message: 'Providers of module are not statically analyzable.'}
];
}

return this._visitProviderResolvedValue(resolvedValue, module);
Expand Down Expand Up @@ -194,8 +195,9 @@ export class MissingInjectableTransform {

const sourceFile = node.getSourceFile();
const newObjectLiteral = ts.updateObjectLiteral(
node, node.properties.concat(
ts.createPropertyAssignment('useValue', ts.createIdentifier('undefined'))));
node,
node.properties.concat(
ts.createPropertyAssignment('useValue', ts.createIdentifier('undefined'))));

this.getUpdateRecorder(sourceFile)
.updateObjectLiteral(
Expand All @@ -217,11 +219,12 @@ export class MissingInjectableTransform {
// decorate the class. This is because the class is instantiated through the
// specified "deps" and the class does not need a factory definition.
if (value.has('provide') && value.has('useClass') && value.get('deps') == null) {
return this._visitProviderResolvedValue(value.get('useClass') !, module);
return this._visitProviderResolvedValue(value.get('useClass')!, module);
}
} else if (Array.isArray(value)) {
return value.reduce((res, v) => res.concat(this._visitProviderResolvedValue(v, module)), [
] as AnalysisFailure[]);
return value.reduce(
(res, v) => res.concat(this._visitProviderResolvedValue(v, module)),
[] as AnalysisFailure[]);
} else if (value instanceof DynamicValue) {
return [{node: value.node, message: `Provider is not statically analyzable.`}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import * as ts from 'typescript';

import {NgDecorator, getAngularDecorators} from '../../utils/ng_decorators';
import {getAngularDecorators, NgDecorator} from '../../utils/ng_decorators';

import {isModuleWithProvidersNotGeneric} from './util';

export interface ResolvedNgModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ModuleWithProvidersTransform {
/** Migrates a given NgModule by walking through the referenced providers and static methods. */
migrateModule(module: ResolvedNgModule): AnalysisFailure[] {
return module.staticMethodsWithoutType.map(this._migrateStaticNgModuleMethod.bind(this))
.filter(v => v) as AnalysisFailure[];
.filter(v => v) as AnalysisFailure[];
}

/** Migrates a ModuleWithProviders type definition that has no explicit generic type */
Expand Down Expand Up @@ -98,8 +98,10 @@ export class ModuleWithProvidersTransform {
return ngModule && (value.size === 1 || (providers && value.size === 2));
}

/** Determine the generic type of a suspected ModuleWithProviders return type and add it
* explicitly */
/**
* Determine the generic type of a suspected ModuleWithProviders return type and add it
* explicitly
*/
private _migrateStaticNgModuleMethod(node: ts.MethodDeclaration): AnalysisFailure|null {
const returnStatement = node.body &&
node.body.statements.find(n => ts.isReturnStatement(n)) as ts.ReturnStatement | undefined;
Expand Down Expand Up @@ -131,7 +133,7 @@ export class ModuleWithProvidersTransform {
*/
private _getTypeOfResolvedValue(value: ResolvedValue): string|undefined {
if (value instanceof Map && this.isModuleWithProvidersType(value)) {
const mapValue = value.get('ngModule') !;
const mapValue = value.get('ngModule')!;
if (mapValue instanceof Reference && ts.isClassDeclaration(mapValue.node) &&
mapValue.node.name) {
return mapValue.node.name.text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function createAnyTypeHelper(): ts.TypeAliasDeclaration {

/** Creates a function parameter that is typed as `any`. */
function getAnyTypedParameter(
parameterName: string | ts.Identifier, isRequired = true): ts.ParameterDeclaration {
parameterName: string|ts.Identifier, isRequired = true): ts.ParameterDeclaration {
// Declare the parameter as `any` so we don't have to add extra logic to ensure that the
// generated code will pass type checking. Use our custom `any` type so people have an incentive
// to clean it up afterwards and to avoid potentially introducing lint warnings in G3.
Expand Down Expand Up @@ -153,10 +153,11 @@ function getCreationHelper(

// `if (parent) { renderer.appendChild(parent, node) }`.
const guardedAppendChildCall = ts.createIf(
parent, ts.createBlock(
[ts.createExpressionStatement(ts.createCall(
ts.createPropertyAccess(renderer, 'appendChild'), [], [parent, node]))],
true));
parent,
ts.createBlock(
[ts.createExpressionStatement(
ts.createCall(ts.createPropertyAccess(renderer, 'appendChild'), [], [parent, node]))],
true));

return ts.createFunctionDeclaration(
[], [], undefined, functionName, [],
Expand Down Expand Up @@ -258,10 +259,11 @@ function getDetachViewHelper(): ts.FunctionDeclaration {

// const node = rootNodes[i];
const nodeVariableStatement = ts.createVariableStatement(
undefined, ts.createVariableDeclarationList(
[ts.createVariableDeclaration(
node, undefined, ts.createElementAccess(rootNodes, incrementor))],
ts.NodeFlags.Const));
undefined,
ts.createVariableDeclarationList(
[ts.createVariableDeclaration(
node, undefined, ts.createElementAccess(rootNodes, incrementor))],
ts.NodeFlags.Const));
// renderer.removeChild(renderer.parentNode(node), node);
const removeCall = ts.createCall(
ts.createPropertyAccess(renderer, 'removeChild'), [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {HelperFunction} from './helpers';
import {findImportSpecifier} from './util';

/** A call expression that is based on a property access. */
type PropertyAccessCallExpression = ts.CallExpression & {expression: ts.PropertyAccessExpression};
type PropertyAccessCallExpression = ts.CallExpression&{expression: ts.PropertyAccessExpression};

/** Replaces an import inside an import statement with a different one. */
export function replaceImport(node: ts.NamedImports, oldImport: string, newImport: string) {
Expand Down Expand Up @@ -42,7 +42,7 @@ export function replaceImport(node: ts.NamedImports, oldImport: string, newImpor
* Returns null if the expression should be dropped.
*/
export function migrateExpression(node: ts.CallExpression, typeChecker: ts.TypeChecker):
{node: ts.Node | null, requiredHelpers?: HelperFunction[]} {
{node: ts.Node|null, requiredHelpers?: HelperFunction[]} {
if (isPropertyAccessCallExpression(node)) {
switch (node.expression.name.getText()) {
case 'setElementProperty':
Expand Down Expand Up @@ -152,7 +152,7 @@ function migrateSetElementClass(node: PropertyAccessCallExpression): ts.Node {
// Clone so we don't mutate by accident. Note that we assume that
// the user's code is providing all three required arguments.
const outputMethodArgs = node.arguments.slice();
const isAddArgument = outputMethodArgs.pop() !;
const isAddArgument = outputMethodArgs.pop()!;
const createRendererCall = (isAdd: boolean) => {
const innerExpression = node.expression.expression;
const topExpression =
Expand Down Expand Up @@ -263,6 +263,6 @@ function migrateAnimateCall() {
*/
function switchToHelperCall(
node: PropertyAccessCallExpression, helper: HelperFunction,
args: ts.Expression[] | ts.NodeArray<ts.Expression>): ts.Node {
args: ts.Expression[]|ts.NodeArray<ts.Expression>): ts.Node {
return ts.createCall(ts.createIdentifier(helper), [], [node.expression.expression, ...args]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export function findImportSpecifier(

/** Checks whether a node is referring to an import spcifier. */
function isReferenceToImport(
typeChecker: ts.TypeChecker, node: ts.Node,
importSpecifier: ts.ImportSpecifier | null): boolean {
typeChecker: ts.TypeChecker, node: ts.Node, importSpecifier: ts.ImportSpecifier|null): boolean {
if (importSpecifier) {
const nodeSymbol = typeChecker.getTypeAtLocation(node).getSymbol();
const importSymbol = typeChecker.getTypeAtLocation(importSpecifier).getSymbol();
Expand All @@ -102,7 +101,7 @@ function isReferenceToImport(
/** Finds the identifier referring to the `Renderer` inside a `forwardRef` call expression. */
function findRendererIdentifierInForwardRef(
typeChecker: ts.TypeChecker, node: ts.CallExpression,
rendererImport: ts.ImportSpecifier | null): ts.Identifier|null {
rendererImport: ts.ImportSpecifier|null): ts.Identifier|null {
const firstArg = node.arguments[0];

if (ts.isArrowFunction(firstArg)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getInputNamesOfClass(
}

const inputDecorator =
getAngularDecorators(typeChecker, m.decorators !).find(d => d.name === 'Input');
getAngularDecorators(typeChecker, m.decorators!).find(d => d.name === 'Input');

if (inputDecorator && hasPropertyNameText(m.name)) {
resolvedInputSetters.push(m.name.text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {AotCompiler, CompileDirectiveMetadata, CompileMetadataResolver, CompileNgModuleMetadata, CompileStylesheetMetadata, ElementAst, EmbeddedTemplateAst, NgAnalyzedModules, QueryMatch, StaticSymbol, TemplateAst} from '@angular/compiler';
import {Diagnostic, createProgram, readConfiguration} from '@angular/compiler-cli';
import {createProgram, Diagnostic, readConfiguration} from '@angular/compiler-cli';
import {resolve} from 'path';
import * as ts from 'typescript';

Expand Down Expand Up @@ -46,17 +46,17 @@ export class QueryTemplateStrategy implements TimingStrategy {
// expose the logic that is necessary to analyze the determined modules. We work around
// this by just accessing the necessary private properties using the bracket notation.
this.compiler = (aotProgram as any)['compiler'];
this.metadataResolver = this.compiler !['_metadataResolver'];
this.metadataResolver = this.compiler!['_metadataResolver'];

// Modify the "DirectiveNormalizer" to not normalize any referenced external stylesheets.
// This is necessary because in CLI projects preprocessor files are commonly referenced
// and we don't want to parse them in order to extract relative style references. This
// breaks the analysis of the project because we instantiate a standalone AOT compiler
// program which does not contain the custom logic by the Angular CLI Webpack compiler plugin.
const directiveNormalizer = this.metadataResolver !['_directiveNormalizer'];
const directiveNormalizer = this.metadataResolver!['_directiveNormalizer'];
directiveNormalizer['_normalizeStylesheet'] = function(metadata: CompileStylesheetMetadata) {
return new CompileStylesheetMetadata(
{styles: metadata.styles, styleUrls: [], moduleUrl: metadata.moduleUrl !});
{styles: metadata.styles, styleUrls: [], moduleUrl: metadata.moduleUrl!});
};

// Retrieves the analyzed modules of the current program. This data can be
Expand All @@ -75,7 +75,7 @@ export class QueryTemplateStrategy implements TimingStrategy {

/** Analyzes a given directive by determining the timing of all matched view queries. */
private _analyzeDirective(symbol: StaticSymbol, analyzedModules: NgAnalyzedModules) {
const metadata = this.metadataResolver !.getDirectiveMetadata(symbol);
const metadata = this.metadataResolver!.getDirectiveMetadata(symbol);
const ngModule = analyzedModules.ngModuleByPipeOrDirective.get(symbol);

if (!metadata.isComponent || !ngModule) {
Expand Down Expand Up @@ -168,15 +168,15 @@ export class QueryTemplateStrategy implements TimingStrategy {
const queryKey = this._getViewQueryUniqueKey(filePath, classDecl.name.text, queryName);

if (this.analyzedQueries.has(queryKey)) {
return this.analyzedQueries.get(queryKey) !;
return this.analyzedQueries.get(queryKey)!;
}
return null;
}

private _parseTemplate(component: CompileDirectiveMetadata, ngModule: CompileNgModuleMetadata):
TemplateAst[] {
return this
.compiler !['_parseTemplate'](component, ngModule, ngModule.transitiveModule.directives)
.compiler!['_parseTemplate'](component, ngModule, ngModule.transitiveModule.directives)
.template;
}

Expand All @@ -201,19 +201,19 @@ function findStaticQueryIds(
nodes.forEach((node) => {
const staticQueryIds = new Set<number>();
const dynamicQueryIds = new Set<number>();
let queryMatches: QueryMatch[] = undefined !;
let queryMatches: QueryMatch[] = undefined!;
if (node instanceof ElementAst) {
findStaticQueryIds(node.children, result);
node.children.forEach((child) => {
const childData = result.get(child) !;
const childData = result.get(child)!;
childData.staticQueryIds.forEach(queryId => staticQueryIds.add(queryId));
childData.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
});
queryMatches = node.queryMatches;
} else if (node instanceof EmbeddedTemplateAst) {
findStaticQueryIds(node.children, result);
node.children.forEach((child) => {
const childData = result.get(child) !;
const childData = result.get(child)!;
childData.staticQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
childData.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface TimingStrategy {
}

export type TimingResult = {
timing: QueryTiming | null; message?: string;
timing: QueryTiming|null;
message?: string;
};

0 comments on commit 1e4c605

Please sign in to comment.