2017-05-05 00:37:25 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-05-05 00:37:25 +08:00
|
|
|
"use strict";
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2018-10-11 22:32:53 +08:00
|
|
|
const makeSerializable = require("../util/makeSerializable");
|
2020-06-10 19:31:01 +08:00
|
|
|
const ImportDependency = require("./ImportDependency");
|
2017-05-05 00:37:25 +08:00
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
2018-07-30 23:08:51 +08:00
|
|
|
/** @typedef {import("../Dependency")} Dependency */
|
2018-07-18 01:38:42 +08:00
|
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
2023-06-17 02:24:34 +08:00
|
|
|
/** @typedef {import("../Module")} Module */
|
|
|
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
2024-06-11 00:21:03 +08:00
|
|
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
2023-05-22 04:31:30 +08:00
|
|
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
2025-09-11 08:10:10 +08:00
|
|
|
/** @typedef {ImportDependency.RawReferencedExports} RawReferencedExports */
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2020-06-10 19:31:01 +08:00
|
|
|
class ImportEagerDependency extends ImportDependency {
|
|
|
|
/**
|
|
|
|
* @param {string} request the request
|
2023-05-22 04:31:30 +08:00
|
|
|
* @param {Range} range expression range
|
2025-09-11 08:10:10 +08:00
|
|
|
* @param {RawReferencedExports | null=} referencedExports list of referenced exports
|
2024-06-11 00:21:03 +08:00
|
|
|
* @param {ImportAttributes=} attributes import attributes
|
2020-06-10 19:31:01 +08:00
|
|
|
*/
|
2024-03-15 23:11:02 +08:00
|
|
|
constructor(request, range, referencedExports, attributes) {
|
|
|
|
super(request, range, referencedExports, attributes);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get type() {
|
2017-12-19 22:50:09 +08:00
|
|
|
return "import() eager";
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2020-05-31 17:48:45 +08:00
|
|
|
|
|
|
|
get category() {
|
|
|
|
return "esm";
|
|
|
|
}
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
|
|
|
|
2018-10-11 22:32:53 +08:00
|
|
|
makeSerializable(
|
|
|
|
ImportEagerDependency,
|
|
|
|
"webpack/lib/dependencies/ImportEagerDependency"
|
|
|
|
);
|
|
|
|
|
2020-11-26 17:52:55 +08:00
|
|
|
ImportEagerDependency.Template = class ImportEagerDependencyTemplate extends (
|
|
|
|
ImportDependency.Template
|
|
|
|
) {
|
2018-07-23 23:33:29 +08:00
|
|
|
/**
|
|
|
|
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
|
|
* @param {ReplaceSource} source the current replace source which can be modified
|
2018-07-18 01:38:42 +08:00
|
|
|
* @param {DependencyTemplateContext} templateContext the context object
|
2018-07-23 23:33:29 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-08-23 02:17:49 +08:00
|
|
|
apply(
|
|
|
|
dependency,
|
|
|
|
source,
|
2018-11-17 01:18:44 +08:00
|
|
|
{ runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
|
2018-08-23 02:17:49 +08:00
|
|
|
) {
|
2018-07-23 23:33:29 +08:00
|
|
|
const dep = /** @type {ImportEagerDependency} */ (dependency);
|
|
|
|
const content = runtimeTemplate.moduleNamespacePromise({
|
2018-08-23 02:17:49 +08:00
|
|
|
chunkGraph,
|
2023-06-17 02:24:34 +08:00
|
|
|
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
2017-12-19 22:50:09 +08:00
|
|
|
request: dep.request,
|
2023-06-17 02:24:34 +08:00
|
|
|
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
2018-11-17 01:18:44 +08:00
|
|
|
message: "import() eager",
|
|
|
|
runtimeRequirements
|
2017-12-19 22:50:09 +08:00
|
|
|
});
|
2018-10-11 22:32:53 +08:00
|
|
|
|
2017-05-05 00:37:25 +08:00
|
|
|
source.replace(dep.range[0], dep.range[1] - 1, content);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ImportEagerDependency;
|