source: imaps-frontend/node_modules/webpack/lib/dependencies/WebpackIsIncludedDependency.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.6 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("../Compilation")} Compilation */
15/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
16/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
17/** @typedef {import("../ModuleGraph")} ModuleGraph */
18/** @typedef {import("../javascript/JavascriptParser").Range} Range */
19/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
20
21class WebpackIsIncludedDependency extends ModuleDependency {
22 /**
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 {(string[] | ReferencedExport)[]} 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 * @param {Dependency} dependency the dependency for which the template should be applied
59 * @param {ReplaceSource} source the current replace source which can be modified
60 * @param {DependencyTemplateContext} templateContext the context object
61 * @returns {void}
62 */
63 apply(dependency, source, { runtimeTemplate, chunkGraph, moduleGraph }) {
64 const dep = /** @type {WebpackIsIncludedDependency} */ (dependency);
65 const connection = moduleGraph.getConnection(dep);
66 const included = connection
67 ? chunkGraph.getNumberOfModuleChunks(connection.module) > 0
68 : false;
69 const comment = runtimeTemplate.outputOptions.pathinfo
70 ? Template.toComment(
71 `__webpack_is_included__ ${runtimeTemplate.requestShortener.shorten(
72 dep.request
73 )}`
74 )
75 : "";
76
77 source.replace(
78 dep.range[0],
79 dep.range[1] - 1,
80 `${comment}${JSON.stringify(included)}`
81 );
82 }
83};
84
85module.exports = WebpackIsIncludedDependency;
Note: See TracBrowser for help on using the repository browser.