index: return the linkageRecord from the rewrite
MODIFY
src/index.js
src/index.js
@@ -93,18 +93,11 @@ const makeModuleTransformer = (babelCore, makeImporter) => {
return {
rewrite(ss) {
// Transform the source into evaluable form.
- const { allowHidden, evaluateProgram, endowments, src: source, url } = ss;
+ const { allowHidden, endowments, src: source, url } = ss;
// Make an importer that uses our transform for its submodules.
function curryImporter(srcSpec) {
- const evaluate = (src, postEndowments = {}) => {
- const endow = Object.create(null, {
- ...Object.getOwnPropertyDescriptors(endowments),
- ...Object.getOwnPropertyDescriptors(postEndowments),
- });
- return evaluateProgram(src, endow, { allowHidden: true });
- };
- return makeImporter(srcSpec, createStaticRecord, evaluate);
+ return makeImporter(srcSpec, endowments);
}
// Create an import expression for the given URL.
@@ -122,14 +115,17 @@ const makeModuleTransformer = (babelCore, makeImporter) => {
});
if (ss.sourceType === 'module') {
- // Import our own source directly, returning a promise.
+ // Do the rewrite of our own sources.
+ const linkageRecord = createStaticRecord(source);
Object.assign(endowments, {
- [h.HIDDEN_IMPORT_SELF]: curryImporter({ url, source }),
+ // Import our own source directly, returning a promise.
+ [h.HIDDEN_IMPORT_SELF]: curryImporter({ url, linkageRecord }),
});
return {
...ss,
endowments,
allowHidden: true,
+ linkageRecord,
sourceType: 'script',
src: `${h.HIDDEN_IMPORT_SELF}();`,
};

MODIFY
test/test-export-default.js
test/test-export-default.js
import { test } from 'tape-promise/tape';
-import { makeEvaluators } from '@agoric/evaluate';
+import { makeEvaluators, evaluateProgram as evaluate } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-const makeMakeImporter = () => (
- srcSpec,
- createStaticRecord,
- evaluateProgram,
-) => {
- const { spec, source } = srcSpec;
+const makeMakeImporter = () => (srcSpec, endowments) => {
+ const { spec, linkageRecord } = srcSpec;
let actualSource;
const doImport = async () => {
- const staticRecord = createStaticRecord(actualSource);
const exportNS = {};
const functorArg = {
constVar: {
@@ -23,17 +18,17 @@ const makeMakeImporter = () => (
},
imports(_imports) {},
};
- // console.log(staticRecord.functorSource);
- evaluateProgram(staticRecord.functorSource)(functorArg);
+ // console.log(actualSource);
+ evaluate(actualSource, endowments)(functorArg);
return exportNS;
};
- if (spec === undefined && source !== undefined) {
- actualSource = source;
+ if (spec === undefined && linkageRecord !== undefined) {
+ actualSource = linkageRecord.functorSource;
return doImport;
}
- actualSource = `export default ${JSON.stringify(spec)};`;
+ actualSource = `({ constVar }) => constVar.default(${JSON.stringify(spec)});`;
return doImport();
};

MODIFY
test/test-export-named.js
test/test-export-named.js
import { test } from 'tape-promise/tape';
-import { makeEvaluators } from '@agoric/evaluate';
+import { makeEvaluators, evaluateProgram as evaluate } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-const makeMakeImporter = (liveVars = []) => (
- srcSpec,
- createStaticRecord,
- evaluateProgram,
-) => {
- const { spec, source } = srcSpec;
+const makeMakeImporter = (liveVars = []) => (srcSpec, endowments) => {
+ const { spec, linkageRecord } = srcSpec;
let actualSource;
const doImport = async () => {
- const staticRecord = createStaticRecord(actualSource);
const exportNS = {};
const onceProxy = new Proxy(
{},
@@ -36,19 +31,22 @@ const makeMakeImporter = (liveVars = []) => (
});
const props = {};
liveVars.forEach(vname => (props[vname] = makeLive(vname)));
- const endow = Object.create(null, props);
+ const endow = Object.create(null, {
+ ...Object.getOwnPropertyDescriptors(endowments),
+ ...props,
+ });
const functorArg = {
constVar: onceProxy,
letVar: onceProxy,
imports(_imports) {},
};
// console.log(staticRecord.functorSource);
- evaluateProgram(staticRecord.functorSource, endow)(functorArg);
+ evaluate(actualSource, endow)(functorArg);
return exportNS;
};
- if (spec === undefined && source !== undefined) {
- actualSource = source;
+ if (spec === undefined && linkageRecord !== undefined) {
+ actualSource = linkageRecord.functorSource;
return doImport;
}

MODIFY
test/test-import.js
test/test-import.js
import { test } from 'tape-promise/tape';
-import { makeEvaluators } from '@agoric/evaluate';
+import { makeEvaluators, evaluateProgram as evaluate } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-const makeMakeImporter = () => (
- srcSpec,
- createStaticRecord,
- evaluateProgram,
-) => {
- const { spec, source } = srcSpec;
+const makeMakeImporter = () => (srcSpec, endowments) => {
+ const { spec, linkageRecord } = srcSpec;
let actualSource;
const doImport = async () => {
- const staticRecord = createStaticRecord(actualSource);
- const ret = { staticRecord };
+ const ret = { staticRecord: linkageRecord };
const functorArg = {
imports(imp) {
ret.imports = imp;
},
};
// console.log(staticRecord.functorSource);
- evaluateProgram(staticRecord.functorSource)(functorArg);
+ evaluate(actualSource, endowments)(functorArg);
return ret;
};
- if (spec === undefined && source !== undefined) {
- actualSource = source;
+ if (spec === undefined && linkageRecord !== undefined) {
+ actualSource = linkageRecord.functorSource;
return doImport;
}

index: return the linkageRecord from the rewrite