1
|
/*
|
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
Author Tobias Koppers @sokra
|
4
|
*/
|
5
|
"use strict";
|
6
|
|
7
|
const util = require("util");
|
8
|
const compareLocations = require("./compareLocations");
|
9
|
const DependencyReference = require("./dependencies/DependencyReference");
|
10
|
|
11
|
/** @typedef {import("./Module")} Module */
|
12
|
/** @typedef {import("webpack-sources").Source} Source */
|
13
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
14
|
|
15
|
/**
|
16
|
* @typedef {Object} DependencyTemplate
|
17
|
* @property {function(Dependency, Source, RuntimeTemplate, Map<Function, DependencyTemplate>): void} apply
|
18
|
*/
|
19
|
|
20
|
/** @typedef {Object} SourcePosition
|
21
|
* @property {number} line
|
22
|
* @property {number=} column
|
23
|
*/
|
24
|
|
25
|
/** @typedef {Object} RealDependencyLocation
|
26
|
* @property {SourcePosition} start
|
27
|
* @property {SourcePosition=} end
|
28
|
* @property {number=} index
|
29
|
*/
|
30
|
|
31
|
/** @typedef {Object} SynteticDependencyLocation
|
32
|
* @property {string} name
|
33
|
* @property {number=} index
|
34
|
*/
|
35
|
|
36
|
/** @typedef {SynteticDependencyLocation|RealDependencyLocation} DependencyLocation */
|
37
|
|
38
|
class Dependency {
|
39
|
constructor() {
|
40
|
/** @type {Module|null} */
|
41
|
this.module = null;
|
42
|
// TODO remove in webpack 5
|
43
|
/** @type {boolean} */
|
44
|
this.weak = false;
|
45
|
/** @type {boolean} */
|
46
|
this.optional = false;
|
47
|
/** @type {DependencyLocation} */
|
48
|
this.loc = undefined;
|
49
|
}
|
50
|
|
51
|
getResourceIdentifier() {
|
52
|
return null;
|
53
|
}
|
54
|
|
55
|
// Returns the referenced module and export
|
56
|
getReference() {
|
57
|
if (!this.module) return null;
|
58
|
return new DependencyReference(this.module, true, this.weak);
|
59
|
}
|
60
|
|
61
|
// Returns the exported names
|
62
|
getExports() {
|
63
|
return null;
|
64
|
}
|
65
|
|
66
|
getWarnings() {
|
67
|
return null;
|
68
|
}
|
69
|
|
70
|
getErrors() {
|
71
|
return null;
|
72
|
}
|
73
|
|
74
|
updateHash(hash) {
|
75
|
hash.update((this.module && this.module.id) + "");
|
76
|
}
|
77
|
|
78
|
disconnect() {
|
79
|
this.module = null;
|
80
|
}
|
81
|
}
|
82
|
|
83
|
// TODO remove in webpack 5
|
84
|
Dependency.compare = util.deprecate(
|
85
|
(a, b) => compareLocations(a.loc, b.loc),
|
86
|
"Dependency.compare is deprecated and will be removed in the next major version"
|
87
|
);
|
88
|
|
89
|
module.exports = Dependency;
|