From df3b47f3d044aea3a58e368b3dca9624c5d49c1c Mon Sep 17 00:00:00 2001 From: Antoine du HAMEL Date: Sun, 24 May 2020 12:15:37 +0200 Subject: [PATCH 1/2] modules: runtime deprecate module.parent --- doc/api/deprecations.md | 8 ++++- doc/api/modules.md | 4 +-- lib/internal/modules/cjs/loader.js | 29 +++++++++++++------ test/fixtures/cjs-module-parent.js | 5 ++++ ...nt-deprecation-no-warning-for-cjs-users.js | 7 +++++ ...rent-deprecation-warning-for-esm-users.mjs | 7 +++++ .../test-module-parent-deprecation.js | 3 +- .../test-module-parent-pending-deprecation.js | 15 ++++++++++ 8 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/cjs-module-parent.js create mode 100644 test/parallel/test-module-parent-deprecation-no-warning-for-cjs-users.js create mode 100644 test/parallel/test-module-parent-deprecation-warning-for-esm-users.mjs create mode 100644 test/parallel/test-module-parent-pending-deprecation.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index fa2f52c8265c2f..f3f1f718c47132 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2612,6 +2612,9 @@ no longer required due to simplification of the implementation. ### DEP0144: `module.parent` -Type: Documentation-only (supports [`--pending-deprecation`][]) +Type: Runtime (supports [`--pending-deprecation`][]) A CommonJS module can access the first module that required it using `module.parent`. This feature is deprecated because it does not work @@ -2643,6 +2646,9 @@ const moduleParents = Object.values(require.cache) .filter((m) => m.children.includes(module)); ``` +Without `--pending-deprecation`, runtime warnings occur only when this property +is accessed from a module that have a nullish value for their `module.parent`. + ### DEP0145: `socket.bufferSize`