fix up tests for makeImporter -> async
MODIFY
src/babelPlugin.js
src/babelPlugin.js
@@ -38,9 +38,11 @@ export default options =>
importSources,
liveExportMap,
} = options;
+ const allowedHiddens = new WeakSet();
+ const exportedVariableDecls = new WeakSet();
const hiddenIdentifier = hi => {
const ident = t.identifier(hi);
- ident.allowedInternalHidden = true;
+ allowedHiddens.add(ident);
return ident;
};
const updaterSources = {};
@@ -149,7 +151,7 @@ export default options =>
const visitor = {
Identifier(path) {
- if (options.allowHidden || path.node.allowedInternalHidden) {
+ if (options.allowHidden || allowedHiddens.has(path.node)) {
return;
}
// Ensure the parse doesn't already include our required hidden symbols.
@@ -289,7 +291,7 @@ export default options =>
VariableDeclaration(path) {
if (
path.parent.type !== 'Program' ||
- path.node.ignoreForModuleTransform
+ exportedVariableDecls.has(path.node)
) {
return;
}
@@ -324,7 +326,7 @@ export default options =>
}
if (decl) {
- decl.ignoreForModuleTransform = true;
+ exportedVariableDecls.add(decl);
replace.push(...rewriteExportDecl(path, decl));
}
specs.forEach(spec => {

MODIFY
src/index.js
src/index.js
@@ -119,7 +119,7 @@ const makeModuleTransformer = (babelCore, importer) => {
const staticRecord = createStaticRecord(source);
Object.assign(endowments, {
// Import our own source directly, returning a promise.
- [h.HIDDEN_IMPORT_SELF]: curryImporter({ url, staticRecord }),
+ [h.HIDDEN_IMPORT_SELF]: () => curryImporter({ url, staticRecord }),
});
return {
...ss,

MODIFY
test/test-export-default.js
test/test-export-default.js
@@ -5,8 +5,8 @@ import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-const makeMakeImporter = () => (srcSpec, endowments) => {
- const { spec, linkageRecord } = srcSpec;
+const makeImporter = () => (srcSpec, endowments) => {
+ const { spec, staticRecord } = srcSpec;
let actualSource;
const doImport = async () => {
const exportNS = {};
@@ -23,9 +23,9 @@ const makeMakeImporter = () => (srcSpec, endowments) => {
return exportNS;
};
- if (spec === undefined && linkageRecord !== undefined) {
- actualSource = linkageRecord.functorSource;
- return doImport;
+ if (spec === undefined && staticRecord !== undefined) {
+ actualSource = staticRecord.functorSource;
+ return doImport();
}
actualSource = `({ constVar }) => constVar.default(${JSON.stringify(spec)});`;
@@ -34,7 +34,7 @@ const makeMakeImporter = () => (srcSpec, endowments) => {
test('export default', async t => {
try {
- const transforms = [makeModuleTransformer(babelCore, makeMakeImporter())];
+ const transforms = [makeModuleTransformer(babelCore, makeImporter())];
const { evaluateExpr, evaluateProgram, evaluateModule } = makeEvaluators({
transforms,
});

MODIFY
test/test-export-named.js
test/test-export-named.js
@@ -5,8 +5,8 @@ import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-const makeMakeImporter = (liveVars = []) => (srcSpec, endowments) => {
- const { spec, linkageRecord } = srcSpec;
+const makeImporter = (liveVars = []) => async (srcSpec, endowments) => {
+ const { spec, staticRecord } = srcSpec;
let actualSource;
const doImport = async () => {
const exportNS = {};
@@ -41,13 +41,13 @@ const makeMakeImporter = (liveVars = []) => (srcSpec, endowments) => {
imports(_imports) {},
};
// console.log(staticRecord.functorSource);
- evaluate(actualSource, endow)(functorArg);
+ await evaluate(actualSource, endow)(functorArg);
return exportNS;
};
- if (spec === undefined && linkageRecord !== undefined) {
- actualSource = linkageRecord.functorSource;
- return doImport;
+ if (spec === undefined && staticRecord !== undefined) {
+ actualSource = staticRecord.functorSource;
+ return doImport();
}
throw Error(`Not expecting import expression`);
@@ -55,8 +55,8 @@ const makeMakeImporter = (liveVars = []) => (srcSpec, endowments) => {
test(`export named`, async t => {
try {
- const makeImporter = makeMakeImporter(['def']);
- const transforms = [makeModuleTransformer(babelCore, makeImporter)];
+ const importer = makeImporter(['def']);
+ const transforms = [makeModuleTransformer(babelCore, importer)];
const { evaluateModule } = makeEvaluators({
transforms,
});
@@ -97,8 +97,8 @@ export const ghi = 789;
test(`export hoisting`, async t => {
try {
- const makeImporter = makeMakeImporter(['abc', 'fn']);
- const transforms = [makeModuleTransformer(babelCore, makeImporter)];
+ const importer = makeImporter(['abc', 'fn']);
+ const transforms = [makeModuleTransformer(babelCore, importer)];
const { evaluateModule } = makeEvaluators({
transforms,
});

MODIFY
test/test-import.js
test/test-import.js
@@ -5,11 +5,11 @@ import * as babelCore from '@babel/core';
import makeModuleTransformer from '../src/index';
-const makeMakeImporter = () => (srcSpec, endowments) => {
- const { spec, linkageRecord } = srcSpec;
+const makeImporter = () => async (srcSpec, endowments) => {
+ const { spec, staticRecord } = srcSpec;
let actualSource;
const doImport = async () => {
- const ret = { staticRecord: linkageRecord };
+ const ret = { staticRecord };
const functorArg = {
imports(imp) {
ret.imports = imp;
@@ -20,9 +20,9 @@ const makeMakeImporter = () => (srcSpec, endowments) => {
return ret;
};
- if (spec === undefined && linkageRecord !== undefined) {
- actualSource = linkageRecord.functorSource;
- return doImport;
+ if (spec === undefined && staticRecord !== undefined) {
+ actualSource = staticRecord.functorSource;
+ return doImport();
}
throw Error(`Not expecting import expression`);
@@ -30,8 +30,8 @@ const makeMakeImporter = () => (srcSpec, endowments) => {
test('import', async t => {
try {
- const makeImporter = makeMakeImporter();
- const transforms = [makeModuleTransformer(babelCore, makeImporter)];
+ const importer = makeImporter();
+ const transforms = [makeModuleTransformer(babelCore, importer)];
const { evaluateModule } = makeEvaluators({
transforms,
});
@@ -49,7 +49,7 @@ test('import', async t => {
moduleSource: srcNS,
imports: { module: ['*'] },
liveExportMap: {},
- fixedExports: [],
+ fixedExportMap: {},
functorSource: fsrcNS,
},
'namespace static record',
@@ -71,7 +71,7 @@ test('import', async t => {
moduleSource: srcNames,
imports: { module: ['foo', 'bar'] },
liveExportMap: {},
- fixedExports: [],
+ fixedExportMap: {},
functorSource: fsrcNames,
},
'names static record',
@@ -90,7 +90,7 @@ test('import', async t => {
moduleSource: srcDefault,
imports: { module: ['default'] },
liveExportMap: {},
- fixedExports: [],
+ fixedExportMap: {},
functorSource: fsrcDefault,
},
'default static record',

fix up tests for makeImporter -> async