@@ -1160,25 +1160,26 @@ condition list **must** be passed through to the `defaultResolve` function.
11601160```js
11611161/**
11621162 * @param {string} specifier
1163- * @param {object} context
1164- * @param {string} context. parentURL
1165- * @param {string[]} context. conditions
1166- * @param {function} defaultResolve
1167- * @returns {object} response
1168- * @returns {string} response. url
1163+ * @param {{
1164+ * parentURL: !(string | undefined),
1165+ * conditions: !(Array<string>),
1166+ * }} context
1167+ * @param {Function} defaultResolve
1168+ * @returns {!(Promise<{ url: string }>)}
11691169 */
11701170export async function resolve (specifier , context , defaultResolve ) {
11711171 const { parentURL = null } = context ;
1172- if (someCondition) {
1172+ if (Math . random () > 0.5 ) { // Some condition.
11731173 // For some or all specifiers, do some custom logic for resolving.
1174- // Always return an object of the form {url: <string>}
1174+ // Always return an object of the form {url: <string>}.
11751175 return {
1176- url: (parentURL) ?
1177- new URL (specifier, parentURL).href : new URL (specifier).href
1176+ url: parentURL ?
1177+ new URL (specifier, parentURL).href :
1178+ new URL (specifier).href ,
11781179 };
11791180 }
1180- if (anotherCondition) {
1181- // When calling the defaultResolve, the arguments can be modified. In this
1181+ if (Math . random () < 0.5 ) { // Another condition.
1182+ // When calling ` defaultResolve` , the arguments can be modified. In this
11821183 // case it's adding another value for matching conditional exports.
11831184 return defaultResolve (specifier, {
11841185 ... context,
@@ -1220,18 +1221,17 @@ not a string, it will be converted to a string using [`util.TextDecoder`][].
12201221` ` ` js
12211222/**
12221223 * @param {string} url
1223- * @param {object} context (currently empty)
1224- * @param {function} defaultGetFormat
1225- * @returns {object} response
1226- * @returns {string} response.format
1224+ * @param {Object} context (currently empty)
1225+ * @param {Function} defaultGetFormat
1226+ * @returns {Promise<{ format: string }>}
12271227 */
12281228export async function getFormat (url , context , defaultGetFormat ) {
1229- if (someCondition) {
1229+ if (Math . random () > 0.5 ) { // Some condition.
12301230 // For some or all URLs, do some custom logic for determining format.
12311231 // Always return an object of the form {format: <string>}, where the
12321232 // format is one of the strings in the table above.
12331233 return {
1234- format: ' module'
1234+ format: ' module' ,
12351235 };
12361236 }
12371237 // Defer to Node.js for all other URLs.
@@ -1251,19 +1251,17 @@ potentially avoid reading files from disk.
12511251` ` ` js
12521252/**
12531253 * @param {string} url
1254- * @param {object} context
1255- * @param {string} context.format
1256- * @param {function} defaultGetSource
1257- * @returns {object} response
1258- * @returns {string|buffer} response.source
1254+ * @param {{ format: string }} context
1255+ * @param {Function} defaultGetSource
1256+ * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>}
12591257 */
12601258export async function getSource (url , context , defaultGetSource ) {
12611259 const { format } = context;
1262- if (someCondition) {
1260+ if (Math . random () > 0.5 ) { // Some condition.
12631261 // For some or all URLs, do some custom logic for retrieving the source.
12641262 // Always return an object of the form {source: <string|buffer>}.
12651263 return {
1266- source: ' ...'
1264+ source: ' ...' ,
12671265 };
12681266 }
12691267 // Defer to Node.js for all other URLs.
@@ -1286,28 +1284,25 @@ unknown-to-Node.js file extensions. See the [transpiler loader example][] below.
12861284
12871285` ` ` js
12881286/**
1289- * @param {string|buffer } source
1290- * @param {object} context
1291- * @param {string} context. url
1292- * @param {string} context. format
1293- * @param {function} defaultTransformSource
1294- * @returns {object} response
1295- * @returns {string|buffer} response.source
1287+ * @param {!(SharedArrayBuffer | string | Uint8Array) } source
1288+ * @param {{
1289+ * url: string,
1290+ * format: string,
1291+ * }} context
1292+ * @param {Function} defaultTransformSource
1293+ * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>}
12961294 */
1297- export async function transformSource (source ,
1298- context ,
1299- defaultTransformSource ) {
1295+ export async function transformSource (source , context , defaultTransformSource ) {
13001296 const { url , format } = context;
1301- if (someCondition) {
1297+ if (Math . random () > 0.5 ) { // Some condition.
13021298 // For some or all URLs, do some custom logic for modifying the source.
13031299 // Always return an object of the form {source: <string|buffer>}.
13041300 return {
1305- source: ' ...'
1301+ source: ' ...' ,
13061302 };
13071303 }
13081304 // Defer to Node.js for all other sources.
1309- return defaultTransformSource (
1310- source, context, defaultTransformSource);
1305+ return defaultTransformSource (source, context, defaultTransformSource);
13111306}
13121307` ` `
13131308
0 commit comments