22
33import { makeModuleAnalyzer } from './transform-analyze.js' ;
44
5- const { keys, values } = Object ;
5+ /**
6+ * @import {ModuleSourceOptions} from './types/module-source.js'
7+ */
68
79// Disable readonly markings.
810const freeze = /** @type {<T>(v: T) => T } */ ( Object . freeze ) ;
@@ -33,28 +35,6 @@ const freeze = /** @type {<T>(v: T) => T} */ (Object.freeze);
3335
3436const analyzeModule = makeModuleAnalyzer ( ) ;
3537
36- /**
37- * @typedef {object } SourceMapHookDetails
38- * @property {string } compartment
39- * @property {string } module
40- * @property {string } location
41- * @property {string } sha512
42- */
43-
44- /**
45- * @callback SourceMapHook
46- * @param {string } sourceMap
47- * @param {SourceMapHookDetails } details
48- */
49-
50- /**
51- * @typedef {object } Options
52- * @property {string | undefined } [sourceUrl]
53- * @property {string | undefined } [sourceMap]
54- * @property {string | undefined } [sourceMapUrl]
55- * @property {SourceMapHook | undefined } [sourceMapHook]
56- */
57-
5838// XXX implements import('ses').PrecompiledModuleSource but adding
5939// `@implements` errors that this isn't a class and `@returns` errors that
6040// there's no value returned.
@@ -64,7 +44,7 @@ const analyzeModule = makeModuleAnalyzer();
6444 *
6545 * @class
6646 * @param {string } source
67- * @param {string | Options } [opts]
47+ * @param {string | ModuleSourceOptions } [opts]
6848 */
6949export function ModuleSource ( source , opts = { } ) {
7050 if ( new . target === undefined ) {
@@ -75,45 +55,18 @@ export function ModuleSource(source, opts = {}) {
7555 if ( typeof opts === 'string' ) {
7656 opts = { sourceUrl : opts } ;
7757 }
78- const {
79- imports,
80- functorSource,
81- liveExportMap,
82- reexportMap,
83- fixedExportMap,
84- exportAlls,
85- needsImport,
86- needsImportMeta,
87- } = analyzeModule ( source , opts ) ;
88- this . imports = freeze ( [ ...keys ( imports ) ] ) ;
89- this . exports = freeze (
90- [
91- ...keys ( liveExportMap ) ,
92- ...keys ( fixedExportMap ) ,
93- ...values ( reexportMap )
94- . flat ( )
95- . map ( ( [ _ , exportName ] ) => exportName ) ,
96- ] . sort ( ) ,
97- ) ;
98- this . reexports = freeze ( [ ...exportAlls ] . sort ( ) ) ;
99- this . __syncModuleProgram__ = functorSource ;
100- for ( const entry of values ( liveExportMap ) ) {
101- freeze ( entry ) ;
102- }
103- for ( const entry of values ( fixedExportMap ) ) {
104- freeze ( entry ) ;
105- }
106- for ( const reexports of values ( reexportMap ) ) {
107- for ( const pair of reexports ) {
108- freeze ( pair ) ;
109- }
110- freeze ( reexports ) ;
111- }
112- this . __liveExportMap__ = freeze ( liveExportMap ) ;
113- this . __reexportMap__ = freeze ( reexportMap ) ;
114- this . __fixedExportMap__ = freeze ( fixedExportMap ) ;
115- this . __needsImport__ = needsImport ;
116- this . __needsImportMeta__ = needsImportMeta ;
58+ // analyzeModule now returns a frozen PrecompiledModuleSource-shaped record
59+ // via buildModuleRecord(), so we copy its properties directly.
60+ const record = analyzeModule ( source , opts ) ;
61+ this . imports = record . imports ;
62+ this . exports = record . exports ;
63+ this . reexports = record . reexports ;
64+ this . __syncModuleProgram__ = record . __syncModuleProgram__ ;
65+ this . __liveExportMap__ = record . __liveExportMap__ ;
66+ this . __reexportMap__ = record . __reexportMap__ ;
67+ this . __fixedExportMap__ = record . __fixedExportMap__ ;
68+ this . __needsImport__ = record . __needsImport__ ;
69+ this . __needsImportMeta__ = record . __needsImportMeta__ ;
11770 freeze ( this ) ;
11871}
11972
0 commit comments