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

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.4 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 RuntimeGlobals = require("../RuntimeGlobals");
9const makeSerializable = require("../util/makeSerializable");
10const NullDependency = require("./NullDependency");
11
12/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13/** @typedef {import("../Dependency")} Dependency */
14/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15/** @typedef {import("../javascript/JavascriptParser").Range} Range */
16/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
18
19class RequireHeaderDependency extends NullDependency {
20 /**
21 * Creates an instance of RequireHeaderDependency.
22 * @param {Range} range range
23 */
24 constructor(range) {
25 super();
26 if (!Array.isArray(range)) throw new Error("range must be valid");
27 this.range = range;
28 }
29
30 /**
31 * Serializes this instance into the provided serializer context.
32 * @param {ObjectSerializerContext} context context
33 */
34 serialize(context) {
35 const { write } = context;
36 write(this.range);
37 super.serialize(context);
38 }
39
40 /**
41 * Restores this instance from the provided deserializer context.
42 * @param {ObjectDeserializerContext} context context
43 * @returns {RequireHeaderDependency} RequireHeaderDependency
44 */
45 static deserialize(context) {
46 const obj = new RequireHeaderDependency(context.read());
47 obj.deserialize(context);
48 return obj;
49 }
50}
51
52makeSerializable(
53 RequireHeaderDependency,
54 "webpack/lib/dependencies/RequireHeaderDependency"
55);
56
57RequireHeaderDependency.Template = class RequireHeaderDependencyTemplate extends (
58 NullDependency.Template
59) {
60 /**
61 * Applies the plugin by registering its hooks on the compiler.
62 * @param {Dependency} dependency the dependency for which the template should be applied
63 * @param {ReplaceSource} source the current replace source which can be modified
64 * @param {DependencyTemplateContext} templateContext the context object
65 * @returns {void}
66 */
67 apply(dependency, source, { runtimeRequirements }) {
68 const dep = /** @type {RequireHeaderDependency} */ (dependency);
69 runtimeRequirements.add(RuntimeGlobals.require);
70 source.replace(dep.range[0], dep.range[1] - 1, RuntimeGlobals.require);
71 }
72};
73
74module.exports = RequireHeaderDependency;
Note: See TracBrowser for help on using the repository browser.