Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Avoid _.get.

Anders Kaseorg392676d4da6e
diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js
index e292ffc0aa9..7331ba2625b 100644
--- a/static/js/typeahead_helper.js
+++ b/static/js/typeahead_helper.js
@@ -260,7 +260,7 @@ function retain_unique_language_aliases(matches) {
for (const lang of matches) {
// The matched list is already sorted based on popularity and has exact matches
// at the top, so we don't need to worry about sorting again.
- const canonical_name = _.get(pygments_data.langs, [lang, "pretty_name"], lang);
+ const canonical_name = pygments_data.langs[lang]?.pretty_name ?? lang;
if (!seen_aliases.has(canonical_name)) {
seen_aliases.add(canonical_name);
unique_aliases.push(lang);
diff --git a/static/shared/js/fenced_code.js b/static/shared/js/fenced_code.js
index e8c64e97bb9..d7fd066f73a 100644
--- a/static/shared/js/fenced_code.js
+++ b/static/shared/js/fenced_code.js
@@ -46,7 +46,7 @@ export function wrap_code(code, lang) {
// the `/shared` folder. To handle such a case we check if pygments data is empty and fallback to
// using the default header if it is.
if (lang !== undefined && lang !== "" && Object.keys(pygments_data).length > 0) {
- const code_language = _.get(pygments_data, [lang, "pretty_name"], lang);
+ const code_language = pygments_data[lang]?.pretty_name ?? lang;
header = `<div class="codehilite" data-code-language="${_.escape(
code_language,
)}"><pre><span></span><code>`;