source: trip-planner-front/node_modules/webpack/lib/dependencies/WebpackIsIncludedDependency.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[6a3a178]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("../Compilation")} Compilation */
15/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
16/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
17/** @typedef {import("../ModuleGraph")} ModuleGraph */
18/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
19
20class WebpackIsIncludedDependency extends ModuleDependency {
21 constructor(request, range) {
22 super(request);
23
24 this.weak = true;
25 this.range = range;
26 }
27
28 /**
29 * Returns list of exports referenced by this dependency
30 * @param {ModuleGraph} moduleGraph module graph
31 * @param {RuntimeSpec} runtime the runtime for which the module is analysed
32 * @returns {(string[] | ReferencedExport)[]} referenced exports
33 */
34 getReferencedExports(moduleGraph, runtime) {
35 // This doesn't use any export
36 return Dependency.NO_EXPORTS_REFERENCED;
37 }
38
39 get type() {
40 return "__webpack_is_included__";
41 }
42}
43
44makeSerializable(
45 WebpackIsIncludedDependency,
46 "webpack/lib/dependencies/WebpackIsIncludedDependency"
47);
48
49WebpackIsIncludedDependency.Template = class WebpackIsIncludedDependencyTemplate extends (
50 ModuleDependency.Template
51) {
52 /**
53 * @param {Dependency} dependency the dependency for which the template should be applied
54 * @param {ReplaceSource} source the current replace source which can be modified
55 * @param {DependencyTemplateContext} templateContext the context object
56 * @returns {void}
57 */
58 apply(dependency, source, { runtimeTemplate, chunkGraph, moduleGraph }) {
59 const dep = /** @type {WebpackIsIncludedDependency} */ (dependency);
60 const connection = moduleGraph.getConnection(dep);
61 const included = connection
62 ? chunkGraph.getNumberOfModuleChunks(connection.module) > 0
63 : false;
64 const comment = runtimeTemplate.outputOptions.pathinfo
65 ? Template.toComment(
66 `__webpack_is_included__ ${runtimeTemplate.requestShortener.shorten(
67 dep.request
68 )}`
69 )
70 : "";
71
72 source.replace(
73 dep.range[0],
74 dep.range[1] - 1,
75 `${comment}${JSON.stringify(included)}`
76 );
77 }
78};
79
80module.exports = WebpackIsIncludedDependency;
Note: See TracBrowser for help on using the repository browser.