fix(static-module-record)!: Remove reliance on Map in scope of preamble
MODIFY
packages/static-module-record/src/transform-analyze.js
packages/static-module-record/src/transform-analyze.js
@@ -114,14 +114,14 @@ const makeCreateStaticRecord = transformSource =>
}
const js = JSON.stringify;
const isrc = sourceOptions.importSources;
- preamble += `${h.HIDDEN_IMPORTS}(new Map([${Object.keys(isrc)
+ preamble += `${h.HIDDEN_IMPORTS}([${Object.keys(isrc)
.map(
src =>
- `[${js(src)}, new Map([${Object.entries(isrc[src])
+ `[${js(src)}, [${Object.entries(isrc[src])
.map(([exp, upds]) => `[${js(exp)}, [${upds.join(',')}]]`)
- .join(',')}])]`,
+ .join(',')}]]`,
)
- .join(',')}]));`;
+ .join(',')}]);`;
preamble += sourceOptions.hoistedDecls
.map(([vname, isOnce, cvname]) => {
let src = '';

MODIFY
packages/static-module-record/test/test-static-module-record.js
packages/static-module-record/test/test-static-module-record.js
@@ -115,14 +115,12 @@ function initialize(t, source, options = {}) {
* @param {ImportUpdaters} newUpdaters
*/
function updateImports(newUpdaters) {
- for (const [module, moduleUpdaters] of Array.from(newUpdaters.entries())) {
+ for (const [module, moduleUpdaters] of newUpdaters) {
const moduleImports = imports.get(module);
const testUpdaters = new Map();
updaters.set(module, testUpdaters);
if (moduleImports) {
- for (const [importName, importUpdaters] of Array.from(
- moduleUpdaters.entries(),
- )) {
+ for (const [importName, importUpdaters] of moduleUpdaters) {
/** @param {any} value */
const updateImport = value => {
for (const importUpdater of importUpdaters) {
@@ -671,3 +669,8 @@ test('export name as default from', t => {
default: ['meaning', false],
});
});
+
+// Regression test for #823
+test('static module records can name Map in scope', t => {
+ t.notThrows(() => initialize(t, `const { Map } = globalThis;`));
+});

fix(static-module-record)!: Remove reliance on Map in scope of preamble