source: imaps-frontend/node_modules/webpack/lib/dependencies/RequireResolveHeaderDependency.js

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[79a0317]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
18class RequireResolveHeaderDependency extends NullDependency {
19 /**
20 * @param {Range} range range
21 */
22 constructor(range) {
23 super();
24
25 if (!Array.isArray(range)) throw new Error("range must be valid");
26
27 this.range = range;
28 }
29
30 /**
31 * @param {ObjectSerializerContext} context context
32 */
33 serialize(context) {
34 const { write } = context;
35
36 write(this.range);
37
38 super.serialize(context);
39 }
40
41 /**
42 * @param {ObjectDeserializerContext} context context
43 * @returns {RequireResolveHeaderDependency} RequireResolveHeaderDependency
44 */
45 static deserialize(context) {
46 const obj = new RequireResolveHeaderDependency(context.read());
47 obj.deserialize(context);
48 return obj;
49 }
50}
51
52makeSerializable(
53 RequireResolveHeaderDependency,
54 "webpack/lib/dependencies/RequireResolveHeaderDependency"
55);
56
57RequireResolveHeaderDependency.Template = class RequireResolveHeaderDependencyTemplate extends (
58 NullDependency.Template
59) {
60 /**
61 * @param {Dependency} dependency the dependency for which the template should be applied
62 * @param {ReplaceSource} source the current replace source which can be modified
63 * @param {DependencyTemplateContext} templateContext the context object
64 * @returns {void}
65 */
66 apply(dependency, source, templateContext) {
67 const dep = /** @type {RequireResolveHeaderDependency} */ (dependency);
68 source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
69 }
70
71 /**
72 * @param {string} name name
73 * @param {RequireResolveHeaderDependency} dep dependency
74 * @param {ReplaceSource} source source
75 */
76 applyAsTemplateArgument(name, dep, source) {
77 source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
78 }
79};
80
81module.exports = RequireResolveHeaderDependency;
Note: See TracBrowser for help on using the repository browser.