From 50c37d45dc8a4f5e38afaf594c9d5017e8eab3bd Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 4 Oct 2016 15:57:37 -0700 Subject: [PATCH] refactor: simplify arrow functions (#12057) --- browser-providers.conf.js | 4 +--- .../src/webdriver/chrome_driver_extension.ts | 2 +- .../benchpress/test/metric/multi_metric_spec.ts | 2 +- .../benchpress/test/reporter/multi_reporter_spec.ts | 2 +- modules/@angular/benchpress/test/sampler_spec.ts | 6 +++--- .../benchpress/test/web_driver_extension_spec.ts | 2 +- .../test/webdriver/chrome_driver_extension_spec.ts | 10 +++++----- .../@angular/compiler/src/output/abstract_emitter.ts | 2 +- modules/@angular/compiler/src/util.ts | 2 +- .../compiler/src/view_compiler/compile_query.ts | 5 ++--- .../compiler/test/animation/animation_parser_spec.ts | 10 +++++----- .../@angular/compiler/testing/metadata_overrider.ts | 2 +- .../core/test/animation/animation_integration_spec.ts | 3 +-- .../differs/default_iterable_differ_spec.ts | 3 +-- modules/@angular/core/test/zone/ng_zone_spec.ts | 2 +- modules/@angular/forms/test/form_array_spec.ts | 4 ++-- modules/@angular/forms/test/form_group_spec.ts | 4 ++-- .../platform-browser/src/browser/testability.ts | 2 +- modules/@angular/platform-browser/src/dom/debug/by.ts | 2 +- modules/@angular/platform-browser/src/dom/util.ts | 4 ++-- .../src/web_workers/worker/location_providers.ts | 2 +- modules/@angular/router/src/router.ts | 3 +-- modules/@angular/router/test/integration.spec.ts | 7 +++---- modules/@angular/upgrade/test/upgrade_spec.ts | 4 ++-- .../e2e_test/web_workers/router/router_spec.ts | 5 ++--- 25 files changed, 43 insertions(+), 51 deletions(-) diff --git a/browser-providers.conf.js b/browser-providers.conf.js index 6107380903..4b6f079f1c 100644 --- a/browser-providers.conf.js +++ b/browser-providers.conf.js @@ -333,7 +333,5 @@ function buildConfiguration(type, target, required) { var conf = CIconfiguration[item][type]; return conf.required === required && conf.target === target; }) - .map((item) => { - return target + '_' + item.toUpperCase(); - }); + .map((item) => target + '_' + item.toUpperCase()); } diff --git a/modules/@angular/benchpress/src/webdriver/chrome_driver_extension.ts b/modules/@angular/benchpress/src/webdriver/chrome_driver_extension.ts index 384ae4a0fd..e89d4264e3 100644 --- a/modules/@angular/benchpress/src/webdriver/chrome_driver_extension.ts +++ b/modules/@angular/benchpress/src/webdriver/chrome_driver_extension.ts @@ -169,7 +169,7 @@ export class ChromeDriverExtension extends WebDriverExtension { eventCategories: string[], eventName: string, expectedCategories: string[], expectedName: string = null): boolean { var hasCategories = expectedCategories.reduce( - (value, cat) => { return value && eventCategories.indexOf(cat) !== -1; }, true); + (value, cat) => value && eventCategories.indexOf(cat) !== -1, true); return !expectedName ? hasCategories : hasCategories && eventName === expectedName; } diff --git a/modules/@angular/benchpress/test/metric/multi_metric_spec.ts b/modules/@angular/benchpress/test/metric/multi_metric_spec.ts index 445a318369..9ee463253f 100644 --- a/modules/@angular/benchpress/test/metric/multi_metric_spec.ts +++ b/modules/@angular/benchpress/test/metric/multi_metric_spec.ts @@ -13,7 +13,7 @@ export function main() { function createMetric(ids: any[]) { var m = ReflectiveInjector .resolveAndCreate([ - ids.map(id => { return {provide: id, useValue: new MockMetric(id)}; }), + ids.map(id => ({provide: id, useValue: new MockMetric(id)})), MultiMetric.provideWith(ids) ]) .get(MultiMetric); diff --git a/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts b/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts index c880fc6393..f52588d808 100644 --- a/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts +++ b/modules/@angular/benchpress/test/reporter/multi_reporter_spec.ts @@ -14,7 +14,7 @@ export function main() { function createReporters(ids: any[]) { var r = ReflectiveInjector .resolveAndCreate([ - ids.map(id => { return {provide: id, useValue: new MockReporter(id)}; }), + ids.map(id => ({provide: id, useValue: new MockReporter(id)})), MultiReporter.provideWith(ids) ]) .get(MultiReporter); diff --git a/modules/@angular/benchpress/test/sampler_spec.ts b/modules/@angular/benchpress/test/sampler_spec.ts index b52f4b2dea..2f6bc0ad12 100644 --- a/modules/@angular/benchpress/test/sampler_spec.ts +++ b/modules/@angular/benchpress/test/sampler_spec.ts @@ -60,8 +60,8 @@ export function main() { createSampler({ driver: driver, validator: createCountingValidator(2), - prepare: () => { return count++; }, - execute: () => { return count++; } + prepare: () => count++, + execute: () => count++, }); sampler.sample().then((_) => { expect(count).toBe(4); @@ -221,7 +221,7 @@ function createCountingValidator( function createCountingMetric(log: any[] = []) { var scriptTime = 0; - return new MockMetric(log, () => { return {'script': scriptTime++}; }); + return new MockMetric(log, () => ({'script': scriptTime++})); } class MockDriverAdapter extends WebDriverAdapter { diff --git a/modules/@angular/benchpress/test/web_driver_extension_spec.ts b/modules/@angular/benchpress/test/web_driver_extension_spec.ts index ed70dc5fda..eb968cfa5e 100644 --- a/modules/@angular/benchpress/test/web_driver_extension_spec.ts +++ b/modules/@angular/benchpress/test/web_driver_extension_spec.ts @@ -17,7 +17,7 @@ export function main() { try { res(ReflectiveInjector .resolveAndCreate([ - ids.map((id) => { return {provide: id, useValue: new MockExtension(id)}; }), + ids.map((id) => ({provide: id, useValue: new MockExtension(id)})), {provide: Options.CAPABILITIES, useValue: caps}, WebDriverExtension.provideFirstSupported(ids) ]) diff --git a/modules/@angular/benchpress/test/webdriver/chrome_driver_extension_spec.ts b/modules/@angular/benchpress/test/webdriver/chrome_driver_extension_spec.ts index f3ab34ecd3..5c1376f08e 100644 --- a/modules/@angular/benchpress/test/webdriver/chrome_driver_extension_spec.ts +++ b/modules/@angular/benchpress/test/webdriver/chrome_driver_extension_spec.ts @@ -396,11 +396,11 @@ class MockDriverAdapter extends WebDriverAdapter { logs(type: string) { this._log.push(['logs', type]); if (type === 'performance') { - return Promise.resolve(this._events.map((event) => { - return { - 'message': Json.stringify({'message': {'method': this._messageMethod, 'params': event}}) - }; - })); + return Promise.resolve(this._events.map( + (event) => ({ + 'message': + Json.stringify({'message': {'method': this._messageMethod, 'params': event}}) + }))); } else { return null; } diff --git a/modules/@angular/compiler/src/output/abstract_emitter.ts b/modules/@angular/compiler/src/output/abstract_emitter.ts index 54dc6b1981..f9ed12a5fe 100644 --- a/modules/@angular/compiler/src/output/abstract_emitter.ts +++ b/modules/@angular/compiler/src/output/abstract_emitter.ts @@ -400,7 +400,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex } visitAllStatements(statements: o.Statement[], ctx: EmitterVisitorContext): void { - statements.forEach((stmt) => { return stmt.visitStatement(this, ctx); }); + statements.forEach((stmt) => stmt.visitStatement(this, ctx)); } } diff --git a/modules/@angular/compiler/src/util.ts b/modules/@angular/compiler/src/util.ts index 512c897566..0cc6789032 100644 --- a/modules/@angular/compiler/src/util.ts +++ b/modules/@angular/compiler/src/util.ts @@ -16,7 +16,7 @@ var CAMEL_CASE_REGEXP = /([A-Z])/g; export function camelCaseToDashCase(input: string): string { return StringWrapper.replaceAllMapped( - input, CAMEL_CASE_REGEXP, (m: string[]) => { return '-' + m[1].toLowerCase(); }); + input, CAMEL_CASE_REGEXP, (m: string[]) => '-' + m[1].toLowerCase()); } export function splitAtColon(input: string, defaultValues: string[]): string[] { diff --git a/modules/@angular/compiler/src/view_compiler/compile_query.ts b/modules/@angular/compiler/src/view_compiler/compile_query.ts index 1bd02aa237..ab7b71e77c 100644 --- a/modules/@angular/compiler/src/view_compiler/compile_query.ts +++ b/modules/@angular/compiler/src/view_compiler/compile_query.ts @@ -101,9 +101,8 @@ function createQueryValues(viewValues: ViewQueryValues): o.Expression[] { function mapNestedViews( declarationAppElement: o.Expression, view: CompileView, expressions: o.Expression[]): o.Expression { - var adjustedExpressions: o.Expression[] = expressions.map((expr) => { - return o.replaceVarInExpression(o.THIS_EXPR.name, o.variable('nestedView'), expr); - }); + var adjustedExpressions: o.Expression[] = expressions.map( + (expr) => o.replaceVarInExpression(o.THIS_EXPR.name, o.variable('nestedView'), expr)); return declarationAppElement.callMethod('mapNestedViews', [ o.variable(view.className), o.fn( diff --git a/modules/@angular/compiler/test/animation/animation_parser_spec.ts b/modules/@angular/compiler/test/animation/animation_parser_spec.ts index f780058167..a726fd23fb 100644 --- a/modules/@angular/compiler/test/animation/animation_parser_spec.ts +++ b/modules/@angular/compiler/test/animation/animation_parser_spec.ts @@ -24,8 +24,9 @@ export function main() { return flatStyles; }; - var collectKeyframeStyles = (keyframe: AnimationKeyframeAst): - {[key: string]: string | number} => { return combineStyles(keyframe.styles); }; + var collectKeyframeStyles = + (keyframe: AnimationKeyframeAst): {[key: string]: string | number} => + combineStyles(keyframe.styles); var collectStepStyles = (step: AnimationStepAst): Array<{[key: string]: string | number}> => { var keyframes = step.keyframes; @@ -51,9 +52,8 @@ export function main() { var getAnimationAstFromEntryAst = (ast: AnimationEntryAst) => { return ast.stateTransitions[0].animation; }; - var parseAnimationAst = (data: AnimationMetadata[]) => { - return getAnimationAstFromEntryAst(parseAnimation(data).ast); - }; + var parseAnimationAst = (data: AnimationMetadata[]) => + getAnimationAstFromEntryAst(parseAnimation(data).ast); var parseAnimationAndGetErrors = (data: AnimationMetadata[]) => parseAnimation(data).errors; diff --git a/modules/@angular/compiler/testing/metadata_overrider.ts b/modules/@angular/compiler/testing/metadata_overrider.ts index f5c909da11..c7b2bebe59 100644 --- a/modules/@angular/compiler/testing/metadata_overrider.ts +++ b/modules/@angular/compiler/testing/metadata_overrider.ts @@ -60,7 +60,7 @@ function removeMetadata(metadata: StringMap, remove: any, references: Map { return !removeObjects.has(_propHashKey(prop, value, references)); }); + (value: any) => !removeObjects.has(_propHashKey(prop, value, references))); } else { if (removeObjects.has(_propHashKey(prop, propValue, references))) { metadata[prop] = undefined; diff --git a/modules/@angular/core/test/animation/animation_integration_spec.ts b/modules/@angular/core/test/animation/animation_integration_spec.ts index 8b563edc4e..f6c594c620 100644 --- a/modules/@angular/core/test/animation/animation_integration_spec.ts +++ b/modules/@angular/core/test/animation/animation_integration_spec.ts @@ -839,8 +839,7 @@ function declareTests({useJit}: {useJit: boolean}) { describe('*ngFor', () => { let tpl = '
{{ item }}
'; - let getText = - (node: any) => { return node.innerHTML ? node.innerHTML : node.children[0].data; }; + let getText = (node: any) => node.innerHTML ? node.innerHTML : node.children[0].data; let assertParentChildContents = (parent: any, content: string) => { var values: string[] = []; diff --git a/modules/@angular/core/test/change_detection/differs/default_iterable_differ_spec.ts b/modules/@angular/core/test/change_detection/differs/default_iterable_differ_spec.ts index 9b2a878c0a..2505badbe5 100644 --- a/modules/@angular/core/test/change_detection/differs/default_iterable_differ_spec.ts +++ b/modules/@angular/core/test/change_detection/differs/default_iterable_differ_spec.ts @@ -486,8 +486,7 @@ export function main() { var trackByItemId = (index: number, item: any): any => item.id; - var buildItemList = - (list: string[]) => { return list.map((val) => { return new ItemWithId(val); }); }; + var buildItemList = (list: string[]) => list.map((val) => new ItemWithId(val)); beforeEach(() => { differ = new DefaultIterableDiffer(trackByItemId); }); diff --git a/modules/@angular/core/test/zone/ng_zone_spec.ts b/modules/@angular/core/test/zone/ng_zone_spec.ts index 5f7a99354c..42f2878f2c 100644 --- a/modules/@angular/core/test/zone/ng_zone_spec.ts +++ b/modules/@angular/core/test/zone/ng_zone_spec.ts @@ -214,7 +214,7 @@ function commonTests() { describe('run', () => { it('should return the body return value from run', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { expect(_zone.run(() => { return 6; })).toEqual(6); }); + macroTask(() => { expect(_zone.run(() => 6)).toEqual(6); }); macroTask(() => { async.done(); }); }), testTimeout); diff --git a/modules/@angular/forms/test/form_array_spec.ts b/modules/@angular/forms/test/form_array_spec.ts index f5d09b8dd1..76ba0644db 100644 --- a/modules/@angular/forms/test/form_array_spec.ts +++ b/modules/@angular/forms/test/form_array_spec.ts @@ -814,7 +814,7 @@ export function main() { describe('disabled errors', () => { it('should clear out array errors when disabled', () => { - const arr = new FormArray([new FormControl()], () => { return {'expected': true}; }); + const arr = new FormArray([new FormControl()], () => ({'expected': true})); expect(arr.errors).toEqual({'expected': true}); arr.disable(); @@ -825,7 +825,7 @@ export function main() { }); it('should re-populate array errors when enabled from a child', () => { - const arr = new FormArray([new FormControl()], () => { return {'expected': true}; }); + const arr = new FormArray([new FormControl()], () => ({'expected': true})); arr.disable(); expect(arr.errors).toEqual(null); diff --git a/modules/@angular/forms/test/form_group_spec.ts b/modules/@angular/forms/test/form_group_spec.ts index 4d787ee6a4..0c1d131d26 100644 --- a/modules/@angular/forms/test/form_group_spec.ts +++ b/modules/@angular/forms/test/form_group_spec.ts @@ -823,7 +823,7 @@ export function main() { describe('disabled errors', () => { it('should clear out group errors when disabled', () => { - const g = new FormGroup({'one': new FormControl()}, () => { return {'expected': true}; }); + const g = new FormGroup({'one': new FormControl()}, () => ({'expected': true})); expect(g.errors).toEqual({'expected': true}); g.disable(); @@ -834,7 +834,7 @@ export function main() { }); it('should re-populate group errors when enabled from a child', () => { - const g = new FormGroup({'one': new FormControl()}, () => { return {'expected': true}; }); + const g = new FormGroup({'one': new FormControl()}, () => ({'expected': true})); g.disable(); expect(g.errors).toEqual(null); diff --git a/modules/@angular/platform-browser/src/browser/testability.ts b/modules/@angular/platform-browser/src/browser/testability.ts index 569e937832..ff7ae2a3d8 100644 --- a/modules/@angular/platform-browser/src/browser/testability.ts +++ b/modules/@angular/platform-browser/src/browser/testability.ts @@ -24,7 +24,7 @@ export class BrowserGetTestability implements GetTestability { return testability; }; - global.getAllAngularTestabilities = () => { return registry.getAllTestabilities(); }; + global.getAllAngularTestabilities = () => registry.getAllTestabilities(); global.getAllAngularRootElements = () => registry.getAllRootElements(); diff --git a/modules/@angular/platform-browser/src/dom/debug/by.ts b/modules/@angular/platform-browser/src/dom/debug/by.ts index 0e3771ab99..07cb057099 100644 --- a/modules/@angular/platform-browser/src/dom/debug/by.ts +++ b/modules/@angular/platform-browser/src/dom/debug/by.ts @@ -52,6 +52,6 @@ export class By { * {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'} */ static directive(type: Type): Predicate { - return (debugElement) => { return debugElement.providerTokens.indexOf(type) !== -1; }; + return (debugElement) => debugElement.providerTokens.indexOf(type) !== -1; } } diff --git a/modules/@angular/platform-browser/src/dom/util.ts b/modules/@angular/platform-browser/src/dom/util.ts index 0ed68a80a0..c482c4392e 100644 --- a/modules/@angular/platform-browser/src/dom/util.ts +++ b/modules/@angular/platform-browser/src/dom/util.ts @@ -14,10 +14,10 @@ var DASH_CASE_REGEXP = /-([a-z])/g; export function camelCaseToDashCase(input: string): string { return StringWrapper.replaceAllMapped( - input, CAMEL_CASE_REGEXP, (m: any /** TODO #9100 */) => { return '-' + m[1].toLowerCase(); }); + input, CAMEL_CASE_REGEXP, (m: string[]) => '-' + m[1].toLowerCase()); } export function dashCaseToCamelCase(input: string): string { return StringWrapper.replaceAllMapped( - input, DASH_CASE_REGEXP, (m: any /** TODO #9100 */) => { return m[1].toUpperCase(); }); + input, DASH_CASE_REGEXP, (m: string[]) => m[1].toUpperCase()); } diff --git a/modules/@angular/platform-webworker/src/web_workers/worker/location_providers.ts b/modules/@angular/platform-webworker/src/web_workers/worker/location_providers.ts index 17999d3875..76c8066ffe 100644 --- a/modules/@angular/platform-webworker/src/web_workers/worker/location_providers.ts +++ b/modules/@angular/platform-webworker/src/web_workers/worker/location_providers.ts @@ -28,5 +28,5 @@ export const WORKER_APP_LOCATION_PROVIDERS = [ function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () => Promise { - return () => { return zone.runGuarded(() => platformLocation.init()); }; + return () => zone.runGuarded(() => platformLocation.init()); } diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index f5da74f613..462ae20108 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -577,8 +577,7 @@ export class Router { preActivation.traverse(this.outletMap); }); - const preactivation2$ = - mergeMap.call(preactivation$, () => { return preActivation.checkGuards(); }); + const preactivation2$ = mergeMap.call(preactivation$, () => preActivation.checkGuards()); const resolveData$ = mergeMap.call(preactivation2$, (shouldActivate: boolean) => { if (shouldActivate) { diff --git a/modules/@angular/router/test/integration.spec.ts b/modules/@angular/router/test/integration.spec.ts index 229e284810..5e4f08d6e8 100644 --- a/modules/@angular/router/test/integration.spec.ts +++ b/modules/@angular/router/test/integration.spec.ts @@ -972,8 +972,7 @@ describe('Integration', () => { TestBed.configureTestingModule({ providers: [{ provide: 'CanActivate', - useValue: - (a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => { return of (false); } + useValue: (a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => of (false), }] }); }); @@ -1047,7 +1046,7 @@ describe('Integration', () => { useValue: (c: any, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => { return a.params['name'] === 'victor'; } - } + }, ] }); }); @@ -1192,7 +1191,7 @@ describe('Integration', () => { TestBed.configureTestingModule({ providers: [{ provide: 'alwaysFalse', - useValue: (a: any, b: any) => { return a.params.id === '22'; } + useValue: (a: any, b: any) => a.params.id === '22', }] }); }); diff --git a/modules/@angular/upgrade/test/upgrade_spec.ts b/modules/@angular/upgrade/test/upgrade_spec.ts index 52bbbd2731..8dd42cc239 100644 --- a/modules/@angular/upgrade/test/upgrade_spec.ts +++ b/modules/@angular/upgrade/test/upgrade_spec.ts @@ -77,8 +77,8 @@ export function main() { }; const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module)); - ng1Module.directive('ng1a', () => { return {template: '{{ l(\'ng1a\') }}'}; }); - ng1Module.directive('ng1b', () => { return {template: '{{ l(\'ng1b\') }}'}; }); + ng1Module.directive('ng1a', () => ({template: '{{ l(\'ng1a\') }}'})); + ng1Module.directive('ng1b', () => ({template: '{{ l(\'ng1b\') }}'})); ng1Module.run(($rootScope: any /** TODO #9100 */) => { $rootScope.l = l; $rootScope.reset = () => log.length = 0; diff --git a/modules/playground/e2e_test/web_workers/router/router_spec.ts b/modules/playground/e2e_test/web_workers/router/router_spec.ts index 81a5930b13..5c315f1a48 100644 --- a/modules/playground/e2e_test/web_workers/router/router_spec.ts +++ b/modules/playground/e2e_test/web_workers/router/router_spec.ts @@ -67,7 +67,7 @@ describe('WebWorker Router', () => { browser.wait(() => { let deferred = protractor.promise.defer(); var elem = element(by.css(contentSelector)); - elem.getText().then((text) => { return deferred.fulfill(text === expected); }); + elem.getText().then((text) => deferred.fulfill(text === expected)); return deferred.promise; }, 5000); } @@ -75,8 +75,7 @@ describe('WebWorker Router', () => { function waitForUrl(regex: any /** TODO #9100 */): void { browser.wait(() => { let deferred = protractor.promise.defer(); - browser.getCurrentUrl().then( - (url) => { return deferred.fulfill(url.match(regex) !== null); }); + browser.getCurrentUrl().then((url) => deferred.fulfill(url.match(regex) !== null)); return deferred.promise; }, 5000); }