aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCyril Sobierajewicz <38043722+cyrilfretlink@users.noreply.github.com>2019-05-24 14:46:35 +0200
committereric <thul.eric@gmail.com>2019-05-24 08:46:35 -0400
commit1cdd37e8b40999c91233a8cc9e0b3ab278b5a219 (patch)
treeb2ec80939cb086f00ee3055482d33c9859fcdad4
parentf5a2abb1da6068203698255c123f097979443b6b (diff)
downloadpurs-loader-1cdd37e8b40999c91233a8cc9e0b3ab278b5a219.tar.gz
purs-loader-1cdd37e8b40999c91233a8cc9e0b3ab278b5a219.tar.zst
purs-loader-1cdd37e8b40999c91233a8cc9e0b3ab278b5a219.zip
Don’t unnecessarily invalidate the module map (#124)
* Don’t unnecessarily invalidate the module map Additional imports in PureScript sources (compared to their JavaScript output) shouldn’t always invalidate the module map because imports of types are erased and re-exports are followed. Also `Prim.*` modules are internal to the compiler and won’t ever be present in the module map. * Don’t add imports to unused modules Otherwise the following expression ```purs hello :: Effect Unit hello = log "Hello" ``` includes the whole `Prelude` into its chunk whereas only `log` is actually needed at runtime.
-rw-r--r--src/to-javascript.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/to-javascript.js b/src/to-javascript.js
index a7d64a2..3663c83 100644
--- a/src/to-javascript.js
+++ b/src/to-javascript.js
@@ -109,12 +109,21 @@ function makeJS(psModule, psModuleMap, js) {
109 return Promise.resolve(result); 109 return Promise.resolve(result);
110 } 110 }
111 else { 111 else {
112 debug('rebuilding module map due to additional imports for %s: %o', name, additionalImports); 112 const missingImports = additionalImports.filter(moduleName =>
113 113 !psModuleMap[moduleName] && moduleName.split('.')[0] !== 'Prim'
114 psModule.cache.psModuleMap = null; 114 );
115 115
116 return updatePsModuleMap(psModule).then(updatedPsModuleMap => { 116 let updatingPsModuleMap;
117 const additionalImportsResult = additionalImports.map(import_ => { 117 if (missingImports.length > 0) {
118 debug('rebuilding module map due to missing imports for %s: %o', name, missingImports);
119 psModule.cache.psModuleMap = null;
120 updatingPsModuleMap = updatePsModuleMap(psModule);
121 } else {
122 updatingPsModuleMap = Promise.resolve(psModuleMap);
123 }
124
125 return updatingPsModuleMap.then(updatedPsModuleMap => {
126 const missingImportsResult = missingImports.map(import_ => {
118 const moduleValue = updatedPsModuleMap[import_]; 127 const moduleValue = updatedPsModuleMap[import_];
119 128
120 if (!moduleValue) { 129 if (!moduleValue) {
@@ -129,7 +138,7 @@ function makeJS(psModule, psModuleMap, js) {
129 } 138 }
130 }).filter(a => a !== null).join('\n'); 139 }).filter(a => a !== null).join('\n');
131 140
132 return result + '\n' + additionalImportsResult; 141 return result + '\n' + missingImportsResult;
133 }); 142 });
134 } 143 }
135} 144}