binding.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. exports.__esModule = true;
  3. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  4. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. var Binding = function () {
  7. function Binding(_ref) {
  8. var existing = _ref.existing,
  9. identifier = _ref.identifier,
  10. scope = _ref.scope,
  11. path = _ref.path,
  12. kind = _ref.kind;
  13. (0, _classCallCheck3.default)(this, Binding);
  14. this.identifier = identifier;
  15. this.scope = scope;
  16. this.path = path;
  17. this.kind = kind;
  18. this.constantViolations = [];
  19. this.constant = true;
  20. this.referencePaths = [];
  21. this.referenced = false;
  22. this.references = 0;
  23. this.clearValue();
  24. if (existing) {
  25. this.constantViolations = [].concat(existing.path, existing.constantViolations, this.constantViolations);
  26. }
  27. }
  28. Binding.prototype.deoptValue = function deoptValue() {
  29. this.clearValue();
  30. this.hasDeoptedValue = true;
  31. };
  32. Binding.prototype.setValue = function setValue(value) {
  33. if (this.hasDeoptedValue) return;
  34. this.hasValue = true;
  35. this.value = value;
  36. };
  37. Binding.prototype.clearValue = function clearValue() {
  38. this.hasDeoptedValue = false;
  39. this.hasValue = false;
  40. this.value = null;
  41. };
  42. Binding.prototype.reassign = function reassign(path) {
  43. this.constant = false;
  44. if (this.constantViolations.indexOf(path) !== -1) {
  45. return;
  46. }
  47. this.constantViolations.push(path);
  48. };
  49. Binding.prototype.reference = function reference(path) {
  50. if (this.referencePaths.indexOf(path) !== -1) {
  51. return;
  52. }
  53. this.referenced = true;
  54. this.references++;
  55. this.referencePaths.push(path);
  56. };
  57. Binding.prototype.dereference = function dereference() {
  58. this.references--;
  59. this.referenced = !!this.references;
  60. };
  61. return Binding;
  62. }();
  63. exports.default = Binding;
  64. module.exports = exports["default"];