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( |     public convert( | ||||||
|         spec: string | any, |         spec: string | { "builtin": string | string[] } | (TagRenderingConfigJson), | ||||||
|         ctx: ConversionContext |         ctx: ConversionContext | ||||||
|     ): QuestionableTagRenderingConfigJson[] { |     ): 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) |             this.pruneMappings<TagRenderingConfigJson & { id: string }>(tr, ctx) | ||||||
|         ) |         ) | ||||||
|         if (!Array.isArray(trs)) { |         if (!Array.isArray(trs)) { | ||||||
|  | @ -123,7 +124,7 @@ export class ExpandTagRendering extends Conversion< | ||||||
|                 } |                 } | ||||||
|                 return { |                 return { | ||||||
|                     ...mapping, |                     ...mapping, | ||||||
|                     if: newIf.asJson(), |                     if: newIf.asJson() | ||||||
|                 } |                 } | ||||||
|             }) |             }) | ||||||
|         const after = newMappings?.length ?? 0 |         const after = newMappings?.length ?? 0 | ||||||
|  | @ -136,7 +137,7 @@ export class ExpandTagRendering extends Conversion< | ||||||
|         } |         } | ||||||
|         const tr = { |         const tr = { | ||||||
|             ...tagRendering, |             ...tagRendering, | ||||||
|             mappings: newMappings, |             mappings: newMappings | ||||||
|         } |         } | ||||||
|         delete tr["strict"] |         delete tr["strict"] | ||||||
|         return tr |         return tr | ||||||
|  | @ -155,17 +156,17 @@ export class ExpandTagRendering extends Conversion< | ||||||
|         for (const tagRenderingConfigJson of direct) { |         for (const tagRenderingConfigJson of direct) { | ||||||
|             const nm: string | string[] | undefined = tagRenderingConfigJson["builtin"] |             const nm: string | string[] | undefined = tagRenderingConfigJson["builtin"] | ||||||
|             if (nm !== undefined) { |             if (nm !== undefined) { | ||||||
|                 let indirect: TagRenderingConfigJson[] |                 let indirect: (TagRenderingConfigJson & { id: string })[] | ||||||
|                 if (typeof nm === "string") { |                 if (typeof nm === "string") { | ||||||
|                     indirect = this.lookup(nm, ctx) |                     indirect = this.lookup(nm, ctx) | ||||||
|                 } else { |                 } else { | ||||||
|                     indirect = [].concat(...nm.map((n) => this.lookup(n, ctx))) |                     indirect = [].concat(...nm.map((n) => this.lookup(n, ctx))) | ||||||
|                 } |                 } | ||||||
|                 for (let foundTr of indirect) { |                 for (let foundTr of indirect) { | ||||||
|                     foundTr = Utils.Clone<any>(foundTr) |                     foundTr = Utils.Clone(foundTr) | ||||||
|                     ctx.MergeObjectsForOverride(tagRenderingConfigJson["override"] ?? {}, foundTr) |                     ctx.MergeObjectsForOverride(tagRenderingConfigJson["override"] ?? {}, foundTr) | ||||||
|                     foundTr["id"] = tagRenderingConfigJson["id"] ?? foundTr["id"] |                     foundTr["id"] = tagRenderingConfigJson["id"] ?? foundTr["id"] | ||||||
|                     result.push(<any>foundTr) |                     result.push(foundTr) | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 result.push(tagRenderingConfigJson) |                 result.push(tagRenderingConfigJson) | ||||||
|  | @ -248,11 +249,15 @@ export class ExpandTagRendering extends Conversion< | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private convertOnce( |     private convertOnce( | ||||||
|         tr: string | any, |         tr: string | { "builtin": string } | TagRenderingConfigJson, | ||||||
|         ctx: ConversionContext |         ctx: ConversionContext | ||||||
|     ): (TagRenderingConfigJson & { id: string })[] { |     ): TagRenderingConfigJson[] { | ||||||
|         const state = this._state |         const state = this._state | ||||||
| 
 | 
 | ||||||
|  |         if (tr === undefined) { | ||||||
|  |             return [] | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         if (typeof tr === "string") { |         if (typeof tr === "string") { | ||||||
|             if (this._state.tagRenderings !== null) { |             if (this._state.tagRenderings !== null) { | ||||||
|                 const lookup = this.lookup(tr, ctx) |                 const lookup = this.lookup(tr, ctx) | ||||||
|  | @ -268,25 +273,25 @@ export class ExpandTagRendering extends Conversion< | ||||||
|                 ctx.warn( |                 ctx.warn( | ||||||
|                     `A literal rendering was detected: ${tr} |                     `A literal rendering was detected: ${tr} | ||||||
|                       Did you perhaps forgot to add a layer name as 'layername.${tr}'? ` +
 |                       Did you perhaps forgot to add a layer name as 'layername.${tr}'? ` +
 | ||||||
|                         Array.from(state.sharedLayers.keys()).join(", ") |                     Array.from(state.sharedLayers.keys()).join(", ") | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (this._options?.noHardcodedStrings && this._state?.sharedLayers?.size > 0) { |             if (this._options?.noHardcodedStrings && this._state?.sharedLayers?.size > 0) { | ||||||
|                 ctx.err( |                 ctx.err( | ||||||
|                     "Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " + |                     "Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " + | ||||||
|                         tr + |                     tr + | ||||||
|                         " \n    Did you perhaps forget to add the layer as prefix, such as `icons." + |                     " \n    Did you perhaps forget to add the layer as prefix, such as `icons." + | ||||||
|                         tr + |                     tr + | ||||||
|                         "`? " |                     "`? " | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return [ |             return [ | ||||||
|                 <any>{ |                 <TagRenderingConfigJson & { id: string }>{ | ||||||
|                     render: tr, |                     render: tr, | ||||||
|                     id: tr.replace(/[^a-zA-Z0-9]/g, ""), |                     id: tr.replace(/[^a-zA-Z0-9]/g, "") | ||||||
|                 }, |                 } | ||||||
|             ] |             ] | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -311,9 +316,9 @@ export class ExpandTagRendering extends Conversion< | ||||||
|                 } |                 } | ||||||
|                 ctx.err( |                 ctx.err( | ||||||
|                     "An object calling a builtin can only have keys `builtin` or `override`, but a key with name `" + |                     "An object calling a builtin can only have keys `builtin` or `override`, but a key with name `" + | ||||||
|                         key + |                     key + | ||||||
|                         "` was found. This won't be picked up! The full object is: " + |                     "` was found. This won't be picked up! The full object is: " + | ||||||
|                         JSON.stringify(tr) |                     JSON.stringify(tr) | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | @ -340,19 +345,19 @@ export class ExpandTagRendering extends Conversion< | ||||||
|                             if (state.sharedLayers.size === 0) { |                             if (state.sharedLayers.size === 0) { | ||||||
|                                 ctx.warn( |                                 ctx.warn( | ||||||
|                                     "BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " + |                                     "BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " + | ||||||
|                                         name + |                                     name + | ||||||
|                                         ": layer " + |                                     ": layer " + | ||||||
|                                         layerName + |                                     layerName + | ||||||
|                                         " not found for now, but ignoring as this is a bootstrapping run. " |                                     " not found for now, but ignoring as this is a bootstrapping run. " | ||||||
|                                 ) |                                 ) | ||||||
|                             } else { |                             } else { | ||||||
|                                 ctx.err( |                                 ctx.err( | ||||||
|                                     ": While reusing tagrendering: " + |                                     ": While reusing tagrendering: " + | ||||||
|                                         name + |                                     name + | ||||||
|                                         ": layer " + |                                     ": layer " + | ||||||
|                                         layerName + |                                     layerName + | ||||||
|                                         " not found. Maybe you meant one of " + |                                     " not found. Maybe you meant one of " + | ||||||
|                                         candidates.slice(0, 3).join(", ") |                                     candidates.slice(0, 3).join(", ") | ||||||
|                                 ) |                                 ) | ||||||
|                             } |                             } | ||||||
|                             continue |                             continue | ||||||
|  | @ -364,15 +369,15 @@ export class ExpandTagRendering extends Conversion< | ||||||
|                     candidates = Utils.sortedByLevenshteinDistance(name, candidates, (i) => i) |                     candidates = Utils.sortedByLevenshteinDistance(name, candidates, (i) => i) | ||||||
|                     ctx.err( |                     ctx.err( | ||||||
|                         "The tagRendering with identifier " + |                         "The tagRendering with identifier " + | ||||||
|                             name + |                         name + | ||||||
|                             " was not found.\n\tDid you mean one of " + |                         " was not found.\n\tDid you mean one of " + | ||||||
|                             candidates.join(", ") + |                         candidates.join(", ") + | ||||||
|                             "?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first" |                         "?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first" | ||||||
|                     ) |                     ) | ||||||
|                     continue |                     continue | ||||||
|                 } |                 } | ||||||
|                 for (let foundTr of lookup) { |                 for (let foundTr of lookup) { | ||||||
|                     foundTr = Utils.Clone<any>(foundTr) |                     foundTr = Utils.Clone(foundTr) | ||||||
|                     ctx.MergeObjectsForOverride(tr["override"] ?? {}, foundTr) |                     ctx.MergeObjectsForOverride(tr["override"] ?? {}, foundTr) | ||||||
|                     if (names.length == 1) { |                     if (names.length == 1) { | ||||||
|                         foundTr["id"] = tr["id"] ?? foundTr["id"] |                         foundTr["id"] = tr["id"] ?? foundTr["id"] | ||||||
|  | @ -383,6 +388,6 @@ export class ExpandTagRendering extends Conversion< | ||||||
|             return trs |             return trs | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return [tr] |         return [<TagRenderingConfigJson & { id: string }>tr] | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue