forked from MapComplete/MapComplete
Chore: typing, formatting
This commit is contained in:
parent
244c976af6
commit
add464f58f
1 changed files with 40 additions and 35 deletions
|
@ -59,10 +59,11 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
|
||||
public convert(
|
||||
spec: string | any,
|
||||
spec: string | { "builtin": string | string[] } | (TagRenderingConfigJson),
|
||||
ctx: ConversionContext
|
||||
): QuestionableTagRenderingConfigJson[] {
|
||||
const trs = this.convertOnce(spec, ctx)?.map((tr) =>
|
||||
|
||||
const trs = this.convertOnce(<any>spec, ctx)?.map((tr) =>
|
||||
this.pruneMappings<TagRenderingConfigJson & { id: string }>(tr, ctx)
|
||||
)
|
||||
if (!Array.isArray(trs)) {
|
||||
|
@ -123,7 +124,7 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
return {
|
||||
...mapping,
|
||||
if: newIf.asJson(),
|
||||
if: newIf.asJson()
|
||||
}
|
||||
})
|
||||
const after = newMappings?.length ?? 0
|
||||
|
@ -136,7 +137,7 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
const tr = {
|
||||
...tagRendering,
|
||||
mappings: newMappings,
|
||||
mappings: newMappings
|
||||
}
|
||||
delete tr["strict"]
|
||||
return tr
|
||||
|
@ -155,17 +156,17 @@ export class ExpandTagRendering extends Conversion<
|
|||
for (const tagRenderingConfigJson of direct) {
|
||||
const nm: string | string[] | undefined = tagRenderingConfigJson["builtin"]
|
||||
if (nm !== undefined) {
|
||||
let indirect: TagRenderingConfigJson[]
|
||||
let indirect: (TagRenderingConfigJson & { id: string })[]
|
||||
if (typeof nm === "string") {
|
||||
indirect = this.lookup(nm, ctx)
|
||||
} else {
|
||||
indirect = [].concat(...nm.map((n) => this.lookup(n, ctx)))
|
||||
}
|
||||
for (let foundTr of indirect) {
|
||||
foundTr = Utils.Clone<any>(foundTr)
|
||||
foundTr = Utils.Clone(foundTr)
|
||||
ctx.MergeObjectsForOverride(tagRenderingConfigJson["override"] ?? {}, foundTr)
|
||||
foundTr["id"] = tagRenderingConfigJson["id"] ?? foundTr["id"]
|
||||
result.push(<any>foundTr)
|
||||
result.push(foundTr)
|
||||
}
|
||||
} else {
|
||||
result.push(tagRenderingConfigJson)
|
||||
|
@ -248,11 +249,15 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
|
||||
private convertOnce(
|
||||
tr: string | any,
|
||||
tr: string | { "builtin": string } | TagRenderingConfigJson,
|
||||
ctx: ConversionContext
|
||||
): (TagRenderingConfigJson & { id: string })[] {
|
||||
): TagRenderingConfigJson[] {
|
||||
const state = this._state
|
||||
|
||||
if (tr === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
if (typeof tr === "string") {
|
||||
if (this._state.tagRenderings !== null) {
|
||||
const lookup = this.lookup(tr, ctx)
|
||||
|
@ -283,10 +288,10 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
|
||||
return [
|
||||
<any>{
|
||||
<TagRenderingConfigJson & { id: string }>{
|
||||
render: tr,
|
||||
id: tr.replace(/[^a-zA-Z0-9]/g, ""),
|
||||
},
|
||||
id: tr.replace(/[^a-zA-Z0-9]/g, "")
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -372,7 +377,7 @@ export class ExpandTagRendering extends Conversion<
|
|||
continue
|
||||
}
|
||||
for (let foundTr of lookup) {
|
||||
foundTr = Utils.Clone<any>(foundTr)
|
||||
foundTr = Utils.Clone(foundTr)
|
||||
ctx.MergeObjectsForOverride(tr["override"] ?? {}, foundTr)
|
||||
if (names.length == 1) {
|
||||
foundTr["id"] = tr["id"] ?? foundTr["id"]
|
||||
|
@ -383,6 +388,6 @@ export class ExpandTagRendering extends Conversion<
|
|||
return trs
|
||||
}
|
||||
|
||||
return [tr]
|
||||
return [<TagRenderingConfigJson & { id: string }>tr]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue