2017-08-08 15:32:43 +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-08-08 15:32:43 +08:00
|
|
|
"use strict";
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2018-10-09 20:30:59 +08:00
|
|
|
const makeSerializable = require("../util/makeSerializable");
|
2017-08-08 15:32:43 +08:00
|
|
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
|
|
|
2018-11-18 20:26:15 +08:00
|
|
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
2018-07-27 17:45:12 +08:00
|
|
|
/** @typedef {import("../Dependency")} Dependency */
|
2024-02-22 22:36:36 +08:00
|
|
|
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
2018-07-18 01:38:42 +08:00
|
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
2020-10-05 22:57:31 +08:00
|
|
|
/** @typedef {import("../Module")} Module */
|
2018-07-24 23:35:36 +08:00
|
|
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
2020-07-28 00:09:48 +08:00
|
|
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
2020-10-05 22:57:31 +08:00
|
|
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
2024-03-15 23:11:02 +08:00
|
|
|
/** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
|
2019-07-17 22:02:33 +08:00
|
|
|
/** @typedef {import("../util/Hash")} Hash */
|
2020-07-28 00:09:48 +08:00
|
|
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
2018-07-25 15:33:48 +08:00
|
|
|
|
2017-08-08 15:32:43 +08:00
|
|
|
class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
2023-05-22 04:31:30 +08:00
|
|
|
/**
|
2024-03-15 23:11:02 +08:00
|
|
|
* @param {string} request the request string
|
2023-05-22 04:31:30 +08:00
|
|
|
* @param {number} sourceOrder source order
|
2024-03-15 23:11:02 +08:00
|
|
|
* @param {Attributes=} attributes assertions
|
2023-05-22 04:31:30 +08:00
|
|
|
*/
|
2024-03-15 23:11:02 +08:00
|
|
|
constructor(request, sourceOrder, attributes) {
|
|
|
|
super(request, sourceOrder, attributes);
|
2017-08-08 15:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "harmony side effect evaluation";
|
|
|
|
}
|
2020-01-30 18:59:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {ModuleGraph} moduleGraph module graph
|
2024-02-22 22:20:17 +08:00
|
|
|
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
2020-01-30 18:59:34 +08:00
|
|
|
*/
|
|
|
|
getCondition(moduleGraph) {
|
|
|
|
return connection => {
|
|
|
|
const refModule = connection.resolvedModule;
|
2020-10-05 22:57:31 +08:00
|
|
|
if (!refModule) return true;
|
|
|
|
return refModule.getSideEffectsConnectionState(moduleGraph);
|
2020-01-30 18:59:34 +08:00
|
|
|
};
|
|
|
|
}
|
2020-10-05 22:57:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
|
|
* @returns {ConnectionState} how this dependency connects the module to referencing modules
|
|
|
|
*/
|
|
|
|
getModuleEvaluationSideEffectsState(moduleGraph) {
|
|
|
|
const refModule = moduleGraph.getModule(this);
|
|
|
|
if (!refModule) return true;
|
|
|
|
return refModule.getSideEffectsConnectionState(moduleGraph);
|
|
|
|
}
|
2017-08-08 15:32:43 +08:00
|
|
|
}
|
|
|
|
|
2018-10-09 20:30:59 +08:00
|
|
|
makeSerializable(
|
|
|
|
HarmonyImportSideEffectDependency,
|
|
|
|
"webpack/lib/dependencies/HarmonyImportSideEffectDependency"
|
|
|
|
);
|
|
|
|
|
2020-11-26 17:52:55 +08:00
|
|
|
HarmonyImportSideEffectDependency.Template = class HarmonyImportSideEffectDependencyTemplate extends (
|
|
|
|
HarmonyImportDependency.Template
|
|
|
|
) {
|
2020-09-11 15:11:58 +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
|
|
|
|
* @param {DependencyTemplateContext} templateContext the context object
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
apply(dependency, source, templateContext) {
|
|
|
|
const { moduleGraph, concatenationScope } = templateContext;
|
|
|
|
if (concatenationScope) {
|
2023-06-17 03:44:20 +08:00
|
|
|
const module = /** @type {Module} */ (moduleGraph.getModule(dependency));
|
2020-09-11 15:11:58 +08:00
|
|
|
if (concatenationScope.isModuleInScope(module)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.apply(dependency, source, templateContext);
|
|
|
|
}
|
|
|
|
};
|
2017-08-08 15:32:43 +08:00
|
|
|
|
|
|
|
module.exports = HarmonyImportSideEffectDependency;
|