diff --git a/common/web/types/src/kmx/element-string.ts b/common/web/types/src/kmx/element-string.ts index 816627c3d3..ebf4d398e5 100644 --- a/common/web/types/src/kmx/element-string.ts +++ b/common/web/types/src/kmx/element-string.ts @@ -31,11 +31,11 @@ export class ElementString extends Array { * @param source if a string array, does not get reinterpreted as UnicodeSet. This is used with vars, etc. Or pass `["str"]` for an explicit 1-element elem. * If it is a string, will be interpreted per reorder element rules. */ - constructor(sections: DependencySections, source: string | string[], order?: string, tertiary?: string, tertiary_base?: string, prebase?: string) { - super(); - //TODO-LDML: full UnicodeSet and parsing + static fromStrings(sections: DependencySections, source: string | string[], order?: string, tertiary?: string, tertiary_base?: string, prebase?: string) : ElementString { + // the returned array + const array = new ElementString(); if(!source) { - return; + return array; } let items : ElementSegment[]; @@ -104,8 +104,9 @@ export class ElementString extends Array { (ElemElementFlags.type & typeFlag) | (tertiary_bases?.[i] == '1' /* TODO-LDML: or 'true'? */ ? ElemElementFlags.tertiary_base : 0) | (prebases?.[i] == '1' /* TODO-LDML: or 'true'? */ ? ElemElementFlags.prebase : 0); - this.push(elem); + array.push(elem); }; + return array; } isEqual(a: ElementString): boolean { if (a.length != this.length) { diff --git a/common/web/types/src/kmx/kmx-plus.ts b/common/web/types/src/kmx/kmx-plus.ts index d28bcbfd3f..1060e50fba 100644 --- a/common/web/types/src/kmx/kmx-plus.ts +++ b/common/web/types/src/kmx/kmx-plus.ts @@ -35,14 +35,14 @@ export class Elem extends Section { strings: ElementString[] = []; constructor(sections: DependencySections) { super(); - this.strings.push(new ElementString(sections, '')); // C7043: null element string + this.strings.push(ElementString.fromStrings(sections, '')); // C7043: null element string } /** * @param source if a string array, does not get reinterpreted as UnicodeSet. This is used with vars, etc. Or pass `["str"]` for an explicit 1-element elem. * If it is a string, will be interpreted per reorder element ruls. */ allocElementString(sections: DependencySections, source: string | string[], order?: string, tertiary?: string, tertiary_base?: string, prebase?: string): ElementString { - let s = new ElementString(sections, source, order, tertiary, tertiary_base, prebase); + let s = ElementString.fromStrings(sections, source, order, tertiary, tertiary_base, prebase); let result = this.strings.find(item => item.isEqual(s)); if(result === undefined) { result = s; @@ -547,14 +547,14 @@ export class List extends Section { let result = this.lists.find(item => item.isEqual(s)); if(result === undefined) { // allocate a new ListItem - result = new ListItem(s, opts, sections); + result = ListItem.fromStrings(s, opts, sections); this.lists.push(result); } return result; } constructor(strs: Strs) { super(); - this.lists.push(new ListItem([], {}, { strs })); // C7043: null element string + this.lists.push(ListItem.fromStrings([], {}, { strs })); // C7043: null element string } lists: ListItem[] = []; }; diff --git a/common/web/types/src/kmx/string-list.ts b/common/web/types/src/kmx/string-list.ts index 2e313dae0c..411c940acf 100644 --- a/common/web/types/src/kmx/string-list.ts +++ b/common/web/types/src/kmx/string-list.ts @@ -33,15 +33,16 @@ export class ListItem extends Array implements OrderedStringList { * be needed depending on the options * @returns */ - constructor(source: Array, opts: StrsOptions, sections: DependencySections) { - super(); - if(!source) { - return; + static fromStrings(source: Array, opts: StrsOptions, sections: DependencySections) : ListItem { + const a = new ListItem(); + if (!source) { + return a; } for (const str of source) { let index = new ListIndex(sections.strs.allocString(str, opts, sections)); - this.push(index); + a.push(index); } + return a; } getItemOrder(item: string): number { return this.findIndex(({value}) => value.value === item);