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
fixup: make sure extension symbols are ignored
  • Loading branch information
BridgeAR committed Jan 6, 2019
commit 38afefbbcaad8b987f38b1e746d7216d65bb11d0
6 changes: 3 additions & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,14 @@ function setExtensionsProxy(extensions) {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like an awful lot of work for to avoid Object.keys here.
How much is the win here for just Object.keys? Can we leave this whole Proxy of the Module out and still get the majority of the wins?

return new Proxy(extensions, {
set(obj, prop, value) {
if (extensionCopy[prop] === undefined) {
if (typeof prop !== 'symbol' && extensionCopy[prop] === undefined) {
extensionCopy[prop] = true;
extensionNames.push(prop);
}
return Reflect.set(obj, prop, value);
},
defineProperty(target, prop, descriptor) {
if (extensionCopy[prop] === undefined) {
if (typeof prop !== 'symbol' && extensionCopy[prop] === undefined) {
extensionCopy[prop] = true;
extensionNames.push(prop);
}
Expand All @@ -754,7 +754,7 @@ function setExtensionsProxy(extensions) {
deleteProperty(target, prop) {
const pos = extensionNames.indexOf(prop);
if (pos !== -1) {
extensionCopy[prop] = false;
delete extensionCopy[prop];
extensionNames.splice(pos, 1);
}
return Reflect.deleteProperty(target, prop);
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-module-multi-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ fs.writeFileSync(dotfile, 'console.log(__filename);', 'utf8');
fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');

{
// The Symbol should be ignored.
require.extensions[Symbol()] = common.mustNotCall();
require.extensions['.bar'] = common.mustNotCall();
require.extensions['.foo.bar'] = common.mustCall();
const modulePath = path.join(tmpdir.path, 'test-extensions');
Expand Down