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 targos committed Nov 10, 2023
1 parent 96edd85 commit a0c10aa
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 @@ -62,6 +62,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 @@ -630,7 +637,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 @@ -239,17 +226,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 a0c10aa

Please sign in to comment.