source: trip-planner-front/node_modules/webpack/lib/dependencies/AMDRequireArrayDependency.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 2.4 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 DependencyTemplate = require("../DependencyTemplate");
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
16class AMDRequireArrayDependency extends NullDependency {
17 constructor(depsArray, range) {
18 super();
19
20 this.depsArray = depsArray;
21 this.range = range;
22 }
23
24 get type() {
25 return "amd require array";
26 }
27
28 get category() {
29 return "amd";
30 }
31
32 serialize(context) {
33 const { write } = context;
34
35 write(this.depsArray);
36 write(this.range);
37
38 super.serialize(context);
39 }
40
41 deserialize(context) {
42 const { read } = context;
43
44 this.depsArray = read();
45 this.range = read();
46
47 super.deserialize(context);
48 }
49}
50
51makeSerializable(
52 AMDRequireArrayDependency,
53 "webpack/lib/dependencies/AMDRequireArrayDependency"
54);
55
56AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate extends (
57 DependencyTemplate
58) {
59 /**
60 * @param {Dependency} dependency the dependency for which the template should be applied
61 * @param {ReplaceSource} source the current replace source which can be modified
62 * @param {DependencyTemplateContext} templateContext the context object
63 * @returns {void}
64 */
65 apply(dependency, source, templateContext) {
66 const dep = /** @type {AMDRequireArrayDependency} */ (dependency);
67 const content = this.getContent(dep, templateContext);
68 source.replace(dep.range[0], dep.range[1] - 1, content);
69 }
70
71 getContent(dep, templateContext) {
72 const requires = dep.depsArray.map(dependency => {
73 return this.contentForDependency(dependency, templateContext);
74 });
75 return `[${requires.join(", ")}]`;
76 }
77
78 contentForDependency(
79 dep,
80 { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
81 ) {
82 if (typeof dep === "string") {
83 return dep;
84 }
85
86 if (dep.localModule) {
87 return dep.localModule.variableName();
88 } else {
89 return runtimeTemplate.moduleExports({
90 module: moduleGraph.getModule(dep),
91 chunkGraph,
92 request: dep.request,
93 runtimeRequirements
94 });
95 }
96 }
97};
98
99module.exports = AMDRequireArrayDependency;
Note: See TracBrowser for help on using the repository browser.