@endo/static-module-record
Advanced tools
Comparing version 0.6.15 to 0.7.0
@@ -6,2 +6,15 @@ # Change Log | ||
## [0.7.0](https://github.com/endojs/endo/compare/@endo/static-module-record@0.6.15...@endo/static-module-record@0.7.0) (2022-03-07) | ||
### ⚠ BREAKING CHANGES | ||
* **static-module-record:** remove dependencies on `@babel/standalone` | ||
### Bug Fixes | ||
* **static-module-record:** remove dependencies on `@babel/standalone` ([1a1d1a4](https://github.com/endojs/endo/commit/1a1d1a4f5a7094f32d3e1edfc620e64065771efa)) | ||
### [0.6.15](https://github.com/endojs/endo/compare/@endo/static-module-record@0.6.14...@endo/static-module-record@0.6.15) (2022-03-02) | ||
@@ -8,0 +21,0 @@ |
{ | ||
"name": "@endo/static-module-record", | ||
"version": "0.6.15", | ||
"version": "0.7.0", | ||
"description": "Shim for the SES StaticModuleRecord and module-to-program transformer", | ||
@@ -38,9 +38,12 @@ "keywords": [ | ||
"dependencies": { | ||
"@agoric/babel-standalone": "^7.14.3", | ||
"ses": "^0.15.10" | ||
"@agoric/babel-generator": "^7.17.6", | ||
"@babel/parser": "^7.17.3", | ||
"@babel/traverse": "^7.17.3", | ||
"@babel/types": "^7.17.0", | ||
"ses": "^0.15.11" | ||
}, | ||
"devDependencies": { | ||
"@ava/babel": "^1.0.1", | ||
"@endo/eslint-config": "^0.4.5", | ||
"@endo/ses-ava": "^0.2.20", | ||
"@endo/eslint-config": "^0.4.6", | ||
"@endo/ses-ava": "^0.2.21", | ||
"ava": "^3.12.1", | ||
@@ -83,3 +86,3 @@ "babel-eslint": "^10.0.3", | ||
}, | ||
"gitHead": "08973d4fc6358a58d733251b051b2812bb4c651a" | ||
"gitHead": "9ddd58b4a26755cdba9403b0cb042b2067c69832" | ||
} |
/* eslint no-underscore-dangle: ["off"] */ | ||
// import babel from '@agoric/babel-standalone'; | ||
import * as babelStar from '@agoric/babel-standalone'; | ||
import { makeModuleAnalyzer } from './transform-analyze.js'; | ||
@@ -33,3 +31,3 @@ | ||
const analyzeModule = makeModuleAnalyzer(babelStar.default || babelStar); | ||
const analyzeModule = makeModuleAnalyzer(); | ||
@@ -36,0 +34,0 @@ /** |
@@ -0,1 +1,6 @@ | ||
import * as babelParser from '@babel/parser'; | ||
import babelGenerate from '@agoric/babel-generator'; | ||
import babelTraverse from '@babel/traverse'; | ||
import babelTypes from '@babel/types'; | ||
import * as h from './hidden.js'; | ||
@@ -6,78 +11,39 @@ import makeModulePlugins from './babelPlugin.js'; | ||
export const getParserPlugins = sourceType => { | ||
// Transform the script/expression source for import expressions. | ||
const parserPlugins = []; | ||
if (sourceType === 'module') { | ||
parserPlugins.push( | ||
'exportDefaultFrom', | ||
'exportNamespaceFrom', | ||
'importMeta', | ||
const parseBabel = babelParser.default | ||
? babelParser.default.parse | ||
: babelParser.parse || babelParser; | ||
const visitorFromPlugin = plugin => plugin({ types: babelTypes }).visitor; | ||
const traverseBabel = babelTraverse.default || babelTraverse; | ||
const generateBabel = babelGenerate.default || babelGenerate; | ||
const makeTransformSource = (babel = null) => { | ||
if (babel !== null) { | ||
throw new Error( | ||
`transform-analyze.js no longer allows injecting babel; use \`null\``, | ||
); | ||
} | ||
// This list taken and amended from: | ||
// https://github.com/prettier/prettier/tree/master/src/language-js/parser-babylon.js#L21 | ||
parserPlugins.push( | ||
'eventualSend', | ||
'doExpressions', | ||
'objectRestSpread', | ||
'classProperties', | ||
// 'exportDefaultFrom', // only for modules, above | ||
// 'exportNamespaceFrom', // only for modules, above | ||
'asyncGenerators', | ||
'functionBind', | ||
'functionSent', | ||
'dynamicImport', // needed for our rewrite | ||
'numericSeparator', | ||
// 'importMeta', // only for modules, above | ||
'optionalCatchBinding', | ||
'optionalChaining', | ||
'classPrivateProperties', | ||
['pipelineOperator', { proposal: 'minimal' }], | ||
'nullishCoalescingOperator', | ||
'bigInt', | ||
'throwExpressions', | ||
'logicalAssignment', | ||
'classPrivateMethods', | ||
'classPrivateProperties', | ||
// 'v8intrinsic', // we really don't want people to rely on platform powers | ||
'partialApplication', | ||
['decorators', { decoratorsBeforeExport: false }], | ||
); | ||
return parserPlugins; | ||
}; | ||
const transformSource = (code, sourceOptions = {}) => { | ||
// console.log(`transforming`, sourceOptions, code); | ||
const { analyzePlugin, transformPlugin } = makeModulePlugins(sourceOptions); | ||
const makeTransformSource = babel => | ||
function transformSource(code, sourceOptions = {}) { | ||
const parserPlugins = getParserPlugins(sourceOptions.sourceType); | ||
const ast = parseBabel(code, { sourceType: 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; | ||
babel.transform(code, { | ||
parserOpts: { | ||
allowAwaitOutsideFunction, | ||
plugins: parserPlugins, | ||
}, | ||
plugins: [analyzePlugin], | ||
ast: false, | ||
code: false, | ||
traverseBabel(ast, visitorFromPlugin(analyzePlugin)); | ||
traverseBabel(ast, visitorFromPlugin(transformPlugin)); | ||
const { code: transformedCode } = generateBabel(ast, { | ||
retainLines: true, | ||
compact: true, | ||
verbatim: true, | ||
}); | ||
const { code: transformedCode } = babel.transform(code, { | ||
parserOpts: { | ||
allowAwaitOutsideFunction, | ||
plugins: parserPlugins, | ||
}, | ||
generatorOpts: { | ||
retainLines: true, | ||
compact: true, | ||
}, | ||
plugins: [transformPlugin], | ||
}); | ||
// console.log(`transformed to`, output.code); | ||
// console.log(`transformed`, transformedCode); | ||
return transformedCode; | ||
}; | ||
return transformSource; | ||
}; | ||
const makeCreateStaticRecord = transformSource => | ||
@@ -84,0 +50,0 @@ function createStaticRecord(moduleSource, url) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56720
5
849
+ Added@babel/parser@^7.17.3
+ Added@babel/traverse@^7.17.3
+ Added@babel/types@^7.17.0
+ Added@agoric/babel-generator@7.17.6(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/generator@7.26.3(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.3(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.26.4(transitive)
+ Added@babel/types@7.26.3(transitive)
+ Added@jridgewell/gen-mapping@0.3.8(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@2.5.23.1.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedsource-map@0.5.7(transitive)
- Removed@agoric/babel-standalone@^7.14.3
- Removed@agoric/babel-standalone@7.17.7(transitive)
Updatedses@^0.15.11