forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependency.js
63 lines (57 loc) · 1.46 KB
/
Dependency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
function Dependency() {
this.module = null;
}
module.exports = Dependency;
Dependency.prototype.isEqualResource = function( /* other */ ) {
return false;
};
// Returns the referenced module and export
Dependency.prototype.getReference = function() {
if(!this.module) return null;
return {
module: this.module,
importedNames: true, // true: full object, false: only sideeffects/no export, array of strings: the exports with this names
}
}
Dependency.prototype.updateHash = function(hash) {
hash.update((this.module && this.module.id) + "");
};
Dependency.prototype.disconnect = function() {
this.module = null;
};
Dependency.compare = function(a, b) {
return Dependency.compareLocations(a.loc, b.loc);
};
Dependency.compareLocations = function(a, b) {
if(typeof a === "string") {
if(typeof b === "string") {
if(a < b) return -1;
if(a > b) return 1;
return 0;
} else if(typeof b === "object") {
return 1;
} else {
return 0;
}
} else if(typeof a === "object") {
if(typeof b === "string") {
return -1;
} else if(typeof b === "object") {
if(a.start) a = a.start;
if(b.start) b = b.start;
if(a.line < b.line) return -1;
if(a.line > b.line) return 1;
if(a.column < b.column) return -1;
if(a.column > b.column) return 1;
if(a.index < b.index) return -1;
if(a.index > b.index) return 1;
return 0;
} else {
return 0;
}
}
};