feat(bundle-source): use newer babel with Agoric fixes
MODIFY
packages/bundle-source/package.json
packages/bundle-source/package.json
"ava": "^3.12.1"
},
"dependencies": {
- "@babel/generator": "^7.14.2",
- "@babel/parser": "^7.14.2",
- "@babel/traverse": "^7.14.2",
+ "@agoric/babel-generator": "^7.17.3",
+ "@babel/parser": "^7.17.3",
+ "@babel/traverse": "^7.17.3",
"@endo/base64": "^0.2.19",
"@endo/compartment-mapper": "^0.6.7",
"@rollup/plugin-commonjs": "^19.0.0",

MODIFY
packages/bundle-source/src/index.js
packages/bundle-source/src/index.js
@@ -6,7 +6,7 @@ import crypto from 'crypto';
import resolve0 from '@rollup/plugin-node-resolve';
import commonjs0 from '@rollup/plugin-commonjs';
import * as babelParser from '@babel/parser';
-import babelGenerate from '@babel/generator';
+import babelGenerate from '@agoric/babel-generator';
import babelTraverse from '@babel/traverse';
import { makeArchive } from '@endo/compartment-mapper/archive.js';
import { makeReadPowers } from '@endo/compartment-mapper/node-powers.js';
@@ -132,7 +132,10 @@ async function transformSource(
transformAst(ast, unmapLoc);
// Now generate the sources with the new positions.
- return (babelGenerate.default || babelGenerate)(ast, { retainLines: true });
+ return (babelGenerate.default || babelGenerate)(ast, {
+ retainLines: true,
+ compact: true,
+ });
}
async function bundleZipBase64(startFilename, dev, powers = {}) {

MODIFY
packages/static-module-record/package.json
packages/static-module-record/package.json
},
"dependencies": {
"@agoric/babel-standalone": "^7.14.3",
- "@babel/traverse": "^7.10.4",
- "@babel/types": "^7.10.4",
- "recast": "agoric-labs/recast#Agoric-built",
"ses": "^0.15.9"
},
"devDependencies": {

MODIFY
packages/static-module-record/src/transform-analyze.js
packages/static-module-record/src/transform-analyze.js
-import * as recastCJS from 'recast';
-import traverseCJS from '@babel/traverse';
-import typesCJS from '@babel/types';
-
import * as h from './hidden.js';
import makeModulePlugins from './babelPlugin.js';
const { freeze } = Object;
-const makeTransformSource = babel =>
- function transformSource(code, sourceOptions = {}) {
+export const getParserPlugins = sourceType => {
// Transform the script/expression source for import expressions.
const parserPlugins = [];
- if (sourceOptions.sourceType === 'module') {
+ if (sourceType === 'module') {
parserPlugins.push(
'exportDefaultFrom',
'exportNamespaceFrom',
@@ -48,39 +43,40 @@ const makeTransformSource = babel =>
'partialApplication',
['decorators', { decoratorsBeforeExport: false }],
);
+ return parserPlugins;
+};
+
+const makeTransformSource = babel =>
+ function transformSource(code, sourceOptions = {}) {
+ const parserPlugins = getParserPlugins(sourceOptions.sourceType);
// console.log(`transforming`, sourceOptions, code);
const { analyzePlugin, transformPlugin } = makeModulePlugins(sourceOptions);
// TODO top-level-await https://github.com/endojs/endo/issues/306
const allowAwaitOutsideFunction = false;
- const recast = recastCJS.default || recastCJS;
- const ast = recast.parse(code, {
- parser: {
- parse: source =>
- babel.transform(source, {
+ babel.transform(code, {
parserOpts: {
allowAwaitOutsideFunction,
- tokens: true,
plugins: parserPlugins,
},
plugins: [analyzePlugin],
- ast: true,
+ ast: false,
code: false,
- }).ast,
- },
});
- const traverse = traverseCJS.default || traverseCJS;
- const types = typesCJS.default || typesCJS;
- traverse(ast, transformPlugin({ types }).visitor);
- ({ code } = recast.print(ast, {
- wrapColumn: Infinity,
- reuseWhitespace: true,
- includeComments: true,
+ const { code: transformedCode } = babel.transform(code, {
+ parserOpts: {
+ allowAwaitOutsideFunction,
+ plugins: parserPlugins,
+ },
+ generatorOpts: {
retainLines: true,
- }));
+ compact: true,
+ },
+ plugins: [transformPlugin],
+ });
// console.log(`transformed to`, output.code);
- return code;
+ return transformedCode;
};
const makeCreateStaticRecord = transformSource =>

feat(bundle-source): use newer babel with Agoric fixes