* 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 })
| 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. |
no test coverage detected