@endo/module-source 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,6 +74,15 @@ the hook returns a promise, it will be dropped and rejections will go uncaught.
74
74
  If the hook must do async work, these should be queued up as a job that the
75
75
  caller can later await.
76
76
 
77
+ ## XS Specific Variant
78
+
79
+ With the `xs` condition, `@endo/module-source` will not entrain Babel and will
80
+ just adapt the native `ModuleSource` to the older interface presented by this
81
+ package.
82
+ That is, the XS native `bindings` will be translated to `imports`, `exports`,
83
+ and `reexports` getters.
84
+ This form of `ModuleSource` ignores all options.
85
+
77
86
  ## Bug Disclosure
78
87
 
79
88
  Please help us practice coordinated security bug disclosure, by using the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/module-source",
3
- "version": "1.1.2",
3
+ "version": "1.3.0",
4
4
  "description": "Ponyfill for the SES ModuleSource and module-to-program transformer",
5
5
  "keywords": [
6
6
  "ses",
@@ -22,7 +22,10 @@
22
22
  "type": "module",
23
23
  "main": "./index.js",
24
24
  "exports": {
25
- ".": "./index.js",
25
+ ".": {
26
+ "xs": "./src-xs/index.js",
27
+ "default": "./index.js"
28
+ },
26
29
  "./shim.js": "./shim.js",
27
30
  "./package.json": "./package.json"
28
31
  },
@@ -35,14 +38,15 @@
35
38
  "lint:types": "tsc",
36
39
  "lint:eslint": "eslint .",
37
40
  "lint-fix": "eslint --fix .",
38
- "test": "ava"
41
+ "test": "ava",
42
+ "test:xs": "node scripts/generate-test-xs.js && xst tmp/test-xs.js"
39
43
  },
40
44
  "dependencies": {
41
- "@agoric/babel-generator": "^7.17.6",
42
- "@babel/parser": "^7.23.6",
43
- "@babel/traverse": "^7.23.6",
44
- "@babel/types": "^7.24.0",
45
- "ses": "^1.10.0"
45
+ "@babel/generator": "^7.26.3",
46
+ "@babel/parser": "~7.26.2",
47
+ "@babel/traverse": "~7.25.9",
48
+ "@babel/types": "~7.26.0",
49
+ "ses": "^1.12.0"
46
50
  },
47
51
  "devDependencies": {
48
52
  "ava": "^6.1.3",
@@ -85,5 +89,5 @@
85
89
  "typeCoverage": {
86
90
  "atLeast": 40.33
87
91
  },
88
- "gitHead": "5486ed1f238104716b6a8321b977fbc508ef80e1"
92
+ "gitHead": "9b6784831d37db948cdd61f6da1f3489e8f97906"
89
93
  }
package/shim.js CHANGED
@@ -1,6 +1,10 @@
1
1
  /* global globalThis */
2
2
 
3
- import { ModuleSource } from './index.js';
3
+ // We are using a reflexive import to make sure we pass through the conditional
4
+ // export in package.json.
5
+ // Eslint does not yet seem to have a carve-out for package-reflexive imports.
6
+ // eslint-disable-next-line import/no-extraneous-dependencies
7
+ import { ModuleSource } from '@endo/module-source';
4
8
 
5
9
  Object.defineProperty(globalThis, 'ModuleSource', {
6
10
  value: ModuleSource,
@@ -53,4 +53,4 @@ declare function makeModulePlugins(options: any): {
53
53
  };
54
54
  };
55
55
  };
56
- //# sourceMappingURL=babelPlugin.d.ts.map
56
+ //# sourceMappingURL=babel-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin.d.ts","sourceRoot":"","sources":["babel-plugin.js"],"names":[],"mappings":";AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+kBC"}
@@ -49,6 +49,7 @@ function makeModulePlugins(options) {
49
49
  reexportMap,
50
50
  liveExportMap,
51
51
  importMeta,
52
+ dynamicImport,
52
53
  } = options;
53
54
 
54
55
  if (sourceType !== 'module') {
@@ -286,6 +287,7 @@ function makeModulePlugins(options) {
286
287
  CallExpression(path) {
287
288
  // import(FOO) -> $h_import(FOO)
288
289
  if (path.node.callee.type === 'Import') {
290
+ dynamicImport.present = true;
289
291
  path.node.callee = hiddenIdentifier(h.HIDDEN_IMPORT);
290
292
  }
291
293
  },
@@ -62,6 +62,7 @@ export class ModuleSource {
62
62
  __liveExportMap__: any;
63
63
  __reexportMap__: any;
64
64
  __fixedExportMap__: any;
65
+ __needsImport__: boolean;
65
66
  __needsImportMeta__: boolean;
66
67
  }
67
68
  export type SourceMapHookDetails = {
@@ -1 +1 @@
1
- {"version":3,"file":"module-source.d.ts","sourceRoot":"","sources":["module-source.js"],"names":[],"mappings":"AAmCA;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAKH;;;;;;;GAOG;AACH,qCAHW,MAAM,6CAoChB;;IAlED;;;;;;OAMG;IAEH;;;;OAIG;IAEH;;;;;;OAMG;IAKH;;;;;;;OAOG;IACH,oBAHW,MAAM,uCAoChB;IAfC,kBAAyC;IACzC,eAMC;IACD,mBAA+C;IAC/C,8BAA0C;IAC1C,uBAAsC;IACtC,qBAAkC;IAClC,wBAAwC;IACxC,6BAA0C;;;iBA9D9B,MAAM;YACN,MAAM;cACN,MAAM;YACN,MAAM;;wCAKT,MAAM,WACN,oBAAoB"}
1
+ {"version":3,"file":"module-source.d.ts","sourceRoot":"","sources":["module-source.js"],"names":[],"mappings":"AAmCA;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAKH;;;;;;;GAOG;AACH,qCAHW,MAAM,6CAsChB;;IApED;;;;;;OAMG;IAEH;;;;OAIG;IAEH;;;;;;OAMG;IAKH;;;;;;;OAOG;IACH,oBAHW,MAAM,uCAsChB;IAhBC,kBAAyC;IACzC,eAMC;IACD,mBAA+C;IAC/C,8BAA0C;IAC1C,uBAAsC;IACtC,qBAAkC;IAClC,wBAAwC;IACxC,yBAAkC;IAClC,6BAA0C;;;iBAhE9B,MAAM;YACN,MAAM;cACN,MAAM;YACN,MAAM;;wCAKT,MAAM,WACN,oBAAoB"}
@@ -82,6 +82,7 @@ export function ModuleSource(source, opts = {}) {
82
82
  reexportMap,
83
83
  fixedExportMap,
84
84
  exportAlls,
85
+ needsImport,
85
86
  needsImportMeta,
86
87
  } = analyzeModule(source, opts);
87
88
  this.imports = freeze([...keys(imports)]);
@@ -97,6 +98,7 @@ export function ModuleSource(source, opts = {}) {
97
98
  this.__liveExportMap__ = liveExportMap;
98
99
  this.__reexportMap__ = reexportMap;
99
100
  this.__fixedExportMap__ = fixedExportMap;
101
+ this.__needsImport__ = needsImport;
100
102
  this.__needsImportMeta__ = needsImportMeta;
101
103
  freeze(this);
102
104
  }
@@ -4,6 +4,7 @@ export function makeModuleAnalyzer(babel: any): (moduleSource: string, { sourceU
4
4
  liveExportMap: any;
5
5
  fixedExportMap: any;
6
6
  reexportMap: any;
7
+ needsImport: boolean;
7
8
  needsImportMeta: boolean;
8
9
  functorSource: string;
9
10
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"transform-analyze.d.ts","sourceRoot":"","sources":["transform-analyze.js"],"names":[],"mappings":"AA+HO,+DAlHM,MAAM,0DACN,OAAO;;;;;;;;GAoHnB;AAEM;;EA6DN;6BAzL0B,oBAAoB"}
1
+ {"version":3,"file":"transform-analyze.d.ts","sourceRoot":"","sources":["transform-analyze.js"],"names":[],"mappings":"AA0HO,+DA7GM,MAAM,0DACN,OAAO;;;;;;;;;GA+GnB;AAEM;;EA6DN;6BApL0B,oBAAoB"}
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck XXX Babel types
2
- import { makeTransformSource } from './transformSource.js';
3
- import makeModulePlugins from './babelPlugin.js';
2
+ import { makeTransformSource } from './transform-source.js';
3
+ import makeModulePlugins from './babel-plugin.js';
4
4
 
5
5
  import * as h from './hidden.js';
6
6
 
@@ -41,6 +41,7 @@ const makeCreateStaticRecord = transformSource =>
41
41
  hoistedDecls: [],
42
42
  importSources: Object.create(null),
43
43
  importDecls: [],
44
+ dynamicImport: { present: false },
44
45
  // enables passing import.meta usage hints up.
45
46
  importMeta: { present: false },
46
47
  };
@@ -71,7 +72,7 @@ const makeCreateStaticRecord = transformSource =>
71
72
  .map(
72
73
  src =>
73
74
  `[${js(src)}, [${Object.entries(isrc[src])
74
- .map(([exp, upds]) => `[${js(exp)}, [${upds.join(',')}]]`)
75
+ .map(([exp, upds]) => `[${js(exp)},[${upds.join(',')}]]`)
75
76
  .join(',')}]]`,
76
77
  )
77
78
  .join(',')}]);`;
@@ -80,9 +81,7 @@ const makeCreateStaticRecord = transformSource =>
80
81
  let src = '';
81
82
  if (cvname) {
82
83
  // It's a function assigned to, so set its name property.
83
- src = `Object.defineProperty(${cvname}, 'name', {value: ${js(
84
- vname,
85
- )}});`;
84
+ src = `Object.defineProperty(${cvname},'name',{value:${js(vname)}});`;
86
85
  }
87
86
  const hDeclId = isOnce ? h.HIDDEN_ONCE : h.HIDDEN_LIVE;
88
87
  src += `${hDeclId}.${vname}(${cvname || ''});`;
@@ -99,14 +98,9 @@ const makeCreateStaticRecord = transformSource =>
99
98
  // well.
100
99
  // Relies on the evaluator to ensure these functions are strict.
101
100
  let functorSource = `\
102
- ({ \
103
- imports: ${h.HIDDEN_IMPORTS}, \
104
- liveVar: ${h.HIDDEN_LIVE}, \
105
- onceVar: ${h.HIDDEN_ONCE}, \
106
- importMeta: ${h.HIDDEN_META}, \
107
- }) => (function () { 'use strict'; \
108
- ${preamble} \
109
- ${scriptSource}
101
+ ({imports:${h.HIDDEN_IMPORTS},liveVar:${h.HIDDEN_LIVE},onceVar:${h.HIDDEN_ONCE},import:${h.HIDDEN_IMPORT},importMeta:${h.HIDDEN_META}})=>(function(){'use strict';\
102
+ ${preamble}\
103
+ ${scriptSource}
110
104
  })()
111
105
  `;
112
106
 
@@ -119,6 +113,7 @@ const makeCreateStaticRecord = transformSource =>
119
113
  liveExportMap: freeze(sourceOptions.liveExportMap),
120
114
  fixedExportMap: freeze(sourceOptions.fixedExportMap),
121
115
  reexportMap: freeze(sourceOptions.reexportMap),
116
+ needsImport: sourceOptions.dynamicImport.present,
122
117
  needsImportMeta: sourceOptions.importMeta.present,
123
118
  functorSource,
124
119
  });
@@ -0,0 +1,2 @@
1
+ export function makeTransformSource(makeModulePlugins: any, babel?: null): (source: any, sourceOptions?: {}) => string;
2
+ //# sourceMappingURL=transform-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-source.d.ts","sourceRoot":"","sources":["transform-source.js"],"names":[],"mappings":"AAeO,uHAmDN"}
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck XXX Babel types
2
2
  import * as babelParser from '@babel/parser';
3
- import babelGenerate from '@agoric/babel-generator';
3
+ import babelGenerate from '@babel/generator';
4
4
  import babelTraverse from '@babel/traverse';
5
5
  import * as babelTypes from '@babel/types';
6
6
 
@@ -26,7 +26,11 @@ export const makeTransformSource = (makeModulePlugins, babel = null) => {
26
26
  const { sourceUrl, sourceMapUrl, sourceType, sourceMap, sourceMapHook } =
27
27
  sourceOptions;
28
28
 
29
- const ast = parseBabel(source, { sourceType });
29
+ const ast = parseBabel(source, {
30
+ sourceType,
31
+ tokens: true,
32
+ createParenthesizedExpressions: true,
33
+ });
30
34
 
31
35
  traverseBabel(ast, visitorFromPlugin(analyzePlugin));
32
36
  traverseBabel(ast, visitorFromPlugin(transformPlugin));
@@ -34,14 +38,19 @@ export const makeTransformSource = (makeModulePlugins, babel = null) => {
34
38
  const sourceMaps = sourceOptions.sourceMapHook !== undefined;
35
39
 
36
40
  const { code: transformedSource, map: transformedSourceMap } =
37
- generateBabel(ast, {
38
- sourceFileName: sourceMapUrl,
39
- sourceMaps,
40
- inputSourceMap: sourceMap,
41
- retainLines: true,
42
- compact: true,
43
- verbatim: true,
44
- });
41
+ generateBabel(
42
+ ast,
43
+ {
44
+ sourceFileName: sourceMapUrl,
45
+ sourceMaps,
46
+ inputSourceMap: sourceMap,
47
+ experimental_preserveFormat: true,
48
+ preserveFormat: true,
49
+ retainLines: true,
50
+ verbatim: true,
51
+ },
52
+ source,
53
+ );
45
54
 
46
55
  if (sourceMaps) {
47
56
  sourceMapHook(transformedSourceMap, {
@@ -1 +0,0 @@
1
- {"version":3,"file":"babelPlugin.d.ts","sourceRoot":"","sources":["babelPlugin.js"],"names":[],"mappings":";AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6kBC"}
@@ -1,2 +0,0 @@
1
- export function makeTransformSource(makeModulePlugins: any, babel?: null): (source: any, sourceOptions?: {}) => any;
2
- //# sourceMappingURL=transformSource.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transformSource.d.ts","sourceRoot":"","sources":["transformSource.js"],"names":[],"mappings":"AAeO,oHA0CN"}