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 06da8a7

Browse filesBrowse files
bmeckMylesBorins
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 4667c5e commit 06da8a7
Copy full SHA for 06da8a7

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
@@ -572,15 +572,21 @@ Module.prototype.load = function(filename) {
572572
if (ESMLoader) {
573573
const url = getURLFromFilePath(filename);
574574
const urlString = `${url}`;
575+
const exports = this.exports;
575576
if (ESMLoader.moduleMap.has(urlString) !== true) {
576-
const ctx = createDynamicModule(['default'], url);
577-
ctx.reflect.exports.default.set(this.exports);
578-
ESMLoader.moduleMap.set(urlString,
579-
new ModuleJob(ESMLoader, url, async () => ctx));
577+
ESMLoader.moduleMap.set(
578+
urlString,
579+
new ModuleJob(ESMLoader, url, async () => {
580+
const ctx = createDynamicModule(
581+
['default'], url);
582+
ctx.reflect.exports.default.set(exports);
583+
return ctx;
584+
})
585+
);
580586
} else {
581587
const job = ESMLoader.moduleMap.get(urlString);
582588
if (job.reflect)
583-
job.reflect.exports.default.set(this.exports);
589+
job.reflect.exports.default.set(exports);
584590
}
585591
}
586592
};

0 commit comments

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