source: imaps-frontend/node_modules/webpack/lib/dependencies/LocalModuleDependency.js@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const makeSerializable = require("../util/makeSerializable");
9const NullDependency = require("./NullDependency");
10
11/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12/** @typedef {import("../Dependency")} Dependency */
13/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
14/** @typedef {import("../javascript/JavascriptParser").Range} Range */
15/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17/** @typedef {import("./LocalModule")} LocalModule */
18
19class LocalModuleDependency extends NullDependency {
20 /**
21 * @param {LocalModule} localModule local module
22 * @param {Range | undefined} range range
23 * @param {boolean} callNew true, when the local module should be called with new
24 */
25 constructor(localModule, range, callNew) {
26 super();
27
28 this.localModule = localModule;
29 this.range = range;
30 this.callNew = callNew;
31 }
32
33 /**
34 * @param {ObjectSerializerContext} context context
35 */
36 serialize(context) {
37 const { write } = context;
38
39 write(this.localModule);
40 write(this.range);
41 write(this.callNew);
42
43 super.serialize(context);
44 }
45
46 /**
47 * @param {ObjectDeserializerContext} context context
48 */
49 deserialize(context) {
50 const { read } = context;
51
52 this.localModule = read();
53 this.range = read();
54 this.callNew = read();
55
56 super.deserialize(context);
57 }
58}
59
60makeSerializable(
61 LocalModuleDependency,
62 "webpack/lib/dependencies/LocalModuleDependency"
63);
64
65LocalModuleDependency.Template = class LocalModuleDependencyTemplate extends (
66 NullDependency.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 dep = /** @type {LocalModuleDependency} */ (dependency);
76 if (!dep.range) return;
77 const moduleInstance = dep.callNew
78 ? `new (function () { return ${dep.localModule.variableName()}; })()`
79 : dep.localModule.variableName();
80 source.replace(dep.range[0], dep.range[1] - 1, moduleInstance);
81 }
82};
83
84module.exports = LocalModuleDependency;
Note: See TracBrowser for help on using the repository browser.