main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 | class Binding {
|
---|
8 | constructor({
|
---|
9 | identifier,
|
---|
10 | scope,
|
---|
11 | path,
|
---|
12 | kind
|
---|
13 | }) {
|
---|
14 | this.identifier = void 0;
|
---|
15 | this.scope = void 0;
|
---|
16 | this.path = void 0;
|
---|
17 | this.kind = void 0;
|
---|
18 | this.constantViolations = [];
|
---|
19 | this.constant = true;
|
---|
20 | this.referencePaths = [];
|
---|
21 | this.referenced = false;
|
---|
22 | this.references = 0;
|
---|
23 | this.identifier = identifier;
|
---|
24 | this.scope = scope;
|
---|
25 | this.path = path;
|
---|
26 | this.kind = kind;
|
---|
27 | if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path)) {
|
---|
28 | this.reassign(path);
|
---|
29 | }
|
---|
30 | this.clearValue();
|
---|
31 | }
|
---|
32 | deoptValue() {
|
---|
33 | this.clearValue();
|
---|
34 | this.hasDeoptedValue = true;
|
---|
35 | }
|
---|
36 | setValue(value) {
|
---|
37 | if (this.hasDeoptedValue) return;
|
---|
38 | this.hasValue = true;
|
---|
39 | this.value = value;
|
---|
40 | }
|
---|
41 | clearValue() {
|
---|
42 | this.hasDeoptedValue = false;
|
---|
43 | this.hasValue = false;
|
---|
44 | this.value = null;
|
---|
45 | }
|
---|
46 | reassign(path) {
|
---|
47 | this.constant = false;
|
---|
48 | if (this.constantViolations.includes(path)) {
|
---|
49 | return;
|
---|
50 | }
|
---|
51 | this.constantViolations.push(path);
|
---|
52 | }
|
---|
53 | reference(path) {
|
---|
54 | if (this.referencePaths.includes(path)) {
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | this.referenced = true;
|
---|
58 | this.references++;
|
---|
59 | this.referencePaths.push(path);
|
---|
60 | }
|
---|
61 | dereference() {
|
---|
62 | this.references--;
|
---|
63 | this.referenced = !!this.references;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | exports.default = Binding;
|
---|
67 | function isDeclaredInLoop(path) {
|
---|
68 | for (let {
|
---|
69 | parentPath,
|
---|
70 | key
|
---|
71 | } = path; parentPath; ({
|
---|
72 | parentPath,
|
---|
73 | key
|
---|
74 | } = parentPath)) {
|
---|
75 | if (parentPath.isFunctionParent()) return false;
|
---|
76 | if (parentPath.isWhile() || parentPath.isForXStatement() || parentPath.isForStatement() && key === "body") {
|
---|
77 | return true;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | //# sourceMappingURL=binding.js.map
|
---|
Note:
See
TracBrowser
for help on using the repository browser.