Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove prending deprecation for backporting
  • Loading branch information
aduh95 committed Jun 9, 2020
commit c88cca4b48d03ffa24731b0dc7c631b0e557f50d
2 changes: 1 addition & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ changes:
description: Documentation-only deprecation.
-->

Type: Documentation-only (supports [`--pending-deprecation`][])
Type: Documentation-only

A CommonJS module can access the first module that required it using
`module.parent`. This feature is deprecated because it does not work
Expand Down
3 changes: 2 additions & 1 deletion doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ Module {
id: '.',
path: '/absolute/path/to',
exports: {},
parent: null,
filename: '/absolute/path/to/entry.js',
loaded: false,
children: [],
Expand Down Expand Up @@ -903,7 +904,7 @@ deprecated: REPLACEME

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
Expand Down
20 changes: 3 additions & 17 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const {
ReflectSet,
RegExpPrototypeTest,
SafeMap,
SafeWeakMap,
String,
StringPrototypeIndexOf,
StringPrototypeMatch,
Expand Down Expand Up @@ -160,12 +159,11 @@ function updateChildren(parent, child, scan) {
children.push(child);
}

const moduleParentCache = new SafeWeakMap();
function Module(id = '', parent) {
this.id = id;
this.path = path.dirname(id);
this.exports = {};
moduleParentCache.set(this, parent);
this.parent = parent;
updateChildren(parent, this, false);
this.filename = null;
this.loaded = false;
Expand Down Expand Up @@ -234,18 +232,6 @@ ObjectDefineProperty(Module, 'wrapper', {
}
});

function getModuleParent() {
return moduleParentCache.get(this);
}
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.',
'DEP0143'
) : getModuleParent
});

const debug = require('internal/util/debuglog').debuglog('module');
Module._debug = deprecate(debug, 'Module._debug is deprecated.', 'DEP0077');

Expand Down Expand Up @@ -1032,7 +1018,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
const requireStack = [];
for (let cursor = parent;
cursor;
cursor = moduleParentCache.get(cursor)) {
cursor = cursor.parent) {
requireStack.push(cursor.filename || cursor.id);
}
let message = `Cannot find module '${request}'`;
Expand Down Expand Up @@ -1225,7 +1211,7 @@ Module._extensions['.js'] = function(module, filename) {
const pkg = readPackageScope(filename);
// Function require shouldn't be used in ES modules.
if (pkg && pkg.data && pkg.data.type === 'module') {
const parent = moduleParentCache.get(module);
const { parent } = module;
const parentPath = parent && parent.filename;
const packageJsonPath = path.resolve(pkg.path, 'package.json');
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
Expand Down
14 changes: 0 additions & 14 deletions test/parallel/test-module-parent-deprecation.js

This file was deleted.