Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da40417

Browse filesBrowse files
bmeckgibfahn
authored andcommitted
module: be lazy when creating CJS facades
This should remove the penalty for loading CJS that is never imported. PR-URL: #17153 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a2c82c3 commit da40417
Copy full SHA for da40417

File tree

Expand file treeCollapse file tree

1 file changed

+11
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-5
lines changed
Open diff view settings
Collapse file

‎lib/module.js‎

Copy file name to clipboardExpand all lines: lib/module.js
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,21 @@ Module.prototype.load = function(filename) {
557557
if (ESMLoader) {
558558
const url = getURLFromFilePath(filename);
559559
const urlString = `${url}`;
560+
const exports = this.exports;
560561
if (ESMLoader.moduleMap.has(urlString) !== true) {
561-
const ctx = createDynamicModule(['default'], url);
562-
ctx.reflect.exports.default.set(this.exports);
563-
ESMLoader.moduleMap.set(urlString,
564-
new ModuleJob(ESMLoader, url, async () => ctx));
562+
ESMLoader.moduleMap.set(
563+
urlString,
564+
new ModuleJob(ESMLoader, url, async () => {
565+
const ctx = createDynamicModule(
566+
['default'], url);
567+
ctx.reflect.exports.default.set(exports);
568+
return ctx;
569+
})
570+
);
565571
} else {
566572
const job = ESMLoader.moduleMap.get(urlString);
567573
if (job.reflect)
568-
job.reflect.exports.default.set(this.exports);
574+
job.reflect.exports.default.set(exports);
569575
}
570576
}
571577
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.