refactor(compiler): use Object.keys instead of Object.getOwnPropertyNames (#10498)

This commit is contained in:
Marc Laval 2016-08-04 19:35:41 +02:00 committed by Alex Rickabaugh
parent fd19671c07
commit cd18de7a21
11 changed files with 19 additions and 23 deletions

View File

@ -87,8 +87,8 @@ export class NgPlural {
_updateView(): void {
this._clearViews();
var key = getPluralCategory(
this._switchValue, Object.getOwnPropertyNames(this._caseViews), this._localization);
var key =
getPluralCategory(this._switchValue, Object.keys(this._caseViews), this._localization);
this._activateView(this._caseViews[key]);
}

View File

@ -68,7 +68,7 @@ export class I18nPluralPipe implements PipeTransform {
throw new InvalidPipeArgumentException(I18nPluralPipe, pluralMap);
}
const key = getPluralCategory(value, Object.getOwnPropertyNames(pluralMap), this._localization);
const key = getPluralCategory(value, Object.keys(pluralMap), this._localization);
return StringWrapper.replaceAll(pluralMap[key], _INTERPOLATION_REGEXP, value.toString());
}

View File

@ -96,8 +96,7 @@ export class PlaceholderRegistry {
// Generate a hash for a tag - does not take attribute order into account
private _hashTag(tag: string, attrs: {[k: string]: string}, isVoid: boolean): string {
const start = `<${tag}`;
const strAttrs =
Object.getOwnPropertyNames(attrs).sort().map((name) => ` ${name}=${attrs[name]}`).join('');
const strAttrs = Object.keys(attrs).sort().map((name) => ` ${name}=${attrs[name]}`).join('');
const end = isVoid ? '/>' : `></${tag}>`;
return start + strAttrs + end;
@ -120,4 +119,4 @@ export class PlaceholderRegistry {
return name;
}
}
}

View File

@ -44,7 +44,7 @@ export class Xmb implements Serializer {
let rootNode = new xml.Tag(_MESSAGES_TAG);
rootNode.children.push(new xml.Text('\n'));
Object.getOwnPropertyNames(messageMap).forEach((id) => {
Object.keys(messageMap).forEach((id) => {
const message = messageMap[id];
let attrs: {[k: string]: string} = {id};
@ -88,7 +88,7 @@ class _Visitor implements i18n.Visitor {
visitIcu(icu: i18n.Icu, context?: any): xml.Node[] {
const nodes = [new xml.Text(`{${icu.expression}, ${icu.type}, `)];
Object.getOwnPropertyNames(icu.cases).forEach((c: string) => {
Object.keys(icu.cases).forEach((c: string) => {
nodes.push(new xml.Text(`${c} {`), ...icu.cases[c].visit(this), new xml.Text(`}`));
});

View File

@ -32,9 +32,7 @@ class _Visitor implements IVisitor {
}
private _serializeAttributes(attrs: {[k: string]: string}) {
const strAttrs = Object.getOwnPropertyNames(attrs)
.map((name: string) => `${name}="${attrs[name]}"`)
.join(' ');
const strAttrs = Object.keys(attrs).map((name: string) => `${name}="${attrs[name]}"`).join(' ');
return strAttrs.length > 0 ? ' ' + strAttrs : '';
}
@ -55,7 +53,7 @@ export class Declaration implements Node {
public attrs: {[k: string]: string} = {};
constructor(unescapedAttrs: {[k: string]: string}) {
Object.getOwnPropertyNames(unescapedAttrs).forEach((k: string) => {
Object.keys(unescapedAttrs).forEach((k: string) => {
this.attrs[k] = _escapeXml(unescapedAttrs[k]);
});
}
@ -75,7 +73,7 @@ export class Tag implements Node {
constructor(
public name: string, unescapedAttrs: {[k: string]: string} = {},
public children: Node[] = []) {
Object.getOwnPropertyNames(unescapedAttrs).forEach((k: string) => {
Object.keys(unescapedAttrs).forEach((k: string) => {
this.attrs[k] = _escapeXml(unescapedAttrs[k]);
});
}

View File

@ -46,7 +46,7 @@ export class Xtb implements Serializer {
let messageMap: {[id: string]: xml.Node[]} = {};
let parseErrors: ParseError[] = [];
Object.getOwnPropertyNames(messages).forEach((id) => {
Object.keys(messages).forEach((id) => {
const res = this._htmlParser.parse(messages[id], url, true, this._interpolationConfig);
parseErrors.push(...res.errors);
messageMap[id] = res.rootNodes;

View File

@ -299,7 +299,7 @@ function _humanizePlaceholders(
// clang-format off
// https://github.com/angular/clang-format/issues/35
return _extractMessages(html, implicitTags, implicitAttrs).map(
msg => Object.getOwnPropertyNames(msg.placeholders).map((name) => `${name}=${msg.placeholders[name]}`).join(', '));
msg => Object.keys(msg.placeholders).map((name) => `${name}=${msg.placeholders[name]}`).join(', '));
// clang-format on
}

View File

@ -69,4 +69,4 @@ function toXmb(html: string): string {
catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG);
return catalog.write(serializer);
}
}

View File

@ -22,8 +22,7 @@ export function main(): void {
{[id: string]: string} {
const asAst = serializer.load(content, 'url', placeholders);
let asText: {[id: string]: string} = {};
Object.getOwnPropertyNames(asAst).forEach(
id => { asText[id] = serializeAst(asAst[id]).join(''); });
Object.keys(asAst).forEach(id => { asText[id] = serializeAst(asAst[id]).join(''); });
return asText;
}
@ -178,4 +177,4 @@ export function main(): void {
it('should throw when trying to save an xmb file',
() => { expect(() => { serializer.write({}); }).toThrow(); });
});
}
}

View File

@ -55,7 +55,7 @@ export function extractSchema(): Map<string, string[]> {
extractProperties(
SVGTextPositioningElement, svgText, visited, descMap, SVG_PREFIX + 'textPositioning',
SVG_PREFIX + 'textContent');
var keys = Object.getOwnPropertyNames(window).filter(
var keys = Object.keys(window).filter(
k => k.endsWith('Element') && (k.startsWith('HTML') || k.startsWith('SVG')));
keys.sort();
keys.forEach(
@ -97,7 +97,7 @@ function extractProperties(
const fullName = name + (superName ? '^' + superName : '');
let props: string[] = descMap.has(fullName) ? descMap.get(fullName) : [];
var prototype = type.prototype;
var keys = Object.getOwnPropertyNames(prototype);
var keys = Object.keys(prototype);
keys.sort();
keys.forEach((n) => {
if (n.startsWith('on')) {

View File

@ -114,14 +114,14 @@ function _serializeReference(ref: any, references: Map<any, string>): string {
function _valueProps(obj: any): string[] {
const props: string[] = [];
// regular public props
Object.getOwnPropertyNames(obj).forEach((prop) => {
Object.keys(obj).forEach((prop) => {
if (!prop.startsWith('_')) {
props.push(prop);
}
});
// getters
const proto = Object.getPrototypeOf(obj);
Object.getOwnPropertyNames(proto).forEach((protoProp) => {
Object.keys(proto).forEach((protoProp) => {
var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
if (!protoProp.startsWith('_') && desc && 'get' in desc) {
props.push(protoProp);