Skip to content

Commit

Permalink
typings: fix JSDoc in ESM loader modules
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48424
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
  • Loading branch information
aduh95 authored and Ceres6 committed Aug 14, 2023
1 parent ca17509 commit f981ada
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
9 changes: 8 additions & 1 deletion lib/internal/modules/esm/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ let debug = require('internal/util/debuglog').debuglog('esm', (fn) => {
});


/**
* @typedef {object} ExportedHooks
* @property {Function} globalPreload Global preload hook.
* @property {Function} resolve Resolve hook.
* @property {Function} load Load hook.
*/

/**
* @typedef {object} KeyedHook
* @property {Function} fn The hook function.
Expand Down Expand Up @@ -631,7 +638,7 @@ ObjectSetPrototypeOf(HooksProxy.prototype, null);
/**
* A utility function to pluck the hooks from a user-defined loader.
* @param {import('./loader.js).ModuleExports} exports
* @returns {import('./loader.js).ExportedHooks}
* @returns {ExportedHooks}
*/
function pluckHooks({
globalPreload,
Expand Down
22 changes: 2 additions & 20 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,10 @@ function getTranslators() {
*/
let hooksProxy;

/**
* @typedef {object} ExportedHooks
* @property {Function} globalPreload Global preload hook.
* @property {Function} resolve Resolve hook.
* @property {Function} load Load hook.
*/

/**
* @typedef {Record<string, any>} ModuleExports
*/

/**
* @typedef {object} KeyedExports
* @property {ModuleExports} exports The contents of the module.
* @property {URL['href']} url The URL of the module.
*/

/**
* @typedef {'builtin'|'commonjs'|'json'|'module'|'wasm'} ModuleFormat
*/
Expand Down Expand Up @@ -229,17 +216,12 @@ class DefaultModuleLoader {

/**
* This method is usually called indirectly as part of the loading processes.
* Internally, it is used directly to add loaders. Use directly with caution.
*
* This method must NOT be renamed: it functions as a dynamic import on a
* loader module.
* Use directly with caution.
* @param {string} specifier The first parameter of an `import()` expression.
* @param {string} parentURL Path of the parent importing the module.
* @param {Record<string, string>} importAssertions Validations for the
* module import.
* @returns {Promise<ExportedHooks | KeyedExports[]>}
* A collection of module export(s) or a list of collections of module
* export(s).
* @returns {Promise<ModuleExports>}
*/
async import(specifier, parentURL, importAssertions) {
const moduleJob = this.getModuleJob(specifier, parentURL, importAssertions);
Expand Down

0 comments on commit f981ada

Please sign in to comment.