Skip to content

Commit b64b5ec

Browse files
alexeaglechuckjaz
authored andcommitted
refactor(facade): Remove most of StringMapWrapper facade. (angular#12022)
This change mostly automated by alexeagle/tslint@12012b0 with some manual fixes.
1 parent ed9c2b6 commit b64b5ec

36 files changed

+140
-205
lines changed

modules/@angular/benchpress/src/metric/multi_metric.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Injector, OpaqueToken} from '@angular/core';
10-
import {StringMapWrapper} from '../facade/collection';
1110

1211
import {Metric} from '../metric';
1312

@@ -57,8 +56,7 @@ export class MultiMetric extends Metric {
5756

5857
function mergeStringMaps(maps: {[key: string]: string}[]): {[key: string]: string} {
5958
var result: {[key: string]: string} = {};
60-
maps.forEach(
61-
map => { StringMapWrapper.forEach(map, (value, prop) => { result[prop] = value; }); });
59+
maps.forEach(map => { Object.keys(map).forEach(prop => { result[prop] = map[prop]; }); });
6260
return result;
6361
}
6462

modules/@angular/benchpress/src/metric/user_metric.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {Inject, Injectable} from '@angular/core';
1010

1111
import {Options} from '../common_options';
12-
import {StringMapWrapper} from '../facade/collection';
1312
import {isNumber} from '../facade/lang';
1413
import {Metric} from '../metric';
1514
import {WebDriverAdapter} from '../web_driver_adapter';
@@ -40,7 +39,7 @@ export class UserMetric extends Metric {
4039
reject = rej;
4140
});
4241
let adapter = this._wdAdapter;
43-
let names = StringMapWrapper.keys(this._userMetrics);
42+
let names = Object.keys(this._userMetrics);
4443

4544
function getAndClearValues() {
4645
Promise.all(names.map(name => adapter.executeScript(`return window.${name}`)))

modules/@angular/benchpress/src/reporter/util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {StringMapWrapper} from '../facade/collection';
9+
1010
import {NumberWrapper} from '../facade/lang';
1111
import {MeasureValues} from '../measure_values';
1212
import {Statistic} from '../statistic';
@@ -17,7 +17,7 @@ export function formatNum(n: number) {
1717

1818
export function sortedProps(obj: {[key: string]: any}) {
1919
var props: string[] = [];
20-
StringMapWrapper.forEach(obj, (value, prop) => props.push(prop));
20+
props.push(...Object.keys(obj));
2121
props.sort();
2222
return props;
2323
}
@@ -30,4 +30,4 @@ export function formatStats(validSamples: MeasureValues[], metricName: string):
3030
// Note: Don't use the unicode character for +- as it might cause
3131
// hickups for consoles...
3232
return NumberWrapper.isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`;
33-
}
33+
}

modules/@angular/benchpress/src/sample_description.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {OpaqueToken} from '@angular/core';
1010

1111
import {Options} from './common_options';
12-
import {StringMapWrapper} from './facade/collection';
1312
import {Metric} from './metric';
1413
import {Validator} from './validator';
1514

@@ -42,7 +41,7 @@ export class SampleDescription {
4241
public metrics: {[key: string]: any}) {
4342
this.description = {};
4443
descriptions.forEach(description => {
45-
StringMapWrapper.forEach(description, (value, prop) => this.description[prop] = value);
44+
Object.keys(description).forEach(prop => { this.description[prop] = description[prop]; });
4645
});
4746
}
4847

modules/@angular/benchpress/test/metric/perflog_metric_spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {Provider} from '@angular/core';
1010
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
1111

1212
import {Metric, Options, PerfLogEvent, PerfLogFeatures, PerflogMetric, ReflectiveInjector, WebDriverExtension} from '../../index';
13-
import {StringMapWrapper} from '../../src/facade/collection';
1413
import {isPresent} from '../../src/facade/lang';
1514
import {TraceEventFactory} from '../trace_event_factory';
1615

@@ -68,7 +67,7 @@ export function main() {
6867

6968
function sortedKeys(stringMap: {[key: string]: any}) {
7069
var res: string[] = [];
71-
StringMapWrapper.forEach(stringMap, (_, key) => { res.push(key); });
70+
res.push(...Object.keys(stringMap));
7271
res.sort();
7372
return res;
7473
}

modules/@angular/compiler-cli/test/reflector_host_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal';
9+
import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';
1010
import * as ts from 'typescript';
1111

1212
import {ReflectorHost} from '../src/reflector_host';

modules/@angular/compiler-cli/test/static_reflector_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector';
1010
import {HostListener, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
1111
import {ListWrapper} from '@angular/facade/src/collection';
12-
import {isBlank} from '@angular/facade/src/lang';
1312
import {MetadataCollector} from '@angular/tsc-wrapped';
1413
import * as ts from 'typescript';
1514

modules/@angular/compiler/src/animation/animation_compiler.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {StringMapWrapper} from '../facade/collection';
9+
1010
import {isPresent} from '../facade/lang';
1111
import {Identifiers, resolveIdentifier} from '../identifiers';
1212
import * as o from '../output/output_ast';
@@ -61,8 +61,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
6161
}
6262

6363
ast.styles.forEach(entry => {
64-
stylesArr.push(
65-
o.literalMap(StringMapWrapper.keys(entry).map(key => [key, o.literal(entry[key])])));
64+
stylesArr.push(o.literalMap(Object.keys(entry).map(key => [key, o.literal(entry[key])])));
6665
});
6766

6867
return o.importExpr(resolveIdentifier(Identifiers.AnimationStyles)).instantiate([
@@ -133,9 +132,8 @@ class _AnimationBuilder implements AnimationAstVisitor {
133132
visitAnimationStateDeclaration(
134133
ast: AnimationStateDeclarationAst, context: _AnimationBuilderContext): void {
135134
var flatStyles: {[key: string]: string | number} = {};
136-
_getStylesArray(ast).forEach(entry => {
137-
StringMapWrapper.forEach(entry, (value: string, key: string) => { flatStyles[key] = value; });
138-
});
135+
_getStylesArray(ast).forEach(
136+
entry => { Object.keys(entry).forEach(key => { flatStyles[key] = entry[key]; }); });
139137
context.stateMap.registerState(ast.stateName, flatStyles);
140138
}
141139

@@ -291,18 +289,16 @@ class _AnimationBuilder implements AnimationAstVisitor {
291289
var fnVariable = o.variable(this._fnVarName);
292290

293291
var lookupMap: any[] = [];
294-
StringMapWrapper.forEach(
295-
context.stateMap.states, (value: {[key: string]: string}, stateName: string) => {
296-
var variableValue = EMPTY_MAP;
297-
if (isPresent(value)) {
298-
let styleMap: any[] = [];
299-
StringMapWrapper.forEach(value, (value: string, key: string) => {
300-
styleMap.push([key, o.literal(value)]);
301-
});
302-
variableValue = o.literalMap(styleMap);
303-
}
304-
lookupMap.push([stateName, variableValue]);
305-
});
292+
Object.keys(context.stateMap.states).forEach(stateName => {
293+
const value = context.stateMap.states[stateName];
294+
var variableValue = EMPTY_MAP;
295+
if (isPresent(value)) {
296+
let styleMap: any[] = [];
297+
Object.keys(value).forEach(key => { styleMap.push([key, o.literal(value[key])]); });
298+
variableValue = o.literalMap(styleMap);
299+
}
300+
lookupMap.push([stateName, variableValue]);
301+
});
306302

307303
const compiledStatesMapStmt = this._statesMapVar.set(o.literalMap(lookupMap)).toDeclStmt();
308304
const statements: o.Statement[] = [compiledStatesMapStmt, fnStatement];
@@ -349,7 +345,7 @@ function _isEndStateAnimateStep(step: AnimationAst): boolean {
349345
if (step instanceof AnimationStepAst && step.duration > 0 && step.keyframes.length == 2) {
350346
var styles1 = _getStylesArray(step.keyframes[0])[0];
351347
var styles2 = _getStylesArray(step.keyframes[1])[0];
352-
return StringMapWrapper.isEmpty(styles1) && StringMapWrapper.isEmpty(styles2);
348+
return Object.keys(styles1).length === 0 && Object.keys(styles2).length === 0;
353349
}
354350
return false;
355351
}

modules/@angular/compiler/src/animation/animation_parser.ts

+35-47
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const _INITIAL_KEYFRAME = 0;
2020
const _TERMINAL_KEYFRAME = 1;
2121
const _ONE_SECOND = 1000;
2222

23+
declare type Styles = {
24+
[key: string]: string | number
25+
};
26+
2327
export class AnimationParseError extends ParseError {
2428
constructor(message: string) { super(null, message); }
2529
toString(): string { return `${this.msg}`; }
@@ -90,11 +94,11 @@ export class AnimationParser {
9094
function _parseAnimationDeclarationStates(
9195
stateMetadata: CompileAnimationStateDeclarationMetadata,
9296
errors: AnimationParseError[]): AnimationStateDeclarationAst[] {
93-
var styleValues: {[key: string]: string | number}[] = [];
97+
var styleValues: Styles[] = [];
9498
stateMetadata.styles.styles.forEach(stylesEntry => {
9599
// TODO (matsko): change this when we get CSS class integration support
96100
if (isStringMap(stylesEntry)) {
97-
styleValues.push(<{[key: string]: string | number}>stylesEntry);
101+
styleValues.push(stylesEntry as Styles);
98102
} else {
99103
errors.push(new AnimationParseError(
100104
`State based animations cannot contain references to other states`));
@@ -169,16 +173,6 @@ function _parseAnimationTransitionExpr(
169173
return expressions;
170174
}
171175

172-
function _fetchSylesFromState(stateName: string, stateStyles: {[key: string]: AnimationStylesAst}):
173-
CompileAnimationStyleMetadata {
174-
var entry = stateStyles[stateName];
175-
if (isPresent(entry)) {
176-
var styles = <{[key: string]: string | number}[]>entry.styles;
177-
return new CompileAnimationStyleMetadata(0, styles);
178-
}
179-
return null;
180-
}
181-
182176
function _normalizeAnimationEntry(entry: CompileAnimationMetadata | CompileAnimationMetadata[]):
183177
CompileAnimationMetadata {
184178
return isArray(entry) ? new CompileAnimationSequenceMetadata(<CompileAnimationMetadata[]>entry) :
@@ -234,7 +228,7 @@ function _normalizeStyleStepEntry(
234228
}
235229

236230
var newSteps: CompileAnimationMetadata[] = [];
237-
var combinedStyles: {[key: string]: string | number}[];
231+
var combinedStyles: Styles[];
238232
steps.forEach(step => {
239233
if (step instanceof CompileAnimationStyleMetadata) {
240234
// this occurs when a style step is followed by a previous style step
@@ -290,7 +284,7 @@ function _normalizeStyleStepEntry(
290284
function _resolveStylesFromState(
291285
stateName: string, stateStyles: {[key: string]: AnimationStylesAst},
292286
errors: AnimationParseError[]) {
293-
var styles: {[key: string]: string | number}[] = [];
287+
var styles: Styles[] = [];
294288
if (stateName[0] != ':') {
295289
errors.push(new AnimationParseError(`Animation states via styles must be prefixed with a ":"`));
296290
} else {
@@ -302,7 +296,7 @@ function _resolveStylesFromState(
302296
} else {
303297
value.styles.forEach(stylesEntry => {
304298
if (isStringMap(stylesEntry)) {
305-
styles.push(<{[key: string]: string | number}>stylesEntry);
299+
styles.push(stylesEntry as Styles);
306300
}
307301
});
308302
}
@@ -336,15 +330,13 @@ function _parseAnimationKeyframes(
336330
var lastOffset = 0;
337331
keyframeSequence.steps.forEach(styleMetadata => {
338332
var offset = styleMetadata.offset;
339-
var keyframeStyles: {[key: string]: string | number} = {};
333+
var keyframeStyles: Styles = {};
340334
styleMetadata.styles.forEach(entry => {
341-
StringMapWrapper.forEach(
342-
<{[key: string]: string | number}>entry,
343-
(value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
344-
if (prop != 'offset') {
345-
keyframeStyles[prop] = value;
346-
}
347-
});
335+
Object.keys(entry).forEach(prop => {
336+
if (prop != 'offset') {
337+
keyframeStyles[prop] = (entry as Styles)[prop];
338+
}
339+
});
348340
});
349341

350342
if (isPresent(offset)) {
@@ -381,24 +373,22 @@ function _parseAnimationKeyframes(
381373
let entry = rawKeyframes[i];
382374
let styles = entry[1];
383375

384-
StringMapWrapper.forEach(
385-
styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
386-
if (!isPresent(firstKeyframeStyles[prop])) {
387-
firstKeyframeStyles[prop] = FILL_STYLE_FLAG;
388-
}
389-
});
376+
Object.keys(styles).forEach(prop => {
377+
if (!isPresent(firstKeyframeStyles[prop])) {
378+
firstKeyframeStyles[prop] = FILL_STYLE_FLAG;
379+
}
380+
});
390381
}
391382

392383
for (i = limit - 1; i >= 0; i--) {
393384
let entry = rawKeyframes[i];
394385
let styles = entry[1];
395386

396-
StringMapWrapper.forEach(
397-
styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
398-
if (!isPresent(lastKeyframeStyles[prop])) {
399-
lastKeyframeStyles[prop] = value;
400-
}
401-
});
387+
Object.keys(styles).forEach(prop => {
388+
if (!isPresent(lastKeyframeStyles[prop])) {
389+
lastKeyframeStyles[prop] = styles[prop];
390+
}
391+
});
402392
}
403393

404394
return rawKeyframes.map(
@@ -422,11 +412,9 @@ function _parseTransitionAnimation(
422412
if (entry instanceof CompileAnimationStyleMetadata) {
423413
entry.styles.forEach(stylesEntry => {
424414
// by this point we know that we only have stringmap values
425-
var map = <{[key: string]: string | number}>stylesEntry;
426-
StringMapWrapper.forEach(
427-
map, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
428-
collectedStyles.insertAtTime(prop, time, value);
429-
});
415+
var map = stylesEntry as Styles;
416+
Object.keys(map).forEach(
417+
prop => { collectedStyles.insertAtTime(prop, time, map[prop]); });
430418
});
431419
previousStyles = entry.styles;
432420
return;
@@ -472,7 +460,7 @@ function _parseTransitionAnimation(
472460
} else {
473461
let styleData = <CompileAnimationStyleMetadata>styles;
474462
let offset = _TERMINAL_KEYFRAME;
475-
let styleAst = new AnimationStylesAst(<{[key: string]: string | number}[]>styleData.styles);
463+
let styleAst = new AnimationStylesAst(styleData.styles as Styles[]);
476464
var keyframe = new AnimationKeyframeAst(offset, styleAst);
477465
keyframes = [keyframe];
478466
}
@@ -484,9 +472,8 @@ function _parseTransitionAnimation(
484472

485473
keyframes.forEach(
486474
(keyframe: any /** TODO #9100 */) => keyframe.styles.styles.forEach(
487-
(entry: any /** TODO #9100 */) => StringMapWrapper.forEach(
488-
entry, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) =>
489-
collectedStyles.insertAtTime(prop, currentTime, value))));
475+
(entry: any /** TODO #9100 */) => Object.keys(entry).forEach(
476+
prop => { collectedStyles.insertAtTime(prop, currentTime, entry[prop]); })));
490477
} else {
491478
// if the code reaches this stage then an error
492479
// has already been populated within the _normalizeStyleSteps()
@@ -559,10 +546,11 @@ function _parseTimeExpression(
559546
function _createStartKeyframeFromEndKeyframe(
560547
endKeyframe: AnimationKeyframeAst, startTime: number, duration: number,
561548
collectedStyles: StylesCollection, errors: AnimationParseError[]): AnimationKeyframeAst {
562-
var values: {[key: string]: string | number} = {};
549+
var values: Styles = {};
563550
var endTime = startTime + duration;
564-
endKeyframe.styles.styles.forEach((styleData: {[key: string]: string | number}) => {
565-
StringMapWrapper.forEach(styleData, (val: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
551+
endKeyframe.styles.styles.forEach((styleData: Styles) => {
552+
Object.keys(styleData).forEach(prop => {
553+
const val = styleData[prop];
566554
if (prop == 'offset') return;
567555

568556
var resultIndex = collectedStyles.indexOfAtOrBeforeTime(prop, startTime);

modules/@angular/compiler/src/compile_metadata.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {ChangeDetectionStrategy, SchemaMetadata, Type, ViewEncapsulation} from '@angular/core';
1010

11-
import {ListWrapper, MapWrapper, StringMapWrapper} from './facade/collection';
11+
import {ListWrapper, MapWrapper} from './facade/collection';
1212
import {isPresent, isStringMap, normalizeBlank, normalizeBool} from './facade/lang';
1313
import {LifecycleHooks} from './private_import_core';
1414
import {CssSelector} from './selector';
@@ -342,7 +342,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
342342
var hostProperties: {[key: string]: string} = {};
343343
var hostAttributes: {[key: string]: string} = {};
344344
if (isPresent(host)) {
345-
StringMapWrapper.forEach(host, (value: string, key: string) => {
345+
Object.keys(host).forEach(key => {
346+
const value = host[key];
346347
const matches = key.match(HOST_REG_EXP);
347348
if (matches === null) {
348349
hostAttributes[key] = value;

modules/@angular/compiler/src/output/value_util.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
import {CompileIdentifierMetadata} from '../compile_metadata';
11-
import {StringMapWrapper} from '../facade/collection';
1211
import {ValueTransformer, visitValue} from '../util';
1312

1413
import * as o from './output_ast';
@@ -24,9 +23,7 @@ class _ValueOutputAstTransformer implements ValueTransformer {
2423

2524
visitStringMap(map: {[key: string]: any}, type: o.MapType): o.Expression {
2625
var entries: Array<string|o.Expression>[] = [];
27-
StringMapWrapper.forEach(map, (value: any, key: string) => {
28-
entries.push([key, visitValue(value, this, null)]);
29-
});
26+
Object.keys(map).forEach(key => { entries.push([key, visitValue(map[key], this, null)]); });
3027
return o.literalMap(entries, type);
3128
}
3229

0 commit comments

Comments
 (0)