refactor(compiler): use Object.keys instead of Object.getOwnPropertyNames (#10498)
This commit is contained in:
parent
fd19671c07
commit
cd18de7a21
|
@ -87,8 +87,8 @@ export class NgPlural {
|
||||||
_updateView(): void {
|
_updateView(): void {
|
||||||
this._clearViews();
|
this._clearViews();
|
||||||
|
|
||||||
var key = getPluralCategory(
|
var key =
|
||||||
this._switchValue, Object.getOwnPropertyNames(this._caseViews), this._localization);
|
getPluralCategory(this._switchValue, Object.keys(this._caseViews), this._localization);
|
||||||
this._activateView(this._caseViews[key]);
|
this._activateView(this._caseViews[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ export class I18nPluralPipe implements PipeTransform {
|
||||||
throw new InvalidPipeArgumentException(I18nPluralPipe, pluralMap);
|
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());
|
return StringWrapper.replaceAll(pluralMap[key], _INTERPOLATION_REGEXP, value.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,8 +96,7 @@ export class PlaceholderRegistry {
|
||||||
// Generate a hash for a tag - does not take attribute order into account
|
// Generate a hash for a tag - does not take attribute order into account
|
||||||
private _hashTag(tag: string, attrs: {[k: string]: string}, isVoid: boolean): string {
|
private _hashTag(tag: string, attrs: {[k: string]: string}, isVoid: boolean): string {
|
||||||
const start = `<${tag}`;
|
const start = `<${tag}`;
|
||||||
const strAttrs =
|
const strAttrs = Object.keys(attrs).sort().map((name) => ` ${name}=${attrs[name]}`).join('');
|
||||||
Object.getOwnPropertyNames(attrs).sort().map((name) => ` ${name}=${attrs[name]}`).join('');
|
|
||||||
const end = isVoid ? '/>' : `></${tag}>`;
|
const end = isVoid ? '/>' : `></${tag}>`;
|
||||||
|
|
||||||
return start + strAttrs + end;
|
return start + strAttrs + end;
|
||||||
|
|
|
@ -44,7 +44,7 @@ export class Xmb implements Serializer {
|
||||||
let rootNode = new xml.Tag(_MESSAGES_TAG);
|
let rootNode = new xml.Tag(_MESSAGES_TAG);
|
||||||
rootNode.children.push(new xml.Text('\n'));
|
rootNode.children.push(new xml.Text('\n'));
|
||||||
|
|
||||||
Object.getOwnPropertyNames(messageMap).forEach((id) => {
|
Object.keys(messageMap).forEach((id) => {
|
||||||
const message = messageMap[id];
|
const message = messageMap[id];
|
||||||
let attrs: {[k: string]: string} = {id};
|
let attrs: {[k: string]: string} = {id};
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class _Visitor implements i18n.Visitor {
|
||||||
visitIcu(icu: i18n.Icu, context?: any): xml.Node[] {
|
visitIcu(icu: i18n.Icu, context?: any): xml.Node[] {
|
||||||
const nodes = [new xml.Text(`{${icu.expression}, ${icu.type}, `)];
|
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(`}`));
|
nodes.push(new xml.Text(`${c} {`), ...icu.cases[c].visit(this), new xml.Text(`}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,7 @@ class _Visitor implements IVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _serializeAttributes(attrs: {[k: string]: string}) {
|
private _serializeAttributes(attrs: {[k: string]: string}) {
|
||||||
const strAttrs = Object.getOwnPropertyNames(attrs)
|
const strAttrs = Object.keys(attrs).map((name: string) => `${name}="${attrs[name]}"`).join(' ');
|
||||||
.map((name: string) => `${name}="${attrs[name]}"`)
|
|
||||||
.join(' ');
|
|
||||||
return strAttrs.length > 0 ? ' ' + strAttrs : '';
|
return strAttrs.length > 0 ? ' ' + strAttrs : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +53,7 @@ export class Declaration implements Node {
|
||||||
public attrs: {[k: string]: string} = {};
|
public attrs: {[k: string]: string} = {};
|
||||||
|
|
||||||
constructor(unescapedAttrs: {[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]);
|
this.attrs[k] = _escapeXml(unescapedAttrs[k]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -75,7 +73,7 @@ export class Tag implements Node {
|
||||||
constructor(
|
constructor(
|
||||||
public name: string, unescapedAttrs: {[k: string]: string} = {},
|
public name: string, unescapedAttrs: {[k: string]: string} = {},
|
||||||
public children: Node[] = []) {
|
public children: Node[] = []) {
|
||||||
Object.getOwnPropertyNames(unescapedAttrs).forEach((k: string) => {
|
Object.keys(unescapedAttrs).forEach((k: string) => {
|
||||||
this.attrs[k] = _escapeXml(unescapedAttrs[k]);
|
this.attrs[k] = _escapeXml(unescapedAttrs[k]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class Xtb implements Serializer {
|
||||||
let messageMap: {[id: string]: xml.Node[]} = {};
|
let messageMap: {[id: string]: xml.Node[]} = {};
|
||||||
let parseErrors: ParseError[] = [];
|
let parseErrors: ParseError[] = [];
|
||||||
|
|
||||||
Object.getOwnPropertyNames(messages).forEach((id) => {
|
Object.keys(messages).forEach((id) => {
|
||||||
const res = this._htmlParser.parse(messages[id], url, true, this._interpolationConfig);
|
const res = this._htmlParser.parse(messages[id], url, true, this._interpolationConfig);
|
||||||
parseErrors.push(...res.errors);
|
parseErrors.push(...res.errors);
|
||||||
messageMap[id] = res.rootNodes;
|
messageMap[id] = res.rootNodes;
|
||||||
|
|
|
@ -299,7 +299,7 @@ function _humanizePlaceholders(
|
||||||
// clang-format off
|
// clang-format off
|
||||||
// https://github.com/angular/clang-format/issues/35
|
// https://github.com/angular/clang-format/issues/35
|
||||||
return _extractMessages(html, implicitTags, implicitAttrs).map(
|
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
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,7 @@ export function main(): void {
|
||||||
{[id: string]: string} {
|
{[id: string]: string} {
|
||||||
const asAst = serializer.load(content, 'url', placeholders);
|
const asAst = serializer.load(content, 'url', placeholders);
|
||||||
let asText: {[id: string]: string} = {};
|
let asText: {[id: string]: string} = {};
|
||||||
Object.getOwnPropertyNames(asAst).forEach(
|
Object.keys(asAst).forEach(id => { asText[id] = serializeAst(asAst[id]).join(''); });
|
||||||
id => { asText[id] = serializeAst(asAst[id]).join(''); });
|
|
||||||
|
|
||||||
return asText;
|
return asText;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ export function extractSchema(): Map<string, string[]> {
|
||||||
extractProperties(
|
extractProperties(
|
||||||
SVGTextPositioningElement, svgText, visited, descMap, SVG_PREFIX + 'textPositioning',
|
SVGTextPositioningElement, svgText, visited, descMap, SVG_PREFIX + 'textPositioning',
|
||||||
SVG_PREFIX + 'textContent');
|
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')));
|
k => k.endsWith('Element') && (k.startsWith('HTML') || k.startsWith('SVG')));
|
||||||
keys.sort();
|
keys.sort();
|
||||||
keys.forEach(
|
keys.forEach(
|
||||||
|
@ -97,7 +97,7 @@ function extractProperties(
|
||||||
const fullName = name + (superName ? '^' + superName : '');
|
const fullName = name + (superName ? '^' + superName : '');
|
||||||
let props: string[] = descMap.has(fullName) ? descMap.get(fullName) : [];
|
let props: string[] = descMap.has(fullName) ? descMap.get(fullName) : [];
|
||||||
var prototype = type.prototype;
|
var prototype = type.prototype;
|
||||||
var keys = Object.getOwnPropertyNames(prototype);
|
var keys = Object.keys(prototype);
|
||||||
keys.sort();
|
keys.sort();
|
||||||
keys.forEach((n) => {
|
keys.forEach((n) => {
|
||||||
if (n.startsWith('on')) {
|
if (n.startsWith('on')) {
|
||||||
|
|
|
@ -114,14 +114,14 @@ function _serializeReference(ref: any, references: Map<any, string>): string {
|
||||||
function _valueProps(obj: any): string[] {
|
function _valueProps(obj: any): string[] {
|
||||||
const props: string[] = [];
|
const props: string[] = [];
|
||||||
// regular public props
|
// regular public props
|
||||||
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
Object.keys(obj).forEach((prop) => {
|
||||||
if (!prop.startsWith('_')) {
|
if (!prop.startsWith('_')) {
|
||||||
props.push(prop);
|
props.push(prop);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// getters
|
// getters
|
||||||
const proto = Object.getPrototypeOf(obj);
|
const proto = Object.getPrototypeOf(obj);
|
||||||
Object.getOwnPropertyNames(proto).forEach((protoProp) => {
|
Object.keys(proto).forEach((protoProp) => {
|
||||||
var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
|
var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
|
||||||
if (!protoProp.startsWith('_') && desc && 'get' in desc) {
|
if (!protoProp.startsWith('_') && desc && 'get' in desc) {
|
||||||
props.push(protoProp);
|
props.push(protoProp);
|
||||||
|
|
Loading…
Reference in New Issue