aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/to-javascript.js
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2017-02-25 09:55:18 -0500
committereric thul <thul.eric@gmail.com>2017-02-25 09:55:18 -0500
commit4305f5b0053d6fd2887b364c5da0a1ca6c06fc54 (patch)
tree541cfb21319f8cb6a751132ff0fdb09addfc000f /src/to-javascript.js
parent03f52cb367cc8f1e57c515e4ac61c49cb72773eb (diff)
downloadpurs-loader-4305f5b0053d6fd2887b364c5da0a1ca6c06fc54.tar.gz
purs-loader-4305f5b0053d6fd2887b364c5da0a1ca6c06fc54.tar.zst
purs-loader-4305f5b0053d6fd2887b364c5da0a1ca6c06fc54.zip
Handle missing module and adding debugging
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);