binding.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. class Binding {
  7. constructor({
  8. identifier,
  9. scope,
  10. path,
  11. kind
  12. }) {
  13. this.constantViolations = void 0;
  14. this.constant = void 0;
  15. this.referencePaths = void 0;
  16. this.referenced = void 0;
  17. this.references = void 0;
  18. this.hasDeoptedValue = void 0;
  19. this.hasValue = void 0;
  20. this.value = void 0;
  21. this.identifier = identifier;
  22. this.scope = scope;
  23. this.path = path;
  24. this.kind = kind;
  25. this.constantViolations = [];
  26. this.constant = true;
  27. this.referencePaths = [];
  28. this.referenced = false;
  29. this.references = 0;
  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.indexOf(path) !== -1) {
  49. return;
  50. }
  51. this.constantViolations.push(path);
  52. }
  53. reference(path) {
  54. if (this.referencePaths.indexOf(path) !== -1) {
  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;