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

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.2 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 * @param {Range} range range
22 */
23 constructor(range) {
24 super();
25 if (!Array.isArray(range)) throw new Error("range must be valid");
26 this.range = range;
27 }
28
29 /**
30 * @param {ObjectSerializerContext} context context
31 */
32 serialize(context) {
33 const { write } = context;
34 write(this.range);
35 super.serialize(context);
36 }
37
38 /**
39 * @param {ObjectDeserializerContext} context context
40 * @returns {RequireHeaderDependency} RequireHeaderDependency
41 */
42 static deserialize(context) {
43 const obj = new RequireHeaderDependency(context.read());
44 obj.deserialize(context);
45 return obj;
46 }
47}
48
49makeSerializable(
50 RequireHeaderDependency,
51 "webpack/lib/dependencies/RequireHeaderDependency"
52);
53
54RequireHeaderDependency.Template = class RequireHeaderDependencyTemplate extends (
55 NullDependency.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, { runtimeRequirements }) {
64 const dep = /** @type {RequireHeaderDependency} */ (dependency);
65 runtimeRequirements.add(RuntimeGlobals.require);
66 source.replace(dep.range[0], dep.range[1] - 1, RuntimeGlobals.require);
67 }
68};
69
70module.exports = RequireHeaderDependency;
Note: See TracBrowser for help on using the repository browser.