[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 HarmonyImportDependency = require("./HarmonyImportDependency");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
| 12 | /** @typedef {import("../Dependency")} Dependency */
|
---|
| 13 | /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
---|
| 14 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
| 15 | /** @typedef {import("../Module")} Module */
|
---|
| 16 | /** @typedef {import("../ModuleGraph")} ModuleGraph */
|
---|
| 17 | /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
---|
| 18 | /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
---|
| 19 | /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
---|
| 20 | /** @typedef {import("../util/Hash")} Hash */
|
---|
| 21 | /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
---|
| 22 |
|
---|
| 23 | class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
---|
| 24 | /**
|
---|
| 25 | * @param {string} request the request string
|
---|
| 26 | * @param {number} sourceOrder source order
|
---|
| 27 | * @param {ImportAttributes=} attributes import attributes
|
---|
| 28 | */
|
---|
| 29 | constructor(request, sourceOrder, attributes) {
|
---|
| 30 | super(request, sourceOrder, attributes);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | get type() {
|
---|
| 34 | return "harmony side effect evaluation";
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * @param {ModuleGraph} moduleGraph module graph
|
---|
| 39 | * @returns {null | false | GetConditionFn} function to determine if the connection is active
|
---|
| 40 | */
|
---|
| 41 | getCondition(moduleGraph) {
|
---|
| 42 | return connection => {
|
---|
| 43 | const refModule = connection.resolvedModule;
|
---|
| 44 | if (!refModule) return true;
|
---|
| 45 | return refModule.getSideEffectsConnectionState(moduleGraph);
|
---|
| 46 | };
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * @param {ModuleGraph} moduleGraph the module graph
|
---|
| 51 | * @returns {ConnectionState} how this dependency connects the module to referencing modules
|
---|
| 52 | */
|
---|
| 53 | getModuleEvaluationSideEffectsState(moduleGraph) {
|
---|
| 54 | const refModule = moduleGraph.getModule(this);
|
---|
| 55 | if (!refModule) return true;
|
---|
| 56 | return refModule.getSideEffectsConnectionState(moduleGraph);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | makeSerializable(
|
---|
| 61 | HarmonyImportSideEffectDependency,
|
---|
| 62 | "webpack/lib/dependencies/HarmonyImportSideEffectDependency"
|
---|
| 63 | );
|
---|
| 64 |
|
---|
| 65 | HarmonyImportSideEffectDependency.Template = class HarmonyImportSideEffectDependencyTemplate extends (
|
---|
| 66 | HarmonyImportDependency.Template
|
---|
| 67 | ) {
|
---|
| 68 | /**
|
---|
| 69 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 70 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 71 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 72 | * @returns {void}
|
---|
| 73 | */
|
---|
| 74 | apply(dependency, source, templateContext) {
|
---|
| 75 | const { moduleGraph, concatenationScope } = templateContext;
|
---|
| 76 | if (concatenationScope) {
|
---|
| 77 | const module = /** @type {Module} */ (moduleGraph.getModule(dependency));
|
---|
| 78 | if (concatenationScope.isModuleInScope(module)) {
|
---|
| 79 | return;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | super.apply(dependency, source, templateContext);
|
---|
| 83 | }
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | module.exports = HarmonyImportSideEffectDependency;
|
---|