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];
return conf.required === required && conf.target === target;
})
.map((item) => {
return target + '_' + item.toUpperCase();
});
.map((item) => target + '_' + item.toUpperCase());
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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)
])

View File

@ -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;
}

View File

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

View File

@ -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[] {

View File

@ -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(

View File

@ -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;

View File

@ -60,7 +60,7 @@ function removeMetadata(metadata: StringMap, remove: any, references: Map<any, s
const propValue = metadata[prop];
if (propValue instanceof Array) {
metadata[prop] = propValue.filter(
(value: any) => { 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;

View File

@ -839,8 +839,7 @@ function declareTests({useJit}: {useJit: boolean}) {
describe('*ngFor', () => {
let tpl = '<div *ngFor="let item of items" @trigger>{{ item }}</div>';
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[] = [];

View File

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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -24,7 +24,7 @@ export class BrowserGetTestability implements GetTestability {
return testability;
};
global.getAllAngularTestabilities = () => { return registry.getAllTestabilities(); };
global.getAllAngularTestabilities = () => registry.getAllTestabilities();
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'}
*/
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 {
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());
}

View File

@ -28,5 +28,5 @@ export const WORKER_APP_LOCATION_PROVIDERS = [
function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () =>
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);
});
const preactivation2$ =
mergeMap.call(preactivation$, () => { return preActivation.checkGuards(); });
const preactivation2$ = mergeMap.call(preactivation$, () => preActivation.checkGuards());
const resolveData$ = mergeMap.call(preactivation2$, (shouldActivate: boolean) => {
if (shouldActivate) {

View File

@ -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',
}]
});
});

View File

@ -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;

View File

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