diff options
Diffstat (limited to 'src/to-javascript.js')
-rw-r--r-- | src/to-javascript.js | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/to-javascript.js b/src/to-javascript.js index 3cc9698..28dde7a 100644 --- a/src/to-javascript.js +++ b/src/to-javascript.js | |||
@@ -59,7 +59,7 @@ function makeBundleJS(psModule) { | |||
59 | 59 | ||
60 | const result = `module.exports = require("${escaped}")["${name}"]`; | 60 | const result = `module.exports = require("${escaped}")["${name}"]`; |
61 | 61 | ||
62 | return result; | 62 | return Promise.resolve(result); |
63 | } | 63 | } |
64 | 64 | ||
65 | // Replace require paths to output files generated by psc with paths | 65 | // Replace require paths to output files generated by psc with paths |
@@ -105,28 +105,33 @@ function makeJS(psModule, psModuleMap, js) { | |||
105 | 105 | ||
106 | const additionalImports = difference(imports, replacedImports); | 106 | const additionalImports = difference(imports, replacedImports); |
107 | 107 | ||
108 | if (additionalImports.length) { | 108 | if (!additionalImports.length) { |
109 | debugVerbose('additional imports for %s: %o', name, additionalImports); | 109 | return Promise.resolve(result); |
110 | } | 110 | } |
111 | else { | ||
112 | debug('rebuilding module map due to additional imports for %s: %o', name, additionalImports); | ||
111 | 113 | ||
112 | const additionalImportsResult = additionalImports.map(import_ => { | 114 | psModule.cache.psModuleMap = null; |
113 | const moduleValue = psModuleMap[import_]; | ||
114 | 115 | ||
115 | if (!moduleValue) { | 116 | return updatePsModuleMap(psModule).then(updatedPsModuleMap => { |
116 | debug('module %s was not found in the map, skipping require', import_); | 117 | const additionalImportsResult = additionalImports.map(import_ => { |
118 | const moduleValue = updatedPsModuleMap[import_]; | ||
117 | 119 | ||
118 | return null; | 120 | if (!moduleValue) { |
119 | } | 121 | debug('module %s was not found in the map, skipping require', import_); |
120 | else { | ||
121 | const escapedPath = jsStringEscape(moduleValue.src); | ||
122 | 122 | ||
123 | return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; | 123 | return null; |
124 | } | 124 | } |
125 | }).filter(a => a !== null).join('\n'); | 125 | else { |
126 | const escapedPath = jsStringEscape(moduleValue.src); | ||
126 | 127 | ||
127 | const result_ = result + (additionalImports.length ? '\n' + additionalImportsResult : ''); | 128 | return `var ${import_.replace(/\./g, '_')} = require("${escapedPath}")`; |
129 | } | ||
130 | }).filter(a => a !== null).join('\n'); | ||
128 | 131 | ||
129 | return result_; | 132 | return result + '\n' + additionalImportsResult; |
133 | }); | ||
134 | } | ||
130 | } | 135 | } |
131 | 136 | ||
132 | module.exports = function toJavaScript(psModule) { | 137 | module.exports = function toJavaScript(psModule) { |