test-export*: refactor
MODIFY
test/test-export-default.js
test/test-export-default.js
@@ -4,23 +4,24 @@ import { makeEvaluators } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-import * as h from '../src/hidden';
-test('export default', async t => {
- try {
- const makeImporter = (srcSpec, createStaticRecord, evaluateProgram) => {
+const makeMakeImporter = () => (
+ srcSpec,
+ createStaticRecord,
+ evaluateProgram,
+) => {
const { spec, source } = srcSpec;
let actualSource;
const doImport = async () => {
const staticRecord = createStaticRecord(actualSource);
const exportNS = {};
const functorArg = {
- [h.HIDDEN_ONCE]: {
+ constVar: {
default(val) {
exportNS.default = val;
},
},
- [h.HIDDEN_IMPORTS](_imports) {},
+ imports(_imports) {},
};
// console.log(staticRecord.functorSource);
evaluateProgram(staticRecord.functorSource)(functorArg);
@@ -36,7 +37,9 @@ test('export default', async t => {
return doImport();
};
- const transforms = [makeModuleTransformer(babelCore, makeImporter)];
+test('export default', async t => {
+ try {
+ const transforms = [makeModuleTransformer(babelCore, makeMakeImporter())];
const { evaluateExpr, evaluateProgram, evaluateModule } = makeEvaluators({
transforms,
});

MODIFY
test/test-export-named.js
test/test-export-named.js
@@ -4,11 +4,12 @@ import { makeEvaluators } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-import * as h from '../src/hidden';
-test(`export named`, async t => {
- try {
- const makeImporter = (srcSpec, createStaticRecord, evaluateProgram) => {
+const makeMakeImporter = (liveVars = []) => (
+ srcSpec,
+ createStaticRecord,
+ evaluateProgram,
+) => {
const { spec, source } = srcSpec;
let actualSource;
const doImport = async () => {
@@ -22,20 +23,24 @@ test(`export named`, async t => {
},
},
);
- const endow = Object.create(null, {
- def: {
+ const makeLive = vname => ({
get() {
- return exportNS.def;
+ if (vname in exportNS) {
+ return exportNS[vname];
+ }
+ throw ReferenceError(`${vname} is not defined`);
},
set(value) {
- exportNS.def = value;
- },
+ return (exportNS[vname] = value);
},
});
+ const props = {};
+ liveVars.forEach(vname => (props[vname] = makeLive(vname)));
+ const endow = Object.create(null, props);
const functorArg = {
- [h.HIDDEN_ONCE]: onceProxy,
- [h.HIDDEN_LIVE]: onceProxy,
- [h.HIDDEN_IMPORTS](_imports) {},
+ constVar: onceProxy,
+ letVar: onceProxy,
+ imports(_imports) {},
};
// console.log(staticRecord.functorSource);
evaluateProgram(staticRecord.functorSource, endow)(functorArg);
@@ -47,10 +52,12 @@ test(`export named`, async t => {
return doImport;
}
- throw Error(`No import expression`);
- // return doImport();
+ throw Error(`Not expecting import expression`);
};
+test(`export named`, async t => {
+ try {
+ const makeImporter = makeMakeImporter(['def']);
const transforms = [makeModuleTransformer(babelCore, makeImporter)];
const { evaluateModule } = makeEvaluators({
transforms,
@@ -92,54 +99,7 @@ export const ghi = 789;
test(`export hoisting`, async t => {
try {
- const makeImporter = (srcSpec, createStaticRecord, evaluateProgram) => {
- const { spec, source } = srcSpec;
- let actualSource;
- const doImport = async () => {
- const staticRecord = createStaticRecord(actualSource);
- const exportNS = {};
- const onceProxy = new Proxy(
- {},
- {
- get(_target, prop) {
- return value => (exportNS[prop] = value);
- },
- },
- );
- const makeLive = vname => ({
- get() {
- if (vname in exportNS) {
- return exportNS[vname];
- }
- throw ReferenceError(`${vname} is not defined`);
- },
- set(value) {
- return (exportNS[vname] = value);
- },
- });
- const endow = Object.create(null, {
- abc: makeLive('abc'),
- fn: makeLive('fn'),
- });
- const functorArg = {
- [h.HIDDEN_ONCE]: onceProxy,
- [h.HIDDEN_LIVE]: onceProxy,
- [h.HIDDEN_IMPORTS](_imports) {},
- };
- console.log(staticRecord.functorSource);
- evaluateProgram(staticRecord.functorSource, endow)(functorArg);
- return exportNS;
- };
-
- if (spec === undefined && source !== undefined) {
- actualSource = source;
- return doImport;
- }
-
- throw Error(`No import expression`);
- // return doImport();
- };
-
+ const makeImporter = makeMakeImporter(['abc', 'fn']);
const transforms = [makeModuleTransformer(babelCore, makeImporter)];
const { evaluateModule } = makeEvaluators({
transforms,

test-export*: refactor