binding.js
2.41 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* This class is responsible for a binding inside of a scope.
*
* It tracks the following:
*
* * Node path.
* * Amount of times referenced by other nodes.
* * Paths to nodes that reassign or modify this binding.
* * The kind of binding. (Is it a parameter, declaration etc)
*/
"use strict";
exports.__esModule = true;
// istanbul ignore next
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Binding = (function () {
function Binding(_ref) {
var existing = _ref.existing;
var identifier = _ref.identifier;
var scope = _ref.scope;
var path = _ref.path;
var kind = _ref.kind;
_classCallCheck(this, Binding);
this.constantViolations = [];
this.constant = true;
this.identifier = identifier;
this.references = 0;
this.referenced = false;
this.scope = scope;
this.path = path;
this.kind = kind;
this.hasValue = false;
this.hasDeoptedValue = false;
this.value = null;
this.clearValue();
if (existing) {
this.constantViolations = [].concat(existing.path, existing.constantViolations, this.constantViolations);
}
}
/**
* [Please add a description.]
*/
Binding.prototype.deoptValue = function deoptValue() {
this.clearValue();
this.hasDeoptedValue = true;
};
/**
* [Please add a description.]
*/
Binding.prototype.setValue = function setValue(value) {
if (this.hasDeoptedValue) return;
this.hasValue = true;
this.value = value;
};
/**
* [Please add a description.]
*/
Binding.prototype.clearValue = function clearValue() {
this.hasDeoptedValue = false;
this.hasValue = false;
this.value = null;
};
/**
* Register a constant violation with the provided `path`.
*/
Binding.prototype.reassign = function reassign(path) {
this.constant = false;
this.constantViolations.push(path);
};
/**
* Increment the amount of references to this binding.
*/
Binding.prototype.reference = function reference() {
this.referenced = true;
this.references++;
};
/**
* Decrement the amount of references to this binding.
*/
Binding.prototype.dereference = function dereference() {
this.references--;
this.referenced = !!this.references;
};
return Binding;
})();
exports["default"] = Binding;
module.exports = exports["default"];