@@ -39,7 +39,6 @@ const {
3939 ReflectSet,
4040 RegExpPrototypeTest,
4141 SafeMap,
42- SafeWeakMap,
4342 String,
4443 StringPrototypeIndexOf,
4544 StringPrototypeMatch,
@@ -160,12 +159,11 @@ function updateChildren(parent, child, scan) {
160159 children . push ( child ) ;
161160}
162161
163- const moduleParentCache = new SafeWeakMap ( ) ;
164162function Module ( id = '' , parent ) {
165163 this . id = id ;
166164 this . path = path . dirname ( id ) ;
167165 this . exports = { } ;
168- moduleParentCache . set ( this , parent ) ;
166+ this . parent = parent ;
169167 updateChildren ( parent , this , false ) ;
170168 this . filename = null ;
171169 this . loaded = false ;
@@ -234,18 +232,6 @@ ObjectDefineProperty(Module, 'wrapper', {
234232 }
235233} ) ;
236234
237- function getModuleParent ( ) {
238- return moduleParentCache . get ( this ) ;
239- }
240- ObjectDefineProperty ( Module . prototype , 'parent' , {
241- get : pendingDeprecation ? deprecate (
242- getModuleParent ,
243- 'module.parent is deprecated due to accuracy issues. Please use ' +
244- 'require.main to find program entry point instead.' ,
245- 'DEP0143'
246- ) : getModuleParent
247- } ) ;
248-
249235const debug = require ( 'internal/util/debuglog' ) . debuglog ( 'module' ) ;
250236Module . _debug = deprecate ( debug , 'Module._debug is deprecated.' , 'DEP0077' ) ;
251237
@@ -1032,7 +1018,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
10321018 const requireStack = [ ] ;
10331019 for ( let cursor = parent ;
10341020 cursor ;
1035- cursor = moduleParentCache . get ( cursor ) ) {
1021+ cursor = cursor . parent ) {
10361022 requireStack . push ( cursor . filename || cursor . id ) ;
10371023 }
10381024 let message = `Cannot find module '${ request } '` ;
@@ -1225,7 +1211,7 @@ Module._extensions['.js'] = function(module, filename) {
12251211 const pkg = readPackageScope ( filename ) ;
12261212 // Function require shouldn't be used in ES modules.
12271213 if ( pkg && pkg . data && pkg . data . type === 'module' ) {
1228- const parent = moduleParentCache . get ( module ) ;
1214+ const { parent } = module ;
12291215 const parentPath = parent && parent . filename ;
12301216 const packageJsonPath = path . resolve ( pkg . path , 'package.json' ) ;
12311217 throw new ERR_REQUIRE_ESM ( filename , parentPath , packageJsonPath ) ;
0 commit comments