You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.2 KiB

4 years ago
  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.identifier = identifier;
  14. this.scope = scope;
  15. this.path = path;
  16. this.kind = kind;
  17. this.constantViolations = [];
  18. this.constant = true;
  19. this.referencePaths = [];
  20. this.referenced = false;
  21. this.references = 0;
  22. this.clearValue();
  23. }
  24. deoptValue() {
  25. this.clearValue();
  26. this.hasDeoptedValue = true;
  27. }
  28. setValue(value) {
  29. if (this.hasDeoptedValue) return;
  30. this.hasValue = true;
  31. this.value = value;
  32. }
  33. clearValue() {
  34. this.hasDeoptedValue = false;
  35. this.hasValue = false;
  36. this.value = null;
  37. }
  38. reassign(path) {
  39. this.constant = false;
  40. if (this.constantViolations.indexOf(path) !== -1) {
  41. return;
  42. }
  43. this.constantViolations.push(path);
  44. }
  45. reference(path) {
  46. if (this.referencePaths.indexOf(path) !== -1) {
  47. return;
  48. }
  49. this.referenced = true;
  50. this.references++;
  51. this.referencePaths.push(path);
  52. }
  53. dereference() {
  54. this.references--;
  55. this.referenced = !!this.references;
  56. }
  57. }
  58. exports.default = Binding;