Skip to content

Commit aaf225a

Browse files
committed
module: add setter for module.parent
PR-URL: #35522 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 30fb4a0 commit aaf225a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

doc/api/modules.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ deprecated:
913913

914914
The module that first required this one, or `null` if the current module is the
915915
entry point of the current process, or `undefined` if the module was loaded by
916-
something that is not a CommonJS module (E.G.: REPL or `import`). Read only.
916+
something that is not a CommonJS module (E.G.: REPL or `import`).
917917

918918
### `module.path`
919919
<!-- YAML

lib/internal/modules/cjs/loader.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,24 @@ ObjectDefineProperty(Module, 'wrapper', {
223223
function getModuleParent() {
224224
return moduleParentCache.get(this);
225225
}
226+
227+
function setModuleParent(value) {
228+
moduleParentCache.set(this, value);
229+
}
230+
226231
ObjectDefineProperty(Module.prototype, 'parent', {
227232
get: pendingDeprecation ? deprecate(
228233
getModuleParent,
229234
'module.parent is deprecated due to accuracy issues. Please use ' +
230235
'require.main to find program entry point instead.',
231236
'DEP0144'
232-
) : getModuleParent
237+
) : getModuleParent,
238+
set: pendingDeprecation ? deprecate(
239+
setModuleParent,
240+
'module.parent is deprecated due to accuracy issues. Please use ' +
241+
'require.main to find program entry point instead.',
242+
'DEP0144'
243+
) : setModuleParent,
233244
});
234245

235246
let debug = require('internal/util/debuglog').debuglog('module', (fn) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Flags: --pending-deprecation
2+
3+
'use strict';
4+
const common = require('../common');
5+
6+
common.expectWarning(
7+
'DeprecationWarning',
8+
'module.parent is deprecated due to accuracy issues. Please use ' +
9+
'require.main to find program entry point instead.',
10+
'DEP0144'
11+
);
12+
13+
module.parent = undefined;

0 commit comments

Comments
 (0)