Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/input_pill.js to ES6 module.
Anders Kaseorg7ec3fc38faa3
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 95b7c76543d..95fff91c05d 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -137,7 +137,6 @@"history": false,"home_msg_list": false,"i18n": false,- "input_pill": false,"jQuery": false,"localStorage": false,"location": false,diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex 77777fe2be8..a53ff0013b9 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -107,7 +107,6 @@ const rtl = zrequire("rtl");const stream_data = zrequire("stream_data");const compose_state = zrequire("compose_state");const people = zrequire("people");-zrequire("input_pill");const compose_pm_pill = zrequire("compose_pm_pill");const echo = zrequire("echo");const compose = zrequire("compose");diff --git a/frontend_tests/node_tests/compose_pm_pill.js b/frontend_tests/node_tests/compose_pm_pill.jsindex 5336ec982c5..7e757b42482 100644--- a/frontend_tests/node_tests/compose_pm_pill.js+++ b/frontend_tests/node_tests/compose_pm_pill.js@@ -122,7 +122,7 @@ run_test("pills", (override) => {return pills;}- input_pill.create = input_pill_stub;+ input_pill.__Rewire__("create", input_pill_stub);// We stub the return value of input_pill.create(), manually add widget functions to it.pills.onPillCreate = (callback) => {diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.jsindex bb6c9e88214..c906f7ed027 100644--- a/frontend_tests/node_tests/input_pill.js+++ b/frontend_tests/node_tests/input_pill.js@@ -31,10 +31,10 @@ run_test("set_up_ids", () => {// just get coverage on a simple one-liner:input_pill.random_id();- input_pill.random_id = () => {+ input_pill.__Rewire__("random_id", () => {id_seq += 1;return "some_id" + id_seq;- };+ });});function pill_html(value, data_id, img_src) {diff --git a/frontend_tests/node_tests/search_pill.js b/frontend_tests/node_tests/search_pill.jsindex 33eb140ba40..dab3858bbaf 100644--- a/frontend_tests/node_tests/search_pill.js+++ b/frontend_tests/node_tests/search_pill.js@@ -73,10 +73,10 @@ run_test("get_items", () => {run_test("create_pills", () => {let input_pill_create_called = false;- input_pill.create = () => {+ input_pill.__Rewire__("create", () => {input_pill_create_called = true;return {dummy: "dummy"};- };+ });const pills = search_pill.create_pills({});assert(input_pill_create_called);diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.jsindex cb5aa97485d..d520e8765d5 100644--- a/frontend_tests/node_tests/settings_user_groups.js+++ b/frontend_tests/node_tests/settings_user_groups.js@@ -38,7 +38,9 @@ const ui_report = {__esModule: true};rewiremock("../../static/js/ui_report").with(ui_report);const page_params = set_global("page_params", {});-const input_pill = set_global("input_pill", {});+const input_pill = {__esModule: true};++rewiremock("../../static/js/input_pill").with(input_pill);rewiremock.enable();diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.jsindex 482e7355665..03528e1ba17 100644--- a/frontend_tests/node_tests/stream_edit.js+++ b/frontend_tests/node_tests/stream_edit.js@@ -35,7 +35,6 @@ const ui = set_global("ui", {rewiremock.enable();-zrequire("input_pill");const peer_data = zrequire("peer_data");const people = zrequire("people");zrequire("subs");diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex f20fac312ca..7518d04430b 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -15,7 +15,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";// Import app JSimport "../i18n";import "../fold_dict";-import "../input_pill";import "../setup";import "../unread_ops";import "../unread";diff --git a/static/js/compose_pm_pill.js b/static/js/compose_pm_pill.jsindex 207a6aa4f46..16c2c3bdadd 100644--- a/static/js/compose_pm_pill.js+++ b/static/js/compose_pm_pill.js@@ -1,3 +1,4 @@+import * as input_pill from "./input_pill";import * as people from "./people";import * as user_pill from "./user_pill";import * as util from "./util";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex a5ddd778c39..6b70652fadc 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -12,7 +12,6 @@ declare let emoji: any;declare let favicon: any;declare let home_msg_list: any;declare let i18n: any;-declare let input_pill: any;declare let message_events: any;declare let message_list: any;declare let narrow: any;diff --git a/static/js/input_pill.js b/static/js/input_pill.jsindex 430efd8c5b9..7808466eda0 100644--- a/static/js/input_pill.js+++ b/static/js/input_pill.js@@ -1,15 +1,13 @@-"use strict";+import render_input_pill from "../templates/input_pill.hbs";-const render_input_pill = require("../templates/input_pill.hbs");--const ui_util = require("./ui_util");+import * as ui_util from "./ui_util";// See https://zulip.readthedocs.io/en/latest/subsystems/input-pills.html-exports.random_id = function () {+export function random_id() {return Math.random().toString(16);-};+}-exports.create = function (opts) {+export function create(opts) {// a dictionary of the key codes that are associated with each key// to make if/else more human readable.const KEY = {@@ -86,7 +84,7 @@ exports.create = function (opts) {// This is generally called by typeahead logic, where we have all// the data we need (as opposed to, say, just a user-typed email).appendValidatedData(item) {- const id = exports.random_id();+ const id = random_id();if (!item.display_value) {blueslip.error("no display_value returned");@@ -403,6 +401,4 @@ exports.create = function (opts) {};return prototype;-};--window.input_pill = exports;+}diff --git a/static/js/search_pill.js b/static/js/search_pill.jsindex 6d60fcc03c3..ab60181b0ba 100644--- a/static/js/search_pill.js+++ b/static/js/search_pill.js@@ -1,4 +1,5 @@import {Filter} from "./filter";+import * as input_pill from "./input_pill";export function create_item_from_search_string(search_string) {const operator = Filter.parse(search_string);diff --git a/static/js/stream_edit.js b/static/js/stream_edit.jsindex 75d8ec4242d..5e6274d1da9 100644--- a/static/js/stream_edit.js+++ b/static/js/stream_edit.js@@ -7,6 +7,7 @@ import render_subscription_stream_privacy_modal from "../templates/subscription_import * as channel from "./channel";import * as hash_util from "./hash_util";import * as hashchange from "./hashchange";+import * as input_pill from "./input_pill";import * as ListWidget from "./list_widget";import * as narrow_state from "./narrow_state";import * as overlays from "./overlays";diff --git a/static/js/user_pill.js b/static/js/user_pill.jsindex 35e821de058..dd4d455744b 100644--- a/static/js/user_pill.js+++ b/static/js/user_pill.js@@ -1,3 +1,4 @@+import * as input_pill from "./input_pill";import * as people from "./people";// This will be used for pills for things like composing PMs