source: trip-planner-front/node_modules/webpack/lib/dependencies/LocalModuleDependency.js@ e29cc2e

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

initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[6a3a178]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
15class LocalModuleDependency extends NullDependency {
16 constructor(localModule, range, callNew) {
17 super();
18
19 this.localModule = localModule;
20 this.range = range;
21 this.callNew = callNew;
22 }
23
24 serialize(context) {
25 const { write } = context;
26
27 write(this.localModule);
28 write(this.range);
29 write(this.callNew);
30
31 super.serialize(context);
32 }
33
34 deserialize(context) {
35 const { read } = context;
36
37 this.localModule = read();
38 this.range = read();
39 this.callNew = read();
40
41 super.deserialize(context);
42 }
43}
44
45makeSerializable(
46 LocalModuleDependency,
47 "webpack/lib/dependencies/LocalModuleDependency"
48);
49
50LocalModuleDependency.Template = class LocalModuleDependencyTemplate extends (
51 NullDependency.Template
52) {
53 /**
54 * @param {Dependency} dependency the dependency for which the template should be applied
55 * @param {ReplaceSource} source the current replace source which can be modified
56 * @param {DependencyTemplateContext} templateContext the context object
57 * @returns {void}
58 */
59 apply(dependency, source, templateContext) {
60 const dep = /** @type {LocalModuleDependency} */ (dependency);
61 if (!dep.range) return;
62 const moduleInstance = dep.callNew
63 ? `new (function () { return ${dep.localModule.variableName()}; })()`
64 : dep.localModule.variableName();
65 source.replace(dep.range[0], dep.range[1] - 1, moduleInstance);
66 }
67};
68
69module.exports = LocalModuleDependency;
Note: See TracBrowser for help on using the repository browser.