refactor: simplify arrow functions (#12057)

This commit is contained in:
Victor Berchet 2016-10-04 15:57:37 -07:00 committed by Chuck Jazdzewski
parent a63359689f
commit 50c37d45dc
25 changed files with 43 additions and 51 deletions

View File

@ -333,7 +333,5 @@ function buildConfiguration(type, target, required) {
var conf = CIconfiguration[item][type]; var conf = CIconfiguration[item][type];
return conf.required === required && conf.target === target; return conf.required === required && conf.target === target;
}) })
.map((item) => { .map((item) => target + '_' + item.toUpperCase());
return target + '_' + item.toUpperCase();
});
} }

View File

@ -169,7 +169,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
eventCategories: string[], eventName: string, expectedCategories: string[], eventCategories: string[], eventName: string, expectedCategories: string[],
expectedName: string = null): boolean { expectedName: string = null): boolean {
var hasCategories = expectedCategories.reduce( 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; return !expectedName ? hasCategories : hasCategories && eventName === expectedName;
} }

View File

@ -13,7 +13,7 @@ export function main() {
function createMetric(ids: any[]) { function createMetric(ids: any[]) {
var m = ReflectiveInjector var m = ReflectiveInjector
.resolveAndCreate([ .resolveAndCreate([
ids.map(id => { return {provide: id, useValue: new MockMetric(id)}; }), ids.map(id => ({provide: id, useValue: new MockMetric(id)})),
MultiMetric.provideWith(ids) MultiMetric.provideWith(ids)
]) ])
.get(MultiMetric); .get(MultiMetric);

View File

@ -14,7 +14,7 @@ export function main() {
function createReporters(ids: any[]) { function createReporters(ids: any[]) {
var r = ReflectiveInjector var r = ReflectiveInjector
.resolveAndCreate([ .resolveAndCreate([
ids.map(id => { return {provide: id, useValue: new MockReporter(id)}; }), ids.map(id => ({provide: id, useValue: new MockReporter(id)})),
MultiReporter.provideWith(ids) MultiReporter.provideWith(ids)
]) ])
.get(MultiReporter); .get(MultiReporter);

View File

@ -60,8 +60,8 @@ export function main() {
createSampler({ createSampler({
driver: driver, driver: driver,
validator: createCountingValidator(2), validator: createCountingValidator(2),
prepare: () => { return count++; }, prepare: () => count++,
execute: () => { return count++; } execute: () => count++,
}); });
sampler.sample().then((_) => { sampler.sample().then((_) => {
expect(count).toBe(4); expect(count).toBe(4);
@ -221,7 +221,7 @@ function createCountingValidator(
function createCountingMetric(log: any[] = []) { function createCountingMetric(log: any[] = []) {
var scriptTime = 0; var scriptTime = 0;
return new MockMetric(log, () => { return {'script': scriptTime++}; }); return new MockMetric(log, () => ({'script': scriptTime++}));
} }
class MockDriverAdapter extends WebDriverAdapter { class MockDriverAdapter extends WebDriverAdapter {

View File

@ -17,7 +17,7 @@ export function main() {
try { try {
res(ReflectiveInjector res(ReflectiveInjector
.resolveAndCreate([ .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}, {provide: Options.CAPABILITIES, useValue: caps},
WebDriverExtension.provideFirstSupported(ids) WebDriverExtension.provideFirstSupported(ids)
]) ])

View File

@ -396,11 +396,11 @@ class MockDriverAdapter extends WebDriverAdapter {
logs(type: string) { logs(type: string) {
this._log.push(['logs', type]); this._log.push(['logs', type]);
if (type === 'performance') { if (type === 'performance') {
return Promise.resolve(this._events.map((event) => { return Promise.resolve(this._events.map(
return { (event) => ({
'message': Json.stringify({'message': {'method': this._messageMethod, 'params': event}}) 'message':
}; Json.stringify({'message': {'method': this._messageMethod, 'params': event}})
})); })));
} else { } else {
return null; return null;
} }

View File

@ -400,7 +400,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
} }
visitAllStatements(statements: o.Statement[], ctx: EmitterVisitorContext): void { visitAllStatements(statements: o.Statement[], ctx: EmitterVisitorContext): void {
statements.forEach((stmt) => { return stmt.visitStatement(this, ctx); }); statements.forEach((stmt) => stmt.visitStatement(this, ctx));
} }
} }

View File

@ -16,7 +16,7 @@ var CAMEL_CASE_REGEXP = /([A-Z])/g;
export function camelCaseToDashCase(input: string): string { export function camelCaseToDashCase(input: string): string {
return StringWrapper.replaceAllMapped( 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[] { export function splitAtColon(input: string, defaultValues: string[]): string[] {

View File

@ -101,9 +101,8 @@ function createQueryValues(viewValues: ViewQueryValues): o.Expression[] {
function mapNestedViews( function mapNestedViews(
declarationAppElement: o.Expression, view: CompileView, declarationAppElement: o.Expression, view: CompileView,
expressions: o.Expression[]): o.Expression { expressions: o.Expression[]): o.Expression {
var adjustedExpressions: o.Expression[] = expressions.map((expr) => { var adjustedExpressions: o.Expression[] = expressions.map(
return o.replaceVarInExpression(o.THIS_EXPR.name, o.variable('nestedView'), expr); (expr) => o.replaceVarInExpression(o.THIS_EXPR.name, o.variable('nestedView'), expr));
});
return declarationAppElement.callMethod('mapNestedViews', [ return declarationAppElement.callMethod('mapNestedViews', [
o.variable(view.className), o.variable(view.className),
o.fn( o.fn(

View File

@ -24,8 +24,9 @@ export function main() {
return flatStyles; return flatStyles;
}; };
var collectKeyframeStyles = (keyframe: AnimationKeyframeAst): var collectKeyframeStyles =
{[key: string]: string | number} => { return combineStyles(keyframe.styles); }; (keyframe: AnimationKeyframeAst): {[key: string]: string | number} =>
combineStyles(keyframe.styles);
var collectStepStyles = (step: AnimationStepAst): Array<{[key: string]: string | number}> => { var collectStepStyles = (step: AnimationStepAst): Array<{[key: string]: string | number}> => {
var keyframes = step.keyframes; var keyframes = step.keyframes;
@ -51,9 +52,8 @@ export function main() {
var getAnimationAstFromEntryAst = var getAnimationAstFromEntryAst =
(ast: AnimationEntryAst) => { return ast.stateTransitions[0].animation; }; (ast: AnimationEntryAst) => { return ast.stateTransitions[0].animation; };
var parseAnimationAst = (data: AnimationMetadata[]) => { var parseAnimationAst = (data: AnimationMetadata[]) =>
return getAnimationAstFromEntryAst(parseAnimation(data).ast); getAnimationAstFromEntryAst(parseAnimation(data).ast);
};
var parseAnimationAndGetErrors = (data: AnimationMetadata[]) => parseAnimation(data).errors; var parseAnimationAndGetErrors = (data: AnimationMetadata[]) => parseAnimation(data).errors;

View File

@ -60,7 +60,7 @@ function removeMetadata(metadata: StringMap, remove: any, references: Map<any, s
const propValue = metadata[prop]; const propValue = metadata[prop];
if (propValue instanceof Array) { if (propValue instanceof Array) {
metadata[prop] = propValue.filter( metadata[prop] = propValue.filter(
(value: any) => { return !removeObjects.has(_propHashKey(prop, value, references)); }); (value: any) => !removeObjects.has(_propHashKey(prop, value, references)));
} else { } else {
if (removeObjects.has(_propHashKey(prop, propValue, references))) { if (removeObjects.has(_propHashKey(prop, propValue, references))) {
metadata[prop] = undefined; metadata[prop] = undefined;

View File

@ -839,8 +839,7 @@ function declareTests({useJit}: {useJit: boolean}) {
describe('*ngFor', () => { describe('*ngFor', () => {
let tpl = '<div *ngFor="let item of items" @trigger>{{ item }}</div>'; let tpl = '<div *ngFor="let item of items" @trigger>{{ item }}</div>';
let getText = let getText = (node: any) => node.innerHTML ? node.innerHTML : node.children[0].data;
(node: any) => { return node.innerHTML ? node.innerHTML : node.children[0].data; };
let assertParentChildContents = (parent: any, content: string) => { let assertParentChildContents = (parent: any, content: string) => {
var values: string[] = []; var values: string[] = [];

View File

@ -486,8 +486,7 @@ export function main() {
var trackByItemId = (index: number, item: any): any => item.id; var trackByItemId = (index: number, item: any): any => item.id;
var buildItemList = var buildItemList = (list: string[]) => list.map((val) => new ItemWithId(val));
(list: string[]) => { return list.map((val) => { return new ItemWithId(val); }); };
beforeEach(() => { differ = new DefaultIterableDiffer(trackByItemId); }); beforeEach(() => { differ = new DefaultIterableDiffer(trackByItemId); });

View File

@ -214,7 +214,7 @@ function commonTests() {
describe('run', () => { describe('run', () => {
it('should return the body return value from run', it('should return the body return value from run',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
macroTask(() => { expect(_zone.run(() => { return 6; })).toEqual(6); }); macroTask(() => { expect(_zone.run(() => 6)).toEqual(6); });
macroTask(() => { async.done(); }); macroTask(() => { async.done(); });
}), testTimeout); }), testTimeout);

View File

@ -814,7 +814,7 @@ export function main() {
describe('disabled errors', () => { describe('disabled errors', () => {
it('should clear out array errors when disabled', () => { 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}); expect(arr.errors).toEqual({'expected': true});
arr.disable(); arr.disable();
@ -825,7 +825,7 @@ export function main() {
}); });
it('should re-populate array errors when enabled from a child', () => { 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(); arr.disable();
expect(arr.errors).toEqual(null); expect(arr.errors).toEqual(null);

View File

@ -823,7 +823,7 @@ export function main() {
describe('disabled errors', () => { describe('disabled errors', () => {
it('should clear out group errors when disabled', () => { 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}); expect(g.errors).toEqual({'expected': true});
g.disable(); g.disable();
@ -834,7 +834,7 @@ export function main() {
}); });
it('should re-populate group errors when enabled from a child', () => { 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(); g.disable();
expect(g.errors).toEqual(null); expect(g.errors).toEqual(null);

View File

@ -24,7 +24,7 @@ export class BrowserGetTestability implements GetTestability {
return testability; return testability;
}; };
global.getAllAngularTestabilities = () => { return registry.getAllTestabilities(); }; global.getAllAngularTestabilities = () => registry.getAllTestabilities();
global.getAllAngularRootElements = () => registry.getAllRootElements(); global.getAllAngularRootElements = () => registry.getAllRootElements();

View File

@ -52,6 +52,6 @@ export class By {
* {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'} * {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
*/ */
static directive(type: Type<any>): Predicate<DebugElement> { static directive(type: Type<any>): Predicate<DebugElement> {
return (debugElement) => { return debugElement.providerTokens.indexOf(type) !== -1; }; return (debugElement) => debugElement.providerTokens.indexOf(type) !== -1;
} }
} }

View File

@ -14,10 +14,10 @@ var DASH_CASE_REGEXP = /-([a-z])/g;
export function camelCaseToDashCase(input: string): string { export function camelCaseToDashCase(input: string): string {
return StringWrapper.replaceAllMapped( 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 { export function dashCaseToCamelCase(input: string): string {
return StringWrapper.replaceAllMapped( return StringWrapper.replaceAllMapped(
input, DASH_CASE_REGEXP, (m: any /** TODO #9100 */) => { return m[1].toUpperCase(); }); input, DASH_CASE_REGEXP, (m: string[]) => m[1].toUpperCase());
} }

View File

@ -28,5 +28,5 @@ export const WORKER_APP_LOCATION_PROVIDERS = [
function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () => function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () =>
Promise<boolean> { Promise<boolean> {
return () => { return zone.runGuarded(() => platformLocation.init()); }; return () => zone.runGuarded(() => platformLocation.init());
} }

View File

@ -577,8 +577,7 @@ export class Router {
preActivation.traverse(this.outletMap); preActivation.traverse(this.outletMap);
}); });
const preactivation2$ = const preactivation2$ = mergeMap.call(preactivation$, () => preActivation.checkGuards());
mergeMap.call(preactivation$, () => { return preActivation.checkGuards(); });
const resolveData$ = mergeMap.call(preactivation2$, (shouldActivate: boolean) => { const resolveData$ = mergeMap.call(preactivation2$, (shouldActivate: boolean) => {
if (shouldActivate) { if (shouldActivate) {

View File

@ -972,8 +972,7 @@ describe('Integration', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [{ providers: [{
provide: 'CanActivate', provide: 'CanActivate',
useValue: useValue: (a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => of (false),
(a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => { return of (false); }
}] }]
}); });
}); });
@ -1047,7 +1046,7 @@ describe('Integration', () => {
useValue: (c: any, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => { useValue: (c: any, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => {
return a.params['name'] === 'victor'; return a.params['name'] === 'victor';
} }
} },
] ]
}); });
}); });
@ -1192,7 +1191,7 @@ describe('Integration', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [{ providers: [{
provide: 'alwaysFalse', provide: 'alwaysFalse',
useValue: (a: any, b: any) => { return a.params.id === '22'; } useValue: (a: any, b: any) => a.params.id === '22',
}] }]
}); });
}); });

View File

@ -77,8 +77,8 @@ export function main() {
}; };
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module)); const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
ng1Module.directive('ng1a', () => { return {template: '{{ l(\'ng1a\') }}'}; }); ng1Module.directive('ng1a', () => ({template: '{{ l(\'ng1a\') }}'}));
ng1Module.directive('ng1b', () => { return {template: '{{ l(\'ng1b\') }}'}; }); ng1Module.directive('ng1b', () => ({template: '{{ l(\'ng1b\') }}'}));
ng1Module.run(($rootScope: any /** TODO #9100 */) => { ng1Module.run(($rootScope: any /** TODO #9100 */) => {
$rootScope.l = l; $rootScope.l = l;
$rootScope.reset = () => log.length = 0; $rootScope.reset = () => log.length = 0;

View File

@ -67,7 +67,7 @@ describe('WebWorker Router', () => {
browser.wait(() => { browser.wait(() => {
let deferred = protractor.promise.defer(); let deferred = protractor.promise.defer();
var elem = element(by.css(contentSelector)); 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; return deferred.promise;
}, 5000); }, 5000);
} }
@ -75,8 +75,7 @@ describe('WebWorker Router', () => {
function waitForUrl(regex: any /** TODO #9100 */): void { function waitForUrl(regex: any /** TODO #9100 */): void {
browser.wait(() => { browser.wait(() => {
let deferred = protractor.promise.defer(); let deferred = protractor.promise.defer();
browser.getCurrentUrl().then( browser.getCurrentUrl().then((url) => deferred.fulfill(url.match(regex) !== null));
(url) => { return deferred.fulfill(url.match(regex) !== null); });
return deferred.promise; return deferred.promise;
}, 5000); }, 5000);
} }