Sanity-check decaffeinate app.views.SearchScope

pull/1441/head
Simon Legner 1 year ago
parent bdfea4b186
commit 0c3f1814aa

@ -1,35 +1,20 @@
// TODO: This file was created by bulk-decaffeinate. app.views.SearchScope = class SearchScope extends app.View {
// Sanity-check the conversion and remove this comment. static SEARCH_PARAM = app.config.search_param;
/*
* decaffeinate suggestions: static elements = {
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
* DS206: Consider reworking classes to avoid initClass
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
(function () {
let SEARCH_PARAM = undefined;
let HASH_RGX = undefined;
app.views.SearchScope = class SearchScope extends app.View {
static initClass() {
SEARCH_PARAM = app.config.search_param;
this.elements = {
input: "._search-input", input: "._search-input",
tag: "._search-tag", tag: "._search-tag",
}; };
this.events = { static events = {
click: "onClick", click: "onClick",
keydown: "onKeydown", keydown: "onKeydown",
textInput: "onTextInput", textInput: "onTextInput",
}; };
this.routes = { after: "afterRoute" }; static routes = { after: "afterRoute" };
HASH_RGX = new RegExp(`^#${SEARCH_PARAM}=(.+?) .`); static HASH_RGX = new RegExp(`^#${SearchScope.SEARCH_PARAM}=(.+?) .`);
}
init() { init() {
this.placeholder = this.input.getAttribute("placeholder"); this.placeholder = this.input.getAttribute("placeholder");
@ -173,8 +158,8 @@
let value; let value;
if ((value = this.getHashValue())) { if ((value = this.getHashValue())) {
const newHash = $.urlDecode(location.hash).replace( const newHash = $.urlDecode(location.hash).replace(
`#${SEARCH_PARAM}=${value} `, `#${SearchScope.SEARCH_PARAM}=${value} `,
`#${SEARCH_PARAM}=`, `#${SearchScope.SEARCH_PARAM}=`,
); );
app.router.replaceHash(newHash); app.router.replaceHash(newHash);
return value; return value;
@ -183,10 +168,7 @@
getHashValue() { getHashValue() {
try { try {
return __guard__( return SearchScope.HASH_RGX.exec($.urlDecode(location.hash))?.[1];
HASH_RGX.exec($.urlDecode(location.hash)),
(x) => x[1],
);
} catch (error) {} } catch (error) {}
} }
@ -195,13 +177,4 @@
this.selectDoc(context.doc); this.selectDoc(context.doc);
} }
} }
}; };
app.views.SearchScope.initClass();
return app.views.SearchScope;
})();
function __guard__(value, transform) {
return typeof value !== "undefined" && value !== null
? transform(value)
: undefined;
}

Loading…
Cancel
Save