[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const makeSerializable = require("../util/makeSerializable");
|
---|
| 9 | const ImportDependency = require("./ImportDependency");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
| 12 | /** @typedef {import("../Dependency")} Dependency */
|
---|
| 13 | /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
---|
| 14 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
| 15 | /** @typedef {import("../ModuleGraph")} ModuleGraph */
|
---|
| 16 |
|
---|
| 17 | class ImportWeakDependency extends ImportDependency {
|
---|
| 18 | /**
|
---|
| 19 | * @param {string} request the request
|
---|
| 20 | * @param {[number, number]} range expression range
|
---|
| 21 | * @param {string[][]=} referencedExports list of referenced exports
|
---|
| 22 | */
|
---|
| 23 | constructor(request, range, referencedExports) {
|
---|
| 24 | super(request, range, referencedExports);
|
---|
| 25 | this.weak = true;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | get type() {
|
---|
| 29 | return "import() weak";
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | makeSerializable(
|
---|
| 34 | ImportWeakDependency,
|
---|
| 35 | "webpack/lib/dependencies/ImportWeakDependency"
|
---|
| 36 | );
|
---|
| 37 |
|
---|
| 38 | ImportWeakDependency.Template = class ImportDependencyTemplate extends (
|
---|
| 39 | ImportDependency.Template
|
---|
| 40 | ) {
|
---|
| 41 | /**
|
---|
| 42 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 43 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 44 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 45 | * @returns {void}
|
---|
| 46 | */
|
---|
| 47 | apply(
|
---|
| 48 | dependency,
|
---|
| 49 | source,
|
---|
| 50 | { runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
|
---|
| 51 | ) {
|
---|
| 52 | const dep = /** @type {ImportWeakDependency} */ (dependency);
|
---|
| 53 | const content = runtimeTemplate.moduleNamespacePromise({
|
---|
| 54 | chunkGraph,
|
---|
| 55 | module: moduleGraph.getModule(dep),
|
---|
| 56 | request: dep.request,
|
---|
| 57 | strict: module.buildMeta.strictHarmonyModule,
|
---|
| 58 | message: "import() weak",
|
---|
| 59 | weak: true,
|
---|
| 60 | runtimeRequirements
|
---|
| 61 | });
|
---|
| 62 |
|
---|
| 63 | source.replace(dep.range[0], dep.range[1] - 1, content);
|
---|
| 64 | }
|
---|
| 65 | };
|
---|
| 66 |
|
---|
| 67 | module.exports = ImportWeakDependency;
|
---|