[79a0317] | 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("../Module")} Module */
|
---|
| 16 | /** @typedef {import("../Module").BuildMeta} BuildMeta */
|
---|
| 17 | /** @typedef {import("../ModuleGraph")} ModuleGraph */
|
---|
| 18 | /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
---|
| 19 | /** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
---|
| 20 |
|
---|
| 21 | class ImportWeakDependency extends ImportDependency {
|
---|
| 22 | /**
|
---|
| 23 | * @param {string} request the request
|
---|
| 24 | * @param {Range} range expression range
|
---|
| 25 | * @param {(string[][] | null)=} referencedExports list of referenced exports
|
---|
| 26 | * @param {ImportAttributes=} attributes import attributes
|
---|
| 27 | */
|
---|
| 28 | constructor(request, range, referencedExports, attributes) {
|
---|
| 29 | super(request, range, referencedExports, attributes);
|
---|
| 30 | this.weak = true;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | get type() {
|
---|
| 34 | return "import() weak";
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | makeSerializable(
|
---|
| 39 | ImportWeakDependency,
|
---|
| 40 | "webpack/lib/dependencies/ImportWeakDependency"
|
---|
| 41 | );
|
---|
| 42 |
|
---|
| 43 | ImportWeakDependency.Template = class ImportDependencyTemplate extends (
|
---|
| 44 | ImportDependency.Template
|
---|
| 45 | ) {
|
---|
| 46 | /**
|
---|
| 47 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 48 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 49 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 50 | * @returns {void}
|
---|
| 51 | */
|
---|
| 52 | apply(
|
---|
| 53 | dependency,
|
---|
| 54 | source,
|
---|
| 55 | { runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
|
---|
| 56 | ) {
|
---|
| 57 | const dep = /** @type {ImportWeakDependency} */ (dependency);
|
---|
| 58 | const content = runtimeTemplate.moduleNamespacePromise({
|
---|
| 59 | chunkGraph,
|
---|
| 60 | module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
---|
| 61 | request: dep.request,
|
---|
| 62 | strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
---|
| 63 | message: "import() weak",
|
---|
| 64 | weak: true,
|
---|
| 65 | runtimeRequirements
|
---|
| 66 | });
|
---|
| 67 |
|
---|
| 68 | source.replace(dep.range[0], dep.range[1] - 1, content);
|
---|
| 69 | }
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | module.exports = ImportWeakDependency;
|
---|