source: frontend/node_modules/webpack/lib/dependencies/WebpackIsIncludedDependency.js@ cdcff72

Last change on this file since cdcff72 was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Ivan Kopeykin @vankop
4*/
5
6"use strict";
7
8const Dependency = require("../Dependency");
9const Template = require("../Template");
10const makeSerializable = require("../util/makeSerializable");
11const ModuleDependency = require("./ModuleDependency");
12
13/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
15/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16/** @typedef {import("../ModuleGraph")} ModuleGraph */
17/** @typedef {import("../javascript/JavascriptParser").Range} Range */
18/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
19
20class WebpackIsIncludedDependency extends ModuleDependency {
21 /**
22 * Creates an instance of WebpackIsIncludedDependency.
23 * @param {string} request the request string
24 * @param {Range} range location in source code
25 */
26 constructor(request, range) {
27 super(request);
28
29 this.weak = true;
30 this.range = range;
31 }
32
33 /**
34 * Returns list of exports referenced by this dependency
35 * @param {ModuleGraph} moduleGraph module graph
36 * @param {RuntimeSpec} runtime the runtime for which the module is analysed
37 * @returns {ReferencedExports} referenced exports
38 */
39 getReferencedExports(moduleGraph, runtime) {
40 // This doesn't use any export
41 return Dependency.NO_EXPORTS_REFERENCED;
42 }
43
44 get type() {
45 return "__webpack_is_included__";
46 }
47}
48
49makeSerializable(
50 WebpackIsIncludedDependency,
51 "webpack/lib/dependencies/WebpackIsIncludedDependency"
52);
53
54WebpackIsIncludedDependency.Template = class WebpackIsIncludedDependencyTemplate extends (
55 ModuleDependency.Template
56) {
57 /**
58 * Applies the plugin by registering its hooks on the compiler.
59 * @param {Dependency} dependency the dependency for which the template should be applied
60 * @param {ReplaceSource} source the current replace source which can be modified
61 * @param {DependencyTemplateContext} templateContext the context object
62 * @returns {void}
63 */
64 apply(dependency, source, { runtimeTemplate, chunkGraph, moduleGraph }) {
65 const dep = /** @type {WebpackIsIncludedDependency} */ (dependency);
66 const connection = moduleGraph.getConnection(dep);
67 const included = connection
68 ? chunkGraph.getNumberOfModuleChunks(connection.module) > 0
69 : false;
70 const comment = runtimeTemplate.outputOptions.pathinfo
71 ? Template.toComment(
72 `__webpack_is_included__ ${runtimeTemplate.requestShortener.shorten(
73 dep.request
74 )}`
75 )
76 : "";
77
78 source.replace(
79 dep.range[0],
80 dep.range[1] - 1,
81 `${comment}${JSON.stringify(included)}`
82 );
83 }
84};
85
86module.exports = WebpackIsIncludedDependency;
Note: See TracBrowser for help on using the repository browser.