fix(static-module-record): Fix treatment of local vs exported names in test scaffold
MODIFY
packages/static-module-record/DESIGN.md
packages/static-module-record/DESIGN.md
@@ -23,7 +23,8 @@ moduleFunctor({
});
```
-So, for example, the following module uses import and export quite thoroughly.
+So, for example, the following module uses import and export somewhat
+thoroughly.
```js
import foo from 'import-default-export-from-me.js';
@@ -38,6 +39,10 @@ export * from 'import-and-export-all.js';
export default 42;
export const quux = 'Hello, World!';
+const aleph = 0;
+export { aleph as alpha };
+export { grey as gray } from './reexport-name-and-rename.js';
+
// Late binding of an exported variable.
quuux = 'Hello, World!';
```
@@ -54,13 +59,16 @@ the module needs to be linked to and how to link their imports and exports.
"import-named-exports-from-me.js": [ "fizz", "buzz" ],
"import-named-export-and-rename.js": [ "color" ],
"import-and-reexport-name-from-me.js": [ "qux" ],
- "import-and-export-all.js": []
+ "import-and-export-all.js": [],
+ "reexport-name-and-rename.js": [ "grey" ],
},
"liveExportMap": {
+ "gray": [ "grey", false ],
"qux": [ "qux", false ],
"quuux": [ "quuux", true ],
},
"fixedExportMap": {
+ "alpha": [ "aleph" ],
"default": [ "default" ],
"quux": [ "quux" ],
}

MODIFY
packages/static-module-record/src/babelPlugin.js
packages/static-module-record/src/babelPlugin.js
@@ -446,7 +446,7 @@ function makeModulePlugins(options) {
const ident = topLevelIsOnce[importFrom]
? h.HIDDEN_ONCE
: h.HIDDEN_LIVE;
- myUpdaterSources.push(`${ident}[${JSON.stringify(importTo)}]`);
+ myUpdaterSources.push(`${ident}[${JSON.stringify(importFrom)}]`);
}
if (source || myUpdaterSources) {

MODIFY
packages/static-module-record/test/test-static-module-record.js
packages/static-module-record/test/test-static-module-record.js
@@ -68,35 +68,39 @@ function initialize(t, source, options = {}) {
const compartment = new Compartment(endowments);
- Object.keys(record.__liveExportMap__).forEach(name => {
+ Object.entries(record.__liveExportMap__).forEach(
+ ([exportedName, [localName]]) => {
/** @param {any} value */
const set = value => {
- namespace[name] = value;
- log.push(`${name}: ${JSON.stringify(value)}`);
+ namespace[exportedName] = value;
+ log.push(`${exportedName}: ${JSON.stringify(value)}`);
};
const get = () => {
- return namespace[name];
+ return namespace[exportedName];
};
// Initialization uses the fast local variable.
- liveUpdaters[name] = set;
+ liveUpdaters[localName] = set;
// Live updates fall through to the scope proxy.
// Live updates could be accomodated with an invasive rewrite of all
// references to the variable in scope, but we elected to avoid
// transforming code except for import and export statements, in order to
// minimize surprise in debugging.
- Object.defineProperty(compartment.globalThis, name, { get, set });
- });
+ Object.defineProperty(compartment.globalThis, localName, { get, set });
+ },
+ );
- Object.keys(record.__fixedExportMap__).forEach(name => {
+ Object.entries(record.__fixedExportMap__).forEach(
+ ([exportedName, [localName]]) => {
/** @param {any} value */
- onceUpdaters[name] = value => {
- t.assert(!(name in namespace));
- namespace[name] = value;
- log.push(`${name}: ${JSON.stringify(value)}`);
+ onceUpdaters[localName] = value => {
+ t.assert(!(exportedName in namespace));
+ namespace[exportedName] = value;
+ log.push(`${exportedName}: ${JSON.stringify(value)}`);
};
- });
+ },
+ );
const functor = compartment.evaluate(record.__syncModuleProgram__);
@@ -638,3 +642,29 @@ test('export function should be live when assigned', t => {
work: ['work', true],
});
});
+
+test('export const name as default', t => {
+ const { __fixedExportMap__, __liveExportMap__ } = new StaticModuleRecord(`
+ const meaning = 42;
+ export { meaning as default };
+ `);
+ t.deepEqual(__fixedExportMap__, {
+ default: ['meaning'],
+ });
+ t.deepEqual(__liveExportMap__, {});
+});
+
+test('export name as default from', t => {
+ const {
+ __syncModuleProgram__,
+ __fixedExportMap__,
+ __liveExportMap__,
+ } = new StaticModuleRecord(`
+ export { meaning as default } from './meaning.js';
+ `);
+ t.log(__syncModuleProgram__);
+ t.deepEqual(__fixedExportMap__, {});
+ t.deepEqual(__liveExportMap__, {
+ default: ['meaning', false],
+ });
+});

fix(static-module-record): Fix treatment of local vs exported names in test scaffold