Skip to content

Commit

Permalink
fix stringmapwrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Oct 1, 2016
1 parent 83d94b7 commit 610a769
Show file tree
Hide file tree
Showing 32 changed files with 167 additions and 114 deletions.
8 changes: 6 additions & 2 deletions modules/@angular/benchpress/src/metric/multi_metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ export class MultiMetric extends Metric {

function mergeStringMaps(maps: {[key: string]: string}[]): {[key: string]: string} {
var result: {[key: string]: string} = {};
maps.forEach(
map => { StringMapWrapper.forEach(map, (value, prop) => { result[prop] = value; }); });
maps.forEach(map => {
Object.keys(map).forEach(prop => {
const value = map[prop];
result[prop] = value;
});
});
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/benchpress/src/metric/user_metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class UserMetric extends Metric {
reject = rej;
});
let adapter = this._wdAdapter;
let names = StringMapWrapper.keys(this._userMetrics);
let names = Object.keys(this._userMetrics);

function getAndClearValues() {
Promise.all(names.map(name => adapter.executeScript(`return window.${name}`)))
Expand Down
5 changes: 4 additions & 1 deletion modules/@angular/benchpress/src/reporter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function formatNum(n: number) {

export function sortedProps(obj: {[key: string]: any}) {
var props: string[] = [];
StringMapWrapper.forEach(obj, (value, prop) => props.push(prop));
Object.keys(obj).forEach(prop => {
const value = obj[prop];
props.push(prop)
});
props.sort();
return props;
}
Expand Down
5 changes: 4 additions & 1 deletion modules/@angular/benchpress/src/sample_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class SampleDescription {
public metrics: {[key: string]: any}) {
this.description = {};
descriptions.forEach(description => {
StringMapWrapper.forEach(description, (value, prop) => this.description[prop] = value);
Object.keys(description).forEach(prop => {
const value = description[prop];
this.description[prop] = value
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export function main() {

function sortedKeys(stringMap: {[key: string]: any}) {
var res: string[] = [];
StringMapWrapper.forEach(stringMap, (_, key) => { res.push(key); });
Object.keys(stringMap).forEach(key => {
const _ = stringMap[key];
res.push(key);
});
res.sort();
return res;
}
Expand Down
33 changes: 18 additions & 15 deletions modules/@angular/compiler/src/animation/animation_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
}

ast.styles.forEach(entry => {
stylesArr.push(
o.literalMap(StringMapWrapper.keys(entry).map(key => [key, o.literal(entry[key])])));
stylesArr.push(o.literalMap(Object.keys(entry).map(key => [key, o.literal(entry[key])])));
});

return o.importExpr(resolveIdentifier(Identifiers.AnimationStyles)).instantiate([
Expand Down Expand Up @@ -134,7 +133,10 @@ class _AnimationBuilder implements AnimationAstVisitor {
ast: AnimationStateDeclarationAst, context: _AnimationBuilderContext): void {
var flatStyles: {[key: string]: string | number} = {};
_getStylesArray(ast).forEach(entry => {
StringMapWrapper.forEach(entry, (value: string, key: string) => { flatStyles[key] = value; });
Object.keys(entry).forEach(key => {
const value = entry[key];
flatStyles[key] = value;
});
});
context.stateMap.registerState(ast.stateName, flatStyles);
}
Expand Down Expand Up @@ -291,18 +293,19 @@ class _AnimationBuilder implements AnimationAstVisitor {
var fnVariable = o.variable(this._fnVarName);

var lookupMap: any[] = [];
StringMapWrapper.forEach(
context.stateMap.states, (value: {[key: string]: string}, stateName: string) => {
var variableValue = EMPTY_MAP;
if (isPresent(value)) {
let styleMap: any[] = [];
StringMapWrapper.forEach(value, (value: string, key: string) => {
styleMap.push([key, o.literal(value)]);
});
variableValue = o.literalMap(styleMap);
}
lookupMap.push([stateName, variableValue]);
Object.keys(context.stateMap.states).forEach(stateName => {
const value = context.stateMap.states[stateName];
var variableValue = EMPTY_MAP;
if (isPresent(value)) {
let styleMap: any[] = [];
Object.keys(value).forEach(key => {
const value2 = value[key];
styleMap.push([key, o.literal(value2)]);
});
variableValue = o.literalMap(styleMap);
}
lookupMap.push([stateName, variableValue]);
});

const compiledStatesMapStmt = this._statesMapVar.set(o.literalMap(lookupMap)).toDeclStmt();
const statements: o.Statement[] = [compiledStatesMapStmt, fnStatement];
Expand Down Expand Up @@ -349,7 +352,7 @@ function _isEndStateAnimateStep(step: AnimationAst): boolean {
if (step instanceof AnimationStepAst && step.duration > 0 && step.keyframes.length == 2) {
var styles1 = _getStylesArray(step.keyframes[0])[0];
var styles2 = _getStylesArray(step.keyframes[1])[0];
return StringMapWrapper.isEmpty(styles1) && StringMapWrapper.isEmpty(styles2);
return Object.keys(styles1).length === 0 && Object.keys(styles2).length === 0;
}
return false;
}
Expand Down
55 changes: 28 additions & 27 deletions modules/@angular/compiler/src/animation/animation_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,12 @@ function _parseAnimationKeyframes(
var offset = styleMetadata.offset;
var keyframeStyles: {[key: string]: string | number} = {};
styleMetadata.styles.forEach(entry => {
StringMapWrapper.forEach(
<{[key: string]: string | number}>entry,
(value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
if (prop != 'offset') {
keyframeStyles[prop] = value;
}
});
Object.keys(entry).forEach(prop => {
const value: any = (entry as{[key: string]: string | number})[prop];
if (prop != 'offset') {
keyframeStyles[prop] = value;
}
});
});

if (isPresent(offset)) {
Expand Down Expand Up @@ -381,24 +380,24 @@ function _parseAnimationKeyframes(
let entry = rawKeyframes[i];
let styles = entry[1];

StringMapWrapper.forEach(
styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
if (!isPresent(firstKeyframeStyles[prop])) {
firstKeyframeStyles[prop] = FILL_STYLE_FLAG;
}
});
Object.keys(styles).forEach(prop => {
const value = styles[prop];
if (!isPresent(firstKeyframeStyles[prop])) {
firstKeyframeStyles[prop] = FILL_STYLE_FLAG;
}
});
}

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

StringMapWrapper.forEach(
styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
if (!isPresent(lastKeyframeStyles[prop])) {
lastKeyframeStyles[prop] = value;
}
});
Object.keys(styles).forEach(prop => {
const value = styles[prop];
if (!isPresent(lastKeyframeStyles[prop])) {
lastKeyframeStyles[prop] = value;
}
});
}

return rawKeyframes.map(
Expand All @@ -423,10 +422,10 @@ function _parseTransitionAnimation(
entry.styles.forEach(stylesEntry => {
// by this point we know that we only have stringmap values
var map = <{[key: string]: string | number}>stylesEntry;
StringMapWrapper.forEach(
map, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
collectedStyles.insertAtTime(prop, time, value);
});
Object.keys(map).forEach(prop => {
const value = map[prop];
collectedStyles.insertAtTime(prop, time, value);
});
});
previousStyles = entry.styles;
return;
Expand Down Expand Up @@ -484,9 +483,10 @@ function _parseTransitionAnimation(

keyframes.forEach(
(keyframe: any /** TODO #9100 */) => keyframe.styles.styles.forEach(
(entry: any /** TODO #9100 */) => StringMapWrapper.forEach(
entry, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) =>
collectedStyles.insertAtTime(prop, currentTime, value))));
(entry: any /** TODO #9100 */) => Object.keys(entry).forEach(prop => {
const value = entry[prop];
collectedStyles.insertAtTime(prop, currentTime, value)
})));
} else {
// if the code reaches this stage then an error
// has already been populated within the _normalizeStyleSteps()
Expand Down Expand Up @@ -562,7 +562,8 @@ function _createStartKeyframeFromEndKeyframe(
var values: {[key: string]: string | number} = {};
var endTime = startTime + duration;
endKeyframe.styles.styles.forEach((styleData: {[key: string]: string | number}) => {
StringMapWrapper.forEach(styleData, (val: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
Object.keys(styleData).forEach(prop => {
const val = styleData[prop];
if (prop == 'offset') return;

var resultIndex = collectedStyles.indexOfAtOrBeforeTime(prop, startTime);
Expand Down
3 changes: 2 additions & 1 deletion modules/@angular/compiler/src/compile_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
var hostProperties: {[key: string]: string} = {};
var hostAttributes: {[key: string]: string} = {};
if (isPresent(host)) {
StringMapWrapper.forEach(host, (value: string, key: string) => {
Object.keys(host).forEach(key => {
const value = host[key];
const matches = key.match(HOST_REG_EXP);
if (matches === null) {
hostAttributes[key] = value;
Expand Down
3 changes: 2 additions & 1 deletion modules/@angular/compiler/src/output/value_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class _ValueOutputAstTransformer implements ValueTransformer {

visitStringMap(map: {[key: string]: any}, type: o.MapType): o.Expression {
var entries: Array<string|o.Expression>[] = [];
StringMapWrapper.forEach(map, (value: any, key: string) => {
Object.keys(map).forEach(key => {
const value = map[key];
entries.push([key, visitValue(value, this, null)]);
});
return o.literalMap(entries, type);
Expand Down
12 changes: 8 additions & 4 deletions modules/@angular/compiler/src/template_parser/template_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ class TemplateParseVisitor implements html.Visitor {
elementName: string, hostProps: {[key: string]: string}, sourceSpan: ParseSourceSpan,
targetPropertyAsts: BoundElementPropertyAst[]) {
if (hostProps) {
StringMapWrapper.forEach(hostProps, (expression: string, propName: string) => {
Object.keys(hostProps).forEach(propName => {
const expression = hostProps[propName];
if (isString(expression)) {
const exprAst = this._parseBinding(expression, sourceSpan);
targetPropertyAsts.push(
Expand All @@ -850,7 +851,8 @@ class TemplateParseVisitor implements html.Visitor {
hostListeners: {[key: string]: string}, sourceSpan: ParseSourceSpan,
targetEventAsts: BoundEventAst[]) {
if (hostListeners) {
StringMapWrapper.forEach(hostListeners, (expression: string, propName: string) => {
Object.keys(hostListeners).forEach(propName => {
const expression = hostListeners[propName];
if (isString(expression)) {
this._parseEventOrAnimationEvent(propName, expression, sourceSpan, [], targetEventAsts);
} else {
Expand All @@ -875,7 +877,8 @@ class TemplateParseVisitor implements html.Visitor {
}
});

StringMapWrapper.forEach(directiveProperties, (elProp: string, dirProp: string) => {
Object.keys(directiveProperties).forEach(dirProp => {
const elProp = directiveProperties[dirProp];
const boundProp = boundPropsByName.get(elProp);

// Bindings are optional, so this binding only needs to be set up if an expression is given.
Expand Down Expand Up @@ -1047,7 +1050,8 @@ class TemplateParseVisitor implements html.Visitor {
const allDirectiveEvents = new Set<string>();

directives.forEach(directive => {
StringMapWrapper.forEach(directive.directive.outputs, (eventName: string) => {
Object.keys(directive.directive.outputs).forEach(k => {
const eventName = directive.directive.outputs[k];
allDirectiveEvents.add(eventName);
});
});
Expand Down
3 changes: 2 additions & 1 deletion modules/@angular/compiler/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class ValueTransformer implements ValueVisitor {
}
visitStringMap(map: {[key: string]: any}, context: any): any {
var result = {};
StringMapWrapper.forEach(map, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
Object.keys(map).forEach(key => {
const value = map[key];
(result as any /** TODO #9100 */)[key] = visitValue(value, this, context);
});
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ export class CompileElement extends CompileNode {
queriesWithReads,
queriesForProvider.map(query => new _QueryWithRead(query, resolvedProvider.token)));
});
StringMapWrapper.forEach(this.referenceTokens, (_: CompileTokenMetadata, varName: string) => {
Object.keys(this.referenceTokens).forEach(varName => {
const _ = this.referenceTokens[varName];
var token = this.referenceTokens[varName];
var varValue: o.Expression;
if (isPresent(token)) {
Expand Down
13 changes: 6 additions & 7 deletions modules/@angular/compiler/src/view_compiler/event_binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,12 @@ export function collectEventListeners(
export function bindDirectiveOutputs(
directiveAst: DirectiveAst, directiveInstance: o.Expression,
eventListeners: CompileEventListener[]) {
StringMapWrapper.forEach(
directiveAst.directive.outputs,
(eventName: any /** TODO #9100 */, observablePropName: any /** TODO #9100 */) => {
eventListeners.filter(listener => listener.eventName == eventName).forEach((listener) => {
listener.listenToDirective(directiveInstance, observablePropName);
});
});
Object.keys(directiveAst.directive.outputs).forEach(observablePropName => {
const eventName = directiveAst.directive.outputs[observablePropName];
eventListeners.filter(listener => listener.eventName == eventName).forEach((listener) => {
listener.listenToDirective(directiveInstance, observablePropName);
});
});
}

export function bindRenderOutputs(eventListeners: CompileEventListener[]) {
Expand Down
22 changes: 13 additions & 9 deletions modules/@angular/compiler/src/view_compiler/view_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,13 @@ function _mergeHtmlAndDirectiveAttrs(
declaredHtmlAttrs: {[key: string]: string},
directives: CompileDirectiveMetadata[]): string[][] {
var result: {[key: string]: string} = {};
StringMapWrapper.forEach(
declaredHtmlAttrs, (value: string, key: string) => { result[key] = value; });
Object.keys(declaredHtmlAttrs).forEach(key => {
const value = declaredHtmlAttrs[key];
result[key] = value;
});
directives.forEach(directiveMeta => {
StringMapWrapper.forEach(directiveMeta.hostAttributes, (value: string, name: string) => {
Object.keys(directiveMeta.hostAttributes).forEach(name => {
const value = directiveMeta.hostAttributes[name];
var prevValue = result[name];
result[name] = isPresent(prevValue) ? mergeAttributeValue(name, prevValue, value) : value;
});
Expand All @@ -373,7 +376,8 @@ function mergeAttributeValue(attrName: string, attrValue1: string, attrValue2: s

function mapToKeyValueArray(data: {[key: string]: string}): string[][] {
var entryArray: string[][] = [];
StringMapWrapper.forEach(data, (value: string, name: string) => {
Object.keys(data).forEach(name => {
const value = data[name];
entryArray.push([name, value]);
});
// We need to sort to get a defined output order
Expand Down Expand Up @@ -421,11 +425,11 @@ function createStaticNodeDebugInfo(node: CompileNode): o.Expression {
if (isPresent(compileElement.component)) {
componentToken = createDiTokenExpression(identifierToken(compileElement.component.type));
}
StringMapWrapper.forEach(
compileElement.referenceTokens, (token: CompileTokenMetadata, varName: string) => {
varTokenEntries.push(
[varName, isPresent(token) ? createDiTokenExpression(token) : o.NULL_EXPR]);
});
Object.keys(compileElement.referenceTokens).forEach(varName => {
const token = compileElement.referenceTokens[varName];
varTokenEntries.push(
[varName, isPresent(token) ? createDiTokenExpression(token) : o.NULL_EXPR]);
});
}
return o.importExpr(resolveIdentifier(Identifiers.StaticNodeDebugInfo))
.instantiate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ export function main() {
describe('parseAnimationEntry', () => {
var combineStyles = (styles: AnimationStylesAst): {[key: string]: string | number} => {
var flatStyles: {[key: string]: string | number} = {};
styles.styles.forEach(
entry => StringMapWrapper.forEach(
entry, (val: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
flatStyles[prop] = val;
}));
styles.styles.forEach(entry => Object.keys(entry).forEach(prop => {
const val = entry[prop];
flatStyles[prop] = val;
}));
return flatStyles;
};

Expand Down

0 comments on commit 610a769

Please sign in to comment.