mirror of https://github.com/nodejs/node.git
module: add setter for module.parent
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
30fb4a015d
commit
aaf225a2a0
|
@ -913,7 +913,7 @@ deprecated:
|
|||
|
||||
The module that first required this one, or `null` if the current module is the
|
||||
entry point of the current process, or `undefined` if the module was loaded by
|
||||
something that is not a CommonJS module (E.G.: REPL or `import`). Read only.
|
||||
something that is not a CommonJS module (E.G.: REPL or `import`).
|
||||
|
||||
### `module.path`
|
||||
<!-- YAML
|
||||
|
|
|
@ -223,13 +223,24 @@ ObjectDefineProperty(Module, 'wrapper', {
|
|||
function getModuleParent() {
|
||||
return moduleParentCache.get(this);
|
||||
}
|
||||
|
||||
function setModuleParent(value) {
|
||||
moduleParentCache.set(this, value);
|
||||
}
|
||||
|
||||
ObjectDefineProperty(Module.prototype, 'parent', {
|
||||
get: pendingDeprecation ? deprecate(
|
||||
getModuleParent,
|
||||
'module.parent is deprecated due to accuracy issues. Please use ' +
|
||||
'require.main to find program entry point instead.',
|
||||
'DEP0144'
|
||||
) : getModuleParent
|
||||
) : getModuleParent,
|
||||
set: pendingDeprecation ? deprecate(
|
||||
setModuleParent,
|
||||
'module.parent is deprecated due to accuracy issues. Please use ' +
|
||||
'require.main to find program entry point instead.',
|
||||
'DEP0144'
|
||||
) : setModuleParent,
|
||||
});
|
||||
|
||||
let debug = require('internal/util/debuglog').debuglog('module', (fn) => {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// Flags: --pending-deprecation
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
common.expectWarning(
|
||||
'DeprecationWarning',
|
||||
'module.parent is deprecated due to accuracy issues. Please use ' +
|
||||
'require.main to find program entry point instead.',
|
||||
'DEP0144'
|
||||
);
|
||||
|
||||
module.parent = undefined;
|
Loading…
Reference in New Issue