From 678b7544dff10666ba5813196f134c21e6b4d0f7 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 14 May 2018 11:50:59 +0200 Subject: [PATCH] module: introduce defaultModuleName in module.js This commit adds a constant named defaultModuleName to avoid duplicating it in the Module constructor function. PR-URL: https://github.com/nodejs/node/pull/20709 Reviewed-By: Yuta Hiroto Reviewed-By: Trivikram Kamat Reviewed-By: Gus Caplan Reviewed-By: James M Snell --- lib/internal/vm/module.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index 0c9ec87a07b02f..c1dd12f0c15256 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -48,6 +48,7 @@ const linkingStatusMap = new WeakMap(); const initImportMetaMap = new WeakMap(); // ModuleWrap -> vm.Module const wrapToModuleMap = new WeakMap(); +const defaultModuleName = 'vm:module'; class Module { constructor(src, options = {}) { @@ -82,13 +83,13 @@ class Module { } url = new URL(url).href; } else if (context === undefined) { - url = `vm:module(${globalModuleId++})`; + url = `${defaultModuleName}(${globalModuleId++})`; } else if (perContextModuleId.has(context)) { const curId = perContextModuleId.get(context); - url = `vm:module(${curId})`; + url = `${defaultModuleName}(${curId})`; perContextModuleId.set(context, curId + 1); } else { - url = 'vm:module(0)'; + url = `${defaultModuleName}(0)`; perContextModuleId.set(context, 1); }