js: Convert static/js/filter.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 15:45:40 -08:00 committed by Tim Abbott
parent 16668904c1
commit cfacf68fb8
33 changed files with 46 additions and 35 deletions

View File

@ -125,7 +125,6 @@
"files": ["static/js/**"],
"globals": {
"$": false,
"Filter": false,
"MessageListView": false,
"activity": false,
"admin": false,

View File

@ -13,7 +13,7 @@ zrequire("unread");
const stream_data = zrequire("stream_data");
const people = zrequire("people");
zrequire("message_util", "js/message_util");
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const me = {
email: "me@example.com",

View File

@ -20,7 +20,7 @@ set_global("location", {
const hash_util = zrequire("hash_util");
const stream_data = zrequire("stream_data");
const people = zrequire("people");
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const narrow_state = zrequire("narrow_state");
const hamlet = {

View File

@ -50,7 +50,7 @@ const stream_list = set_global("stream_list", {
rewiremock.enable();
const message_fetch = zrequire("message_fetch");
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const message_list = zrequire("message_list");
const people = zrequire("people");

View File

@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
@ -13,7 +15,9 @@ const $ = require("../zjsunit/zjquery");
const noop = function () {};
set_global("Filter", noop);
rewiremock("../../static/js/filter").with({
Filter: noop,
});
set_global("document", {
to_$() {
return {
@ -28,6 +32,8 @@ set_global("recent_topics", {
is_visible: () => false,
});
rewiremock.enable();
const muting = zrequire("muting");
zrequire("MessageListView", "js/message_list_view");
const {MessageList} = zrequire("message_list");
@ -440,3 +446,4 @@ run_test("add_remove_rerender", () => {
assert.equal(list.num_items(), 0);
}
});
rewiremock.disable();

View File

@ -14,7 +14,6 @@ set_global("setTimeout", (f, delay) => {
const muting = zrequire("muting");
zrequire("unread");
zrequire("Filter", "js/filter");
const {MessageListData} = zrequire("MessageListData", "js/message_list_data");
function make_msg(msg_id) {

View File

@ -47,7 +47,7 @@ rewiremock("../../static/js/rows").with({
rewiremock.enable();
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const MessageListView = zrequire("MessageListView", "js/message_list_view");
const message_list = zrequire("message_list");

View File

@ -21,7 +21,7 @@ const narrow_state = zrequire("narrow_state");
const people = zrequire("people");
const stream_data = zrequire("stream_data");
const stream_topic_history = set_global("stream_topic_history", {});
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const narrow = zrequire("narrow");
function set_filter(operators) {

View File

@ -68,7 +68,6 @@ rewiremock.enable();
const util = zrequire("util");
const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
zrequire("Filter", "js/filter");
zrequire("unread");
const narrow = zrequire("narrow");

View File

@ -14,7 +14,7 @@ rewiremock("../../static/js/muting").with({
rewiremock.enable();
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const {MessageListData} = zrequire("MessageListData", "js/message_list_data");
const narrow_state = zrequire("narrow_state");
const narrow = zrequire("narrow");

View File

@ -8,7 +8,7 @@ const {run_test} = require("../zjsunit/test");
set_global("page_params", {});
const people = zrequire("people");
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const stream_data = zrequire("stream_data");
const narrow_state = zrequire("narrow_state");

View File

@ -16,7 +16,7 @@ rewiremock("../../static/js/muting").with({
rewiremock.enable();
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const people = zrequire("people");
const stream_data = zrequire("stream_data");
const unread = zrequire("unread");

View File

@ -29,7 +29,7 @@ set_global("setTimeout", (func) => func());
const search = zrequire("search");
const search_pill = zrequire("search_pill");
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
zrequire("message_view_header");
run_test("clear_search_form", () => {

View File

@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
@ -18,10 +20,16 @@ set_global("ui_util", {
change_tab_to: noop,
});
const narrow = set_global("narrow", {});
const Filter = set_global("Filter", {});
const Filter = {};
rewiremock("../../static/js/filter").with({
Filter,
});
set_global("setTimeout", (func) => func());
rewiremock.enable();
const search = zrequire("search");
zrequire("message_view_header");
@ -293,3 +301,4 @@ run_test("initiate_search", () => {
search.initiate_search();
assert.equal($("#search_query").val(), "ver ");
});
rewiremock.disable();

View File

@ -7,7 +7,6 @@ const {run_test} = require("../zjsunit/test");
const search_pill = zrequire("search_pill");
const input_pill = zrequire("input_pill");
zrequire("Filter", "js/filter");
const is_starred_item = {
display_value: "is:starred",

View File

@ -22,7 +22,6 @@ page_params.realm_email_address_visibility =
const huddle_data = zrequire("huddle_data");
zrequire("typeahead_helper");
zrequire("Filter", "js/filter");
const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");

View File

@ -20,7 +20,6 @@ page_params.realm_email_address_visibility =
const huddle_data = zrequire("huddle_data");
zrequire("typeahead_helper");
zrequire("Filter", "js/filter");
const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");

View File

@ -19,7 +19,6 @@ const stream_topic_history = zrequire("stream_topic_history");
const people = zrequire("people");
const stream_color = zrequire("stream_color");
const stream_data = zrequire("stream_data");
zrequire("Filter", "js/filter");
zrequire("MessageListView", "js/message_list_view");
const message_list = zrequire("message_list");
const settings_config = zrequire("settings_config");

View File

@ -39,7 +39,7 @@ const peer_data = zrequire("peer_data");
const people = zrequire("people");
const stream_data = zrequire("stream_data");
const stream_events = zrequire("stream_events");
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const narrow_state = zrequire("narrow_state");
const message_view_header = zrequire("message_view_header");

View File

@ -29,7 +29,7 @@ rewiremock("../../static/js/keydown_util").with({
rewiremock.enable();
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const stream_sort = zrequire("stream_sort");
const stream_color = zrequire("stream_color");
zrequire("hash_util");

View File

@ -12,7 +12,7 @@ set_global("resize", {
resize_stream_filters_container: () => {},
});
rewiremock.enable();
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
const people = zrequire("people");
const top_left_corner = zrequire("top_left_corner");

View File

@ -187,7 +187,7 @@ run_test("unread", () => {
// We use the second argument of zrequire to find the location of the
// Filter class.
const Filter = zrequire("Filter", "js/filter");
const {Filter} = zrequire("Filter", "js/filter");
run_test("filter", () => {
const filter_terms = [

View File

@ -20,7 +20,6 @@ import "../setup";
import "../unread_ops";
import "../unread";
import "../stream_list";
import "../filter";
import "../poll_widget";
import "../widgetize";
import "../submessage";

View File

@ -1,10 +1,8 @@
"use strict";
import Handlebars from "handlebars/runtime";
import _ from "lodash";
const Handlebars = require("handlebars/runtime");
const _ = require("lodash");
const people = require("./people");
const util = require("./util");
import * as people from "./people";
import * as util from "./util";
function zephyr_stream_name_match(message, operand) {
// Zephyr users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/
@ -174,7 +172,7 @@ function message_matches_search_term(message, operator, operand) {
return true; // unknown operators return true (effectively ignored)
}
class Filter {
export class Filter {
constructor(operators) {
if (operators === undefined) {
this._operators = [];
@ -982,7 +980,3 @@ class Filter {
return Handlebars.Utils.escapeExpression(Filter.describe_unescaped(operators));
}
}
module.exports = Filter;
window.Filter = Filter;

View File

@ -3,7 +3,6 @@
// remove each declaration when the corresponding module is migrated
// to TS.
declare let Filter: any;
declare let MessageListView: any;
declare let activity: any;
declare let admin: any;

View File

@ -1,6 +1,7 @@
"use strict";
const channel = require("./channel");
const {Filter} = require("./filter");
const huddle_data = require("./huddle_data");
const people = require("./people");
const pm_list = require("./pm_list");

View File

@ -1,6 +1,7 @@
import _ from "lodash";
import {FetchStatus} from "./fetch_status";
import {Filter} from "./filter";
import * as muting from "./muting";
import * as util from "./util";

View File

@ -1,6 +1,7 @@
"use strict";
const channel = require("./channel");
const {Filter} = require("./filter");
const {MessageListData} = require("./message_list_data");
const people = require("./people");
const search_pill = require("./search_pill");

View File

@ -1,5 +1,6 @@
"use strict";
const {Filter} = require("./filter");
const people = require("./people");
let current_filter;

View File

@ -1,5 +1,6 @@
"use strict";
const {Filter} = require("./filter");
const search_pill = require("./search_pill");
// Exported for unit testing

View File

@ -1,3 +1,5 @@
import {Filter} from "./filter";
export function create_item_from_search_string(search_string) {
const operator = Filter.parse(search_string);
const description = Filter.describe(operator);

View File

@ -3,6 +3,7 @@
const Handlebars = require("handlebars/runtime");
const common = require("./common");
const {Filter} = require("./filter");
const huddle_data = require("./huddle_data");
const people = require("./people");
const settings_data = require("./settings_data");

View File

@ -1,5 +1,7 @@
"use strict";
const {Filter} = require("./filter");
// This file is being eliminated as part of the general purge of
// global variables from Zulip (everything is being moved into
// modules). Please don't add things here.