feat(static-module-record): Make source location argument optional
This is necessary because, currently, we need to add the source URL
notation to a module functor in compartment-mapper after the source URL
has been canonicalized, which happens long after the initial analysis of
the source.
MODIFY
packages/static-module-record/src/static-module-record.js
packages/static-module-record/src/static-module-record.js
@@ -15,7 +15,7 @@ const analyzeModule = makeModuleAnalyzer(babel);
* @param {string} source
* @param {string} [url]
*/
-export function StaticModuleRecord(source, url = '<unknown>') {
+export function StaticModuleRecord(source, url) {
if (new.target === undefined) {
throw new TypeError(
"Class constructor StaticModuleRecord cannot be invoked without 'new'",

MODIFY
packages/static-module-record/src/transform-analyze.js
packages/static-module-record/src/transform-analyze.js
@@ -121,7 +121,7 @@ const makeCreateStaticRecord = transformSource =>
.map(([exp, upds]) => `[${js(exp)}, [${upds.join(',')}]]`)
.join(',')}])]`,
)
- .join(',')}]), ${js(sourceOptions.exportAlls)});`;
+ .join(',')}]));`;
preamble += sourceOptions.hoistedDecls
.map(([vname, cvname]) => {
let src = '';
@@ -143,7 +143,7 @@ const makeCreateStaticRecord = transformSource =>
// It must also be strict to enforce strictness of modules.
// We use destructuring parameters, so 'use strict' is not allowed
// but the function actually is strict.
- const functorSource = `\
+ let functorSource = `\
(({ \
imports: ${h.HIDDEN_IMPORTS}, \
liveVar: ${h.HIDDEN_LIVE}, \
@@ -152,7 +152,11 @@ const makeCreateStaticRecord = transformSource =>
${preamble} \
${scriptSource}
})
-//# sourceURL=${url}`;
+`;
+
+ if (url) {
+ functorSource += `//# sourceURL=${url}\n`;
+ }
const moduleAnalysis = freeze({
exportAlls: freeze(sourceOptions.exportAlls),

feat(static-module-record): Make source location argument optional

This is necessary because, currently, we need to add the source URL
notation to a module functor in compartment-mapper after the source URL
has been canonicalized, which happens long after the initial analysis of
the source.