feat(analyze): separate analyze from the transform
The recursive import->transform->import is only in the evaluator
not the importer.
MODIFY
src/index.js
src/index.js
import * as h from './hidden';
import makeModulePlugins from './babelPlugin';
-const makeModuleTransformer = (babelCore, importer) => {
+const makeTransformSource = babelCore =>
function transformSource(source, sourceOptions = {}) {
// Transform the script/expression source for import expressions.
const parserPlugins = [];
@@ -78,8 +78,9 @@ const makeModuleTransformer = (babelCore, importer) => {
// console.log(`transformed to`, output.code);
return code;
- }
+ };
+const makeCreateStaticRecord = transformSource =>
function createStaticRecord(moduleSource) {
// Transform the Module source code.
const sourceOptions = {
@@ -101,6 +102,7 @@ const makeModuleTransformer = (babelCore, importer) => {
importDecls: [],
};
if (moduleSource.startsWith('#!')) {
+ // Comment out the shebang lines.
moduleSource = `//${moduleSource}`;
}
const scriptSource = transformSource(moduleSource, sourceOptions);
@@ -159,8 +161,17 @@ const makeModuleTransformer = (babelCore, importer) => {
};
// console.log(moduleStaticRecord);
return moduleStaticRecord;
- }
+ };
+export const makeModuleAnalyzer = babelCore => {
+ const transformSource = makeTransformSource(babelCore);
+ const createStaticRecord = makeCreateStaticRecord(transformSource);
+ return ({ string }) => createStaticRecord(string);
+};
+
+export const makeModuleTransformer = (babelCore, importer) => {
+ const transformSource = makeTransformSource(babelCore);
+ const createStaticRecord = makeCreateStaticRecord(transformSource);
return {
rewrite(ss) {
// Transform the source into evaluable form.
@@ -221,5 +232,3 @@ const makeModuleTransformer = (babelCore, importer) => {
},
};
};
-
-export default makeModuleTransformer;

MODIFY
test/test-export-default.js
test/test-export-default.js
@@ -3,7 +3,7 @@ import { makeEvaluators, evaluateProgram as evaluate } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
-import makeModuleTransformer from '../src/index';
+import { makeModuleTransformer } from '../src/index';
const makeImporter = () => (srcSpec, endowments) => {
const { spec, staticRecord } = srcSpec;

MODIFY
test/test-export-named.js
test/test-export-named.js
@@ -3,7 +3,7 @@ import { makeEvaluators, evaluateProgram as evaluate } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
-import makeModuleTransformer from '../src/index';
+import { makeModuleTransformer } from '../src/index';
const makeImporter = (liveVars = []) => async (srcSpec, endowments) => {
const { spec, staticRecord } = srcSpec;

MODIFY
test/test-import.js
test/test-import.js
@@ -3,7 +3,7 @@ import { makeEvaluators, evaluateProgram as evaluate } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
-import makeModuleTransformer from '../src/index';
+import { makeModuleTransformer } from '../src/index';
const makeImporter = () => async (srcSpec, endowments) => {
const { spec, staticRecord } = srcSpec;

MODIFY
test/test-sanity.js
test/test-sanity.js
@@ -3,7 +3,7 @@ import { makeEvaluators } from '@agoric/evaluate';
import * as babelCore from '@babel/core';
-import makeModuleTransformer from '../src/index';
+import { makeModuleTransformer } from '../src/index';
test('sanity', async t => {
try {

feat(analyze): separate analyze from the transform

The recursive import->transform->import is only in the evaluator
not the importer.