Add code quality test, remove all constructor.name entries as they are unreadable after minification

This commit is contained in:
Pieter Vander Vennet 2022-02-14 02:26:03 +01:00
parent 312dbe7aff
commit 1c418e5a49
15 changed files with 95 additions and 52 deletions

View file

@ -19,6 +19,7 @@ import {PrepareTheme} from "../Models/ThemeConfig/Conversion/PrepareTheme";
import * as licenses from "../assets/generated/license_info.json"
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
import {FixImages} from "../Models/ThemeConfig/Conversion/FixImages";
import Svg from "../Svg";
export default class DetermineLayout {
@ -73,6 +74,8 @@ export default class DetermineLayout {
userLayoutParam: UIEventSource<string>
): LayoutConfig | null {
let hash = location.hash.substr(1);
let json: any;
try {
// layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
const dedicatedHashFromLocalStorage = LocalStorageSource.Get(
@ -95,7 +98,6 @@ export default class DetermineLayout {
dedicatedHashFromLocalStorage.setData(hash);
}
let json: any;
try {
json = JSON.parse(atob(hash));
} catch (e) {
@ -115,23 +117,26 @@ export default class DetermineLayout {
} catch (e) {
console.error(e)
if (hash === undefined || hash.length < 10) {
DetermineLayout.ShowErrorOnCustomTheme("Could not load a theme from the hash", new FixedUiElement("Hash does not contain data"))
DetermineLayout.ShowErrorOnCustomTheme("Could not load a theme from the hash", new FixedUiElement("Hash does not contain data"), json)
}
this.ShowErrorOnCustomTheme("Could not parse the hash", new FixedUiElement(e))
this.ShowErrorOnCustomTheme("Could not parse the hash", new FixedUiElement(e), json)
return null;
}
}
public static ShowErrorOnCustomTheme(
intro: string = "Error: could not parse the custom layout:",
error: BaseUIElement) {
error: BaseUIElement,
json?: any) {
new Combine([
intro,
error.SetClass("alert"),
new SubtleButton("./assets/svg/mapcomplete_logo.svg",
new SubtleButton(Svg.back_svg(),
"Go back to the theme overview",
{url: window.location.protocol + "//" + window.location.hostname + "/index.html", newTab: false})
{url: window.location.protocol + "//" + window.location.hostname + "/index.html", newTab: false}),
json !== undefined ? new SubtleButton(Svg.download_svg(),"Download the JSON file").onClick(() => {
Utils.offerContentsAsDownloadableFile(JSON.stringify(json, null, " "), "theme_definition.json")
}) : undefined
])
.SetClass("flex flex-col clickable")
.AttachTo("centermessage");
@ -189,7 +194,8 @@ export default class DetermineLayout {
console.error(e)
DetermineLayout.ShowErrorOnCustomTheme(
`<a href="${link}">${link}</a> is invalid:`,
new FixedUiElement(e)
new FixedUiElement(e),
parsed
)
return null;
}

View file

@ -413,7 +413,6 @@ export class ExtraFunctions {
const elems = []
for (const func of ExtraFunctions.allFuncs) {
console.log("Generating ", func.constructor.name)
elems.push(new Title(func._name, 3),
func._doc,
new List(func._args ?? [], true))

View file

@ -35,7 +35,7 @@ export default abstract class ImageProvider {
}): UIEventSource<ProvidedImage[]> {
const prefixes = options?.prefixes ?? this.defaultKeyPrefixes
if (prefixes === undefined) {
throw "The image provider" + this.constructor.name + " doesn't define `defaultKeyPrefixes`"
throw "No `defaultKeyPrefixes` defined by this image provider"
}
const relevantUrls = new UIEventSource<{ url: string; key: string; provider: ImageProvider }[]>([])
const seenValues = new Set<string>()

View file

@ -23,7 +23,7 @@ export default abstract class OsmChangeAction {
public Perform(changes: Changes) {
if (this.isUsed) {
throw "This ChangeAction is already used: " + this.constructor.name
throw "This ChangeAction is already used"
}
this.isUsed = true;
return this.CreateChangeDescriptions(changes)