aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/to-javascript.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/to-javascript.js')
-rw-r--r--src/to-javascript.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/to-javascript.js b/src/to-javascript.js
index 237ef1e..0acf180 100644
--- a/src/to-javascript.js
+++ b/src/to-javascript.js
@@ -74,11 +74,20 @@ function makeJS(psModule, psModuleMap, js) {
74 74
75 const result = js 75 const result = js
76 .replace(requireRE, (m, p1) => { 76 .replace(requireRE, (m, p1) => {
77 const escapedPath = jsStringEscape(psModuleMap[p1].src); 77 const moduleValue = psModuleMap[p1];
78 78
79 replacedImports.push(p1); 79 if (!moduleValue) {
80 debug('module %s was not found in the map, replacing require with null', p1);
80 81
81 return `require("${escapedPath}")`; 82 return 'null';
83 }
84 else {
85 const escapedPath = jsStringEscape(moduleValue.src);
86
87 replacedImports.push(p1);
88
89 return `require("${escapedPath}")`;
90 }
82 }) 91 })
83 .replace(foreignRE, () => { 92 .replace(foreignRE, () => {
84 const escapedPath = jsStringEscape(psModuleMap[name].ffi); 93 const escapedPath = jsStringEscape(psModuleMap[name].ffi);
@@ -87,13 +96,11 @@ function makeJS(psModule, psModuleMap, js) {
87 }) 96 })
88 ; 97 ;
89 98
90 debug('imports %o', imports);
91
92 debug('replaced imports %o', replacedImports);
93
94 const additionalImports = difference(imports, replacedImports); 99 const additionalImports = difference(imports, replacedImports);
95 100
96 debug('additional imports for %s: %o', name, additionalImports); 101 if (additionalImports.length) {
102 debug('additional imports for %s: %o', name, additionalImports);
103 }
97 104
98 const additionalImportsResult = additionalImports.map(import_ => { 105 const additionalImportsResult = additionalImports.map(import_ => {
99 const escapedPath = jsStringEscape(psModuleMap[import_].src); 106 const escapedPath = jsStringEscape(psModuleMap[import_].src);