fix(ses): transform is an object with a rewrite method
Fixes
Or rather, demonstrates that was a misunderstanding and this is
working as expected.
MODIFY
packages/ses/test/compartment.test.js
packages/ses/test/compartment.test.js
@@ -111,3 +111,24 @@ test('main use case', t => {
t.throws(() => user(-1), c.global.TypeError);
t.end();
});
+
+const transform = {
+ rewrite(rewriterState) {
+ const { src, endowments } = rewriterState;
+ return {
+ src: src.replace('replaceme', 'substitution'),
+ endowments: { added: 'by transform', ...endowments },
+ };
+ },
+};
+
+test('transforms can add endowments', t => {
+ // eslint-disable-next-line no-template-curly-in-string
+ const src = '(function f4(a) { return `replaceme ${added} ${a}`; })';
+ const transforms = [transform];
+ const c = new Compartment({}, {}, { transforms });
+ const f4 = c.evaluate(src);
+ const out = f4('ok');
+ t.equal(out, 'substitution by transform ok');
+ t.end();
+});

fix(ses): transform is an object with a rewrite method (#255)

Fixes #248

Or rather, demonstrates that #248 was a misunderstanding and this is
working as expected.