source: frontend/node_modules/webpack/lib/dependencies/LocalModuleDependency.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 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 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 * Creates an instance of LocalModuleDependency.
22 * @param {LocalModule} localModule local module
23 * @param {Range | undefined} range range
24 * @param {boolean} callNew true, when the local module should be called with new
25 */
26 constructor(localModule, range, callNew) {
27 super();
28
29 this.localModule = localModule;
30 this.range = range;
31 this.callNew = callNew;
32 }
33
34 /**
35 * Serializes this instance into the provided serializer context.
36 * @param {ObjectSerializerContext} context context
37 */
38 serialize(context) {
39 const { write } = context;
40
41 write(this.localModule);
42 write(this.range);
43 write(this.callNew);
44
45 super.serialize(context);
46 }
47
48 /**
49 * Restores this instance from the provided deserializer context.
50 * @param {ObjectDeserializerContext} context context
51 */
52 deserialize(context) {
53 const { read } = context;
54
55 this.localModule = read();
56 this.range = read();
57 this.callNew = read();
58
59 super.deserialize(context);
60 }
61}
62
63makeSerializable(
64 LocalModuleDependency,
65 "webpack/lib/dependencies/LocalModuleDependency"
66);
67
68LocalModuleDependency.Template = class LocalModuleDependencyTemplate extends (
69 NullDependency.Template
70) {
71 /**
72 * Applies the plugin by registering its hooks on the compiler.
73 * @param {Dependency} dependency the dependency for which the template should be applied
74 * @param {ReplaceSource} source the current replace source which can be modified
75 * @param {DependencyTemplateContext} templateContext the context object
76 * @returns {void}
77 */
78 apply(dependency, source, templateContext) {
79 const dep = /** @type {LocalModuleDependency} */ (dependency);
80 if (!dep.range) return;
81 const moduleInstance = dep.callNew
82 ? `new (function () { return ${dep.localModule.variableName()}; })()`
83 : dep.localModule.variableName();
84 source.replace(dep.range[0], dep.range[1] - 1, moduleInstance);
85 }
86};
87
88module.exports = LocalModuleDependency;
Note: See TracBrowser for help on using the repository browser.