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

PR Close #36447
This commit is contained in:
Pete Bacon Darwin
2020-04-06 08:30:08 +01:00
committed by Kara Erickson
parent bfa55162de
commit 74b7a8eaf5
118 changed files with 1386 additions and 1046 deletions

View File

@ -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';
@ -21,7 +21,7 @@ import {Migration, MigrationHost} from '../../src/migrations/migration';
import {MockLogger} from '../helpers/mock_logger';
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
type DecoratorHandlerWithResolve = DecoratorHandler<unknown, unknown, unknown>& {
type DecoratorHandlerWithResolve = DecoratorHandler<unknown, unknown, unknown>&{
resolve: NonNullable<DecoratorHandler<unknown, unknown, unknown>['resolve']>;
};
@ -29,7 +29,9 @@ runInEachFileSystem(() => {
describe('DecorationAnalyzer', () => {
let _: typeof absoluteFrom;
beforeEach(() => { _ = absoluteFrom; });
beforeEach(() => {
_ = absoluteFrom;
});
describe('analyzeProgram()', () => {
let logs: string[];
@ -50,8 +52,8 @@ runInEachFileSystem(() => {
]);
// Only detect the Component and Directive decorators
handler.detect.and.callFake(
(node: ts.Declaration, decorators: Decorator[] | null): DetectResult<unknown>|
undefined => {
(node: ts.Declaration, decorators: Decorator[]|null): DetectResult<unknown>|
undefined => {
const className = (node as any).name.text;
if (decorators === null) {
logs.push(`detect: ${className} (no decorators)`);
@ -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());
@ -173,9 +175,9 @@ runInEachFileSystem(() => {
it('should return an object containing a reference to the original source file', () => {
const testFile = getSourceFileOrError(program, _('/node_modules/test-package/test.js'));
expect(result.get(testFile) !.sourceFile).toBe(testFile);
expect(result.get(testFile)!.sourceFile).toBe(testFile);
const otherFile = getSourceFileOrError(program, _('/node_modules/test-package/other.js'));
expect(result.get(otherFile) !.sourceFile).toBe(otherFile);
expect(result.get(otherFile)!.sourceFile).toBe(otherFile);
});
it('should call detect on the decorator handlers with each class from the parsed file',
@ -192,20 +194,23 @@ runInEachFileSystem(() => {
it('should return an object containing the classes that were analyzed', () => {
const file1 = getSourceFileOrError(program, _('/node_modules/test-package/test.js'));
const compiledFile1 = result.get(file1) !;
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) !;
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));
});
@ -284,18 +289,18 @@ runInEachFileSystem(() => {
() => {
const file =
getSourceFileOrError(program, _('/node_modules/test-package/component.js'));
const analysis = result.get(file) !;
const analysis = result.get(file)!;
expect(analysis).toBeDefined();
const ImportedComponent =
analysis.compiledClasses.find(f => f.name === 'ImportedComponent') !;
analysis.compiledClasses.find(f => f.name === 'ImportedComponent')!;
expect(ImportedComponent).toBeDefined();
});
it('should analyze an internally defined component, which is not exported at all', () => {
const file = getSourceFileOrError(program, _('/node_modules/test-package/entrypoint.js'));
const analysis = result.get(file) !;
const analysis = result.get(file)!;
expect(analysis).toBeDefined();
const LocalComponent = analysis.compiledClasses.find(f => f.name === 'LocalComponent') !;
const LocalComponent = analysis.compiledClasses.find(f => f.name === 'LocalComponent')!;
expect(LocalComponent).toBeDefined();
});
});
@ -341,7 +346,7 @@ runInEachFileSystem(() => {
});
it('should ignore classes from an externally imported file', () => {
const file = program.getSourceFile(_('/node_modules/other/component.js')) !;
const file = program.getSourceFile(_('/node_modules/other/component.js'))!;
expect(result.has(file)).toBe(false);
});
});
@ -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([{

View File

@ -62,7 +62,7 @@ runInEachFileSystem(() => {
const {host, compiler} = createMigrationHost({entryPoint, handlers: [handler]});
host.injectSyntheticDecorator(mockClazz, injectedDecorator);
const record = compiler.recordFor(mockClazz) !;
const record = compiler.recordFor(mockClazz)!;
expect(record).toBeDefined();
expect(record.traits.length).toBe(1);
expect(record.traits[0].detected.decorator).toBe(injectedDecorator);
@ -77,7 +77,7 @@ runInEachFileSystem(() => {
const decorator = createComponentDecorator(mockClazz, {selector: 'comp', exportAs: null});
host.injectSyntheticDecorator(mockClazz, decorator);
const record = compiler.recordFor(mockClazz) !;
const record = compiler.recordFor(mockClazz)!;
const migratedTrait = record.traits[0];
if (migratedTrait.state !== TraitState.ERRORED) {
return fail('Expected migrated class trait to be in an error state');
@ -120,7 +120,7 @@ runInEachFileSystem(() => {
host.injectSyntheticDecorator(myClass, injectedDecorator);
const decorators = host.getAllDecorators(myClass) !;
const decorators = host.getAllDecorators(myClass)!;
expect(decorators.length).toBe(2);
expect(decorators[0].name).toBe('Directive');
expect(decorators[1].name).toBe('InjectedDecorator');
@ -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 [];
}
}

View File

@ -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';
@ -333,7 +333,7 @@ runInEachFileSystem(() => {
'test-package', 'esm2015', false, getRootFiles(TEST_PROGRAM),
getRootFiles(TEST_DTS_PROGRAM));
program = bundle.src.program;
dtsProgram = bundle.dts !;
dtsProgram = bundle.dts!;
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, dtsProgram);
referencesRegistry = new NgccReferencesRegistry(host);
@ -367,8 +367,8 @@ runInEachFileSystem(() => {
const libraryModuleDeclaration = getDeclaration(
program, absoluteFrom('/node_modules/some-library/index.d.ts'), 'LibraryModule',
ts.isClassDeclaration);
expect(declarations.has(externalModuleDeclaration.name !)).toBe(true);
expect(declarations.has(libraryModuleDeclaration.name !)).toBe(false);
expect(declarations.has(externalModuleDeclaration.name!)).toBe(true);
expect(declarations.has(libraryModuleDeclaration.name!)).toBe(false);
});
it('should find declarations that have implicit return types', () => {
@ -414,13 +414,12 @@ runInEachFileSystem(() => {
analyses: ModuleWithProvidersAnalyses, fileName: AbsoluteFsPath) {
const file = getSourceFileOrError(dtsProgram.program, fileName);
const analysis = analyses.get(file);
return analysis ?
analysis.map(
info =>
[info.declaration.name !.getText(),
(info.ngModule.node as ts.ClassDeclaration).name !.getText(),
info.ngModule.viaModule]) :
[];
return analysis ? analysis.map(
info =>
[info.declaration.name!.getText(),
(info.ngModule.node as ts.ClassDeclaration).name!.getText(),
info.ngModule.viaModule]) :
[];
}
});
});
@ -536,7 +535,7 @@ runInEachFileSystem(() => {
'test-package', 'esm2015', false, getRootFiles(TEST_PROGRAM),
getRootFiles(TEST_DTS_PROGRAM));
const program = bundle.src.program;
const dtsProgram = bundle.dts !;
const dtsProgram = bundle.dts!;
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, dtsProgram);
const referencesRegistry = new NgccReferencesRegistry(host);
@ -558,9 +557,9 @@ runInEachFileSystem(() => {
const libraryModuleDeclaration = getDeclaration(
program, absoluteFrom('/node_modules/some-library/index.d.ts'), 'LibraryModule',
ts.isClassDeclaration);
expect(declarations.has(explicitInternalModuleDeclaration.name !)).toBe(true);
expect(declarations.has(externalModuleDeclaration.name !)).toBe(true);
expect(declarations.has(libraryModuleDeclaration.name !)).toBe(false);
expect(declarations.has(explicitInternalModuleDeclaration.name!)).toBe(true);
expect(declarations.has(externalModuleDeclaration.name!)).toBe(true);
expect(declarations.has(libraryModuleDeclaration.name!)).toBe(false);
});
it('should track references even when typings have already been processed', () => {
@ -586,9 +585,9 @@ runInEachFileSystem(() => {
const libraryModuleDeclaration = getDeclaration(
program, absoluteFrom('/node_modules/some-library/index.d.ts'), 'LibraryModule',
ts.isClassDeclaration);
expect(declarations.has(explicitInternalModuleDeclaration.name !)).toBe(true);
expect(declarations.has(externalModuleDeclaration.name !)).toBe(true);
expect(declarations.has(libraryModuleDeclaration.name !)).toBe(false);
expect(declarations.has(explicitInternalModuleDeclaration.name!)).toBe(true);
expect(declarations.has(externalModuleDeclaration.name!)).toBe(true);
expect(declarations.has(libraryModuleDeclaration.name!)).toBe(false);
});
});
});

View File

@ -91,7 +91,7 @@ runInEachFileSystem(() => {
const record = compiler.recordFor(mockClazz);
expect(record).toBeDefined();
expect(record !.traits.length).toBe(1);
expect(record!.traits.length).toBe(1);
});
it('should add a new trait to an existing class record', () => {
@ -118,11 +118,11 @@ runInEachFileSystem(() => {
compiler.analyzeFile(entryPoint.src.file);
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
const record = compiler.recordFor(myClass) !;
const record = compiler.recordFor(myClass)!;
expect(record).toBeDefined();
expect(record.traits.length).toBe(2);
expect(record.traits[0].detected.decorator !.name).toBe('Directive');
expect(record.traits[1].detected.decorator !.name).toBe('InjectedDecorator');
expect(record.traits[0].detected.decorator!.name).toBe('Directive');
expect(record.traits[1].detected.decorator!.name).toBe('InjectedDecorator');
});
it('should not add a weak handler when a primary handler already exists', () => {
@ -150,10 +150,10 @@ runInEachFileSystem(() => {
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
const record = compiler.recordFor(myClass) !;
const record = compiler.recordFor(myClass)!;
expect(record).toBeDefined();
expect(record.traits.length).toBe(1);
expect(record.traits[0].detected.decorator !.name).toBe('Directive');
expect(record.traits[0].detected.decorator!.name).toBe('Directive');
});
it('should replace an existing weak handler when injecting a primary handler', () => {
@ -181,10 +181,10 @@ runInEachFileSystem(() => {
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
const record = compiler.recordFor(myClass) !;
const record = compiler.recordFor(myClass)!;
expect(record).toBeDefined();
expect(record.traits.length).toBe(1);
expect(record.traits[0].detected.decorator !.name).toBe('InjectedDecorator');
expect(record.traits[0].detected.decorator!.name).toBe('InjectedDecorator');
});
it('should produce an error when a primary handler is added when a primary handler is already present',
@ -214,12 +214,11 @@ runInEachFileSystem(() => {
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
const record = compiler.recordFor(myClass) !;
const record = compiler.recordFor(myClass)!;
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!.length).toBe(1);
expect(record.metaDiagnostics![0].code).toBe(ngErrorCode(ErrorCode.DECORATOR_COLLISION));
expect(record.traits.length).toBe(0);
});
@ -233,7 +232,7 @@ runInEachFileSystem(() => {
const decorator = createComponentDecorator(mockClazz, {selector: 'comp', exportAs: null});
compiler.injectSyntheticDecorator(mockClazz, decorator);
const record = compiler.recordFor(mockClazz) !;
const record = compiler.recordFor(mockClazz)!;
const migratedTrait = record.traits[0];
if (migratedTrait.state !== TraitState.ERRORED) {
return fail('Expected migrated class trait to be in an error state');
@ -286,13 +285,12 @@ runInEachFileSystem(() => {
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
const decorators = compiler.getAllDecorators(myClass) !;
const decorators = compiler.getAllDecorators(myClass)!;
expect(decorators.length).toBe(2);
expect(decorators[0].name).toBe('Directive');
expect(decorators[1].name).toBe('InjectedDecorator');
});
});
});
});
@ -302,7 +300,7 @@ class TestHandler implements DecoratorHandler<unknown, unknown, unknown> {
precedence = HandlerPrecedence.PRIMARY;
detect(node: ClassDeclaration, decorators: Decorator[]|null): DetectResult<unknown>|undefined {
this.log.push(`${this.name}:detect:${node.name.text}:${decorators !.map(d => d.name)}`);
this.log.push(`${this.name}:detect:${node.name.text}:${decorators!.map(d => d.name)}`);
return undefined;
}

View File

@ -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';
@ -192,6 +192,6 @@ runInEachFileSystem(() => {
program: ts.Program, registry: NgccReferencesRegistry, fileName: AbsoluteFsPath,
componentName: string) {
const declaration = getDeclaration(program, fileName, componentName, ts.isClassDeclaration);
registry.add(null !, new Reference(declaration));
registry.add(null!, new Reference(declaration));
}
});

View File

@ -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';
@ -44,19 +44,19 @@ runInEachFileSystem(() => {
getDeclaration(program, indexPath, 'someFunction', ts.isFunctionDeclaration);
const someVariableDecl =
getDeclaration(program, indexPath, 'someVariable', ts.isVariableDeclaration);
const testArrayExpression = testArrayDeclaration.initializer !;
const testArrayExpression = testArrayDeclaration.initializer!;
const reflectionHost = new TypeScriptReflectionHost(checker);
const evaluator = new PartialEvaluator(reflectionHost, checker, /* dependencyTracker */ null);
const registry = new NgccReferencesRegistry(reflectionHost);
const references = (evaluator.evaluate(testArrayExpression) as any[]).filter(isReference);
registry.add(null !, ...references);
registry.add(null!, ...references);
const map = registry.getDeclarationMap();
expect(map.size).toEqual(2);
expect(map.get(someClassDecl.name !) !.node).toBe(someClassDecl);
expect(map.get(someFunctionDecl.name !) !.node).toBe(someFunctionDecl);
expect(map.get(someClassDecl.name!)!.node).toBe(someClassDecl);
expect(map.get(someFunctionDecl.name!)!.node).toBe(someFunctionDecl);
expect(map.has(someVariableDecl.name as ts.Identifier)).toBe(false);
});
});

View File

@ -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[];
@ -87,14 +86,14 @@ runInEachFileSystem(() => {
expect(analysis.has(entrypoint)).toBe(false);
expect(analysis.has(a)).toBe(false);
expect(analysis.has(b)).toBe(true);
expect(analysis.get(b) !.sourceFile).toBe(b);
expect(analysis.get(b) !.declarations.map(decl => decl.getText())).toEqual([
expect(analysis.get(b)!.sourceFile).toBe(b);
expect(analysis.get(b)!.declarations.map(decl => decl.getText())).toEqual([
'factoryB = factory__PRE_R3__'
]);
expect(analysis.has(c)).toBe(true);
expect(analysis.get(c) !.sourceFile).toBe(c);
expect(analysis.get(c) !.declarations.map(decl => decl.getText())).toEqual([
expect(analysis.get(c)!.sourceFile).toBe(c);
expect(analysis.get(c)!.declarations.map(decl => decl.getText())).toEqual([
'factoryC = factory__PRE_R3__',
'factoryD = factory__PRE_R3__',
]);