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