mirror of https://github.com/zulip/zulip.git
namespace: Recognize immutable ES modules without checking __Rewire__.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
8c60b66a95
commit
aab541bd4e
|
@ -26,26 +26,19 @@ let jquery_function;
|
|||
const template_path = path.resolve(__dirname, "../../templates");
|
||||
|
||||
function load(request, parent, isMain) {
|
||||
let module;
|
||||
|
||||
const filename = Module._resolveFilename(request, parent, isMain);
|
||||
if (module_mocks.has(filename)) {
|
||||
used_module_mocks.add(filename);
|
||||
module = module_mocks.get(filename);
|
||||
return module_mocks.get(filename);
|
||||
} else if (filename.endsWith(".hbs") && filename.startsWith(template_path + path.sep)) {
|
||||
const actual_render = actual_load(request, parent, isMain);
|
||||
module = template_stub({filename, actual_render});
|
||||
return template_stub({filename, actual_render});
|
||||
} else if (filename === jquery_path && parent.filename !== real_jquery_path) {
|
||||
module = jquery_function || $;
|
||||
} else {
|
||||
module = actual_load(request, parent, isMain);
|
||||
return jquery_function || $;
|
||||
}
|
||||
|
||||
if (
|
||||
(typeof module === "object" || typeof module === "function") &&
|
||||
"__esModule" in module &&
|
||||
"__Rewire__" in module
|
||||
) {
|
||||
const module = actual_load(request, parent, isMain);
|
||||
if ((typeof module === "object" || typeof module === "function") && "__esModule" in module) {
|
||||
/* istanbul ignore next */
|
||||
function error_immutable() {
|
||||
throw new Error(`${filename} is an immutable ES module`);
|
||||
|
@ -289,11 +282,6 @@ exports.with_overrides = function (test_function) {
|
|||
`We cannot override a function for ${typeof obj} objects`,
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
!("__esModule" in obj && "__Rewire__" in obj),
|
||||
"Cannot mutate an ES module from outside. Consider exporting a test helper function from it instead.",
|
||||
);
|
||||
|
||||
const had_value = Object.hasOwn(obj, prop);
|
||||
const old_value = obj[prop];
|
||||
let new_value = value;
|
||||
|
|
Loading…
Reference in New Issue