* Returns the import statement and the compat statement. * @param {object} options options object * @param {boolean=} options.update whether a new variable should be created or the existing one updated * @param {Module} options.module the module * @param {Module} options.originModule module
({
update,
module,
moduleGraph,
chunkGraph,
request,
importVar,
originModule,
weak,
dependency,
runtimeRequirements
})
| 1046 | * @returns {[string, string]} the import statement and the compat statement |
| 1047 | */ |
| 1048 | importStatement({ |
| 1049 | update, |
| 1050 | module, |
| 1051 | moduleGraph, |
| 1052 | chunkGraph, |
| 1053 | request, |
| 1054 | importVar, |
| 1055 | originModule, |
| 1056 | weak, |
| 1057 | dependency, |
| 1058 | runtimeRequirements |
| 1059 | }) { |
| 1060 | if (!module) { |
| 1061 | return [ |
| 1062 | this.missingModuleStatement({ |
| 1063 | request |
| 1064 | }), |
| 1065 | "" |
| 1066 | ]; |
| 1067 | } |
| 1068 | |
| 1069 | if (chunkGraph.getModuleId(module) === null) { |
| 1070 | if (weak) { |
| 1071 | // only weak referenced modules don't get an id |
| 1072 | // we can always emit an error emitting code here |
| 1073 | return [ |
| 1074 | this.weakError({ |
| 1075 | module, |
| 1076 | chunkGraph, |
| 1077 | request, |
| 1078 | type: "statements" |
| 1079 | }), |
| 1080 | "" |
| 1081 | ]; |
| 1082 | } |
| 1083 | throw new Error( |
| 1084 | `RuntimeTemplate.importStatement(): ${noModuleIdErrorMessage( |
| 1085 | module, |
| 1086 | chunkGraph |
| 1087 | )}` |
| 1088 | ); |
| 1089 | } |
| 1090 | const moduleId = this.moduleId({ |
| 1091 | module, |
| 1092 | chunkGraph, |
| 1093 | request, |
| 1094 | weak |
| 1095 | }); |
| 1096 | // Harmony imports may be wrapped in runtime-condition `if` blocks |
| 1097 | // but referenced outside those blocks (e.g. by harmony reexport), |
| 1098 | // so they must remain function-scoped (`var`) rather than |
| 1099 | // block-scoped (`let`/`const`). |
| 1100 | const optDeclaration = update ? "" : "var "; |
| 1101 | |
| 1102 | const exportsType = module.getExportsType( |
| 1103 | chunkGraph.moduleGraph, |
| 1104 | /** @type {BuildMeta} */ |
| 1105 | (originModule.buildMeta).strictHarmonyModule |
no test coverage detected