@@ -11,12 +11,21 @@ let debug = require('internal/util/debuglog').debuglog('esm', (fn) => {
11
11
debug = fn ;
12
12
} ) ;
13
13
14
+ /**
15
+ * Creates an import statement for a given module path and index.
16
+ * @param {string } impt - The module path to import.
17
+ * @param {number } index - The index of the import statement.
18
+ */
14
19
function createImport ( impt , index ) {
15
20
const imptPath = JSONStringify ( impt ) ;
16
21
return `import * as $import_${ index } from ${ imptPath } ;
17
22
import.meta.imports[${ imptPath } ] = $import_${ index } ;` ;
18
23
}
19
24
25
+ /**
26
+ * Creates an export for a given module.
27
+ * @param {string } expt - The name of the export.
28
+ */
20
29
function createExport ( expt ) {
21
30
const name = `${ expt } ` ;
22
31
return `let $${ name } ;
@@ -27,6 +36,17 @@ import.meta.exports.${name} = {
27
36
};` ;
28
37
}
29
38
39
+ /**
40
+ * Creates a dynamic module with the given imports, exports, URL, and evaluate function.
41
+ * @param {string[] } imports - An array of imports.
42
+ * @param {string[] } exports - An array of exports.
43
+ * @param {string } [url=''] - The URL of the module.
44
+ * @param {(reflect: DynamicModuleReflect) => void } evaluate - The function to evaluate the module.
45
+ * @typedef {object } DynamicModuleReflect
46
+ * @property {string[] } imports - The imports of the module.
47
+ * @property {string[] } exports - The exports of the module.
48
+ * @property {(cb: (reflect: DynamicModuleReflect) => void) => void } onReady - Callback to evaluate the module.
49
+ */
30
50
const createDynamicModule = ( imports , exports , url = '' , evaluate ) => {
31
51
debug ( 'creating ESM facade for %s with exports: %j' , url , exports ) ;
32
52
const source = `
@@ -38,6 +58,7 @@ import.meta.done();
38
58
const m = new ModuleWrap ( `${ url } ` , undefined , source , 0 , 0 ) ;
39
59
40
60
const readyfns = new SafeSet ( ) ;
61
+ /** @type {DynamicModuleReflect } */
41
62
const reflect = {
42
63
exports : { __proto__ : null } ,
43
64
onReady : ( cb ) => { readyfns . add ( cb ) ; } ,
0 commit comments