MCPcopy
hub / github.com/webpack/webpack / weakError

Method weakError

lib/RuntimeTemplate.js:607–630  ·  view source on GitHub ↗

* Returns the code. * @param {object} options options object * @param {ChunkGraph} options.chunkGraph the chunk graph * @param {Module} options.module the module * @param {string=} options.request the request that should be printed as comment * @param {string=} options.idExpr expression to

({ module, chunkGraph, request, idExpr, type })

Source from the content-addressed store, hash-verified

605 * @returns {string} the code
606 */
607 weakError({ module, chunkGraph, request, idExpr, type }) {
608 const moduleId = chunkGraph.getModuleId(module);
609 const errorMessage =
610 moduleId === null
611 ? JSON.stringify("Module is not available (weak dependency)")
612 : idExpr
613 ? `"Module '" + ${idExpr} + "' is not available (weak dependency)"`
614 : JSON.stringify(
615 `Module '${moduleId}' is not available (weak dependency)`
616 );
617 const comment = request ? `${Template.toNormalComment(request)} ` : "";
618 const errorStatements = `${this.renderConst()} e = new Error(${errorMessage}); ${comment}e.code = 'MODULE_NOT_FOUND'; throw e;`;
619 switch (type) {
620 case "statements":
621 return errorStatements;
622 case "promise":
623 return `Promise.resolve().then(${this.basicFunction(
624 "",
625 errorStatements
626 )})`;
627 case "expression":
628 return this.iife("", errorStatements);
629 }
630 }
631
632 /**
633 * Returns the expression.

Callers 4

moduleRawMethod · 0.95
moduleNamespaceMethod · 0.95
importStatementMethod · 0.95

Calls 5

renderConstMethod · 0.95
basicFunctionMethod · 0.95
iifeMethod · 0.95
getModuleIdMethod · 0.80
toNormalCommentMethod · 0.80

Tested by

no test coverage detected