Skip to content

Commit 54896ab

Browse files
aduh95RafaelGSS
authored andcommitted
module: fix unintended mutation
Refs: #46061 (comment) PR-URL: #46108 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 1146f02 commit 54896ab

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎lib/internal/modules/cjs/loader.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
ArrayPrototypeJoin,
3030
ArrayPrototypeMap,
3131
ArrayPrototypePush,
32+
ArrayPrototypePushApply,
3233
ArrayPrototypeSlice,
3334
ArrayPrototypeSplice,
3435
ArrayPrototypeUnshift,
@@ -667,12 +668,11 @@ Module._findPath = function(request, paths, isMain) {
667668
returnfilename;
668669
}
669670

670-
if(exts===undefined){
671-
exts=[''];
672-
}else{
673-
ArrayPrototypeUnshift(exts,'');
671+
constextensions=[''];
672+
if(exts!==undefined){
673+
ArrayPrototypePushApply(extensions,exts);
674674
}
675-
reportModuleNotFoundToWatchMode(basePath,exts);
675+
reportModuleNotFoundToWatchMode(basePath,extensions);
676676
}
677677

678678
returnfalse;

‎test/fixtures/require-resolve.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ assert.strictEqual(
9898
require.resolve('./printA.js',{}),
9999
require.resolve('./printA.js')
100100
);
101+
102+
assert.strictEqual(
103+
require.resolve('no_index/'),
104+
path.join(__dirname,'node_modules','no_index','lib','index.js'),
105+
)

0 commit comments

Comments
 (0)