fix: Fully thread __shimTransforms__ through Compartment Mapper and SES
MODIFY
packages/compartment-mapper/NEWS.md
packages/compartment-mapper/NEWS.md
@@ -10,8 +10,8 @@ User-visible changes to the compartment mapper:
Compartment Mapper unusable with a combination of `-r esm` and Rollup.
CommonJS support should be restored with an alternate implementation in
a future version.
-* The `import` options bag now also accepts `globalLexicals` and `transforms`,
- passing these without alteration to each `Compartment`.
+* The `import` options bag now also accepts `globalLexicals`, `transforms`, and
+ `__shimTransforms__`, passing these without alteration to each `Compartment`.
* The `import` options bag now also accepts a `Compartment` constructor, to use
instead of the one assumed to be present globally.

MODIFY
packages/compartment-mapper/src/assemble.js
packages/compartment-mapper/src/assemble.js
@@ -132,6 +132,7 @@ export const assemble = (
globals = {},
globalLexicals = {},
transforms = [],
+ __shimTransforms__ = [],
modules: exitModules = {},
Compartment = defaultCompartment
}
@@ -171,6 +172,7 @@ export const assemble = (
importHook,
moduleMapHook,
transforms,
+ __shimTransforms__,
globalLexicals,
name: location
});

MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
@@ -54,6 +54,7 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
globalLexicals,
modules,
transforms,
+ __shimTransforms__,
Compartment
} = options;
const {
@@ -71,6 +72,7 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
globalLexicals,
modules,
transforms,
+ __shimTransforms__,
Compartment
});
return compartment.import(moduleSpecifier);

MODIFY
packages/compartment-mapper/src/import.js
packages/compartment-mapper/src/import.js
@@ -31,6 +31,7 @@ export const loadLocation = async (read, moduleLocation) => {
globalLexicals,
modules,
transforms,
+ __shimTransforms__,
Compartment
} = options;
const makeImportHook = makeImportHookMaker(read, packageLocation);
@@ -40,6 +41,7 @@ export const loadLocation = async (read, moduleLocation) => {
globalLexicals,
modules,
transforms,
+ __shimTransforms__,
Compartment
});
return compartment.import(moduleSpecifier);

MODIFY
packages/ses/src/compartment-shim.js
packages/ses/src/compartment-shim.js
@@ -114,7 +114,7 @@ export const makeCompartmentConstructor = (
__shimTransforms__ = [],
globalLexicals = {},
} = options;
- const globalTransforms = [...transforms];
+ const globalTransforms = [...transforms, ...__shimTransforms__];
const globalObject = {};
initGlobalObject(

MODIFY
packages/ses/test/compartment-transforms.test.js
packages/ses/test/compartment-transforms.test.js
@@ -66,7 +66,7 @@ test('__shimTransforms__ apply to evaluated expressions', t => {
const transform = source => source.replace(/Farewell/g, 'Hello');
const transforms = [transform];
- const c = new Compartment({}, {}, { transforms });
+ const c = new Compartment({}, {}, { __shimTransforms__: transforms });
const greeting = c.evaluate('"Farewell, World!"');
t.equal(greeting, 'Hello, World!');

fix: Fully thread __shimTransforms__ through Compartment Mapper and SES (#509)