mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
js: Convert static/js/i18n.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
40c3d07b2c
commit
bb1b2048bd
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
exports.t = function (str, context) {
|
||||
exports.i18n = {};
|
||||
exports.i18n.t = function (str, context) {
|
||||
// HAPPY PATH: most translations are a simple string:
|
||||
if (context === undefined) {
|
||||
return "translated: " + str;
|
||||
|
||||
@@ -89,7 +89,8 @@ try {
|
||||
|
||||
namespace.mock_esm("../../static/js/blueslip", blueslip);
|
||||
require("../../static/js/blueslip");
|
||||
namespace.set_global("i18n", stub_i18n);
|
||||
namespace.mock_esm("../../static/js/i18n", stub_i18n);
|
||||
require("../../static/js/i18n");
|
||||
|
||||
run_one_module(file);
|
||||
|
||||
|
||||
@@ -93,6 +93,25 @@ exports.mock_esm = (request, obj = {}) => {
|
||||
return exports.mock_cjs(request, {...obj, __esModule: true});
|
||||
};
|
||||
|
||||
exports.unmock_module = (request) => {
|
||||
const filename = Module._resolveFilename(
|
||||
request,
|
||||
require.cache[callsites()[1].getFileName()],
|
||||
false,
|
||||
);
|
||||
|
||||
if (!module_mocks.has(filename)) {
|
||||
throw new Error(`Cannot unmock ${filename}, which was not mocked`);
|
||||
}
|
||||
|
||||
if (!used_module_mocks.has(filename)) {
|
||||
throw new Error(`You asked to mock ${filename} but we never saw it during compilation.`);
|
||||
}
|
||||
|
||||
module_mocks.delete(filename);
|
||||
used_module_mocks.delete(filename);
|
||||
};
|
||||
|
||||
exports.set_global = function (name, val) {
|
||||
if (val === null) {
|
||||
throw new Error(`
|
||||
|
||||
Reference in New Issue
Block a user