clarity-pattern-parser 11.0.3 → 11.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2717,9 +2717,9 @@
2717
2717
  this._binaryPlaceholder = Node.createNode("placeholder", "binary-placeholder");
2718
2718
  this._atomNode = null;
2719
2719
  this._binaryNode = null;
2720
- this._orphanedAtom = null;
2721
2720
  this._precedenceMap = precedenceMap;
2722
2721
  this._associationMap = associationMap;
2722
+ this._revertBinary = () => { };
2723
2723
  }
2724
2724
  addPrefix(name, ...prefix) {
2725
2725
  const lastPrefixNode = this._prefixNode;
@@ -2754,15 +2754,22 @@
2754
2754
  throw new Error("Cannot add a binary without an atom node.");
2755
2755
  }
2756
2756
  this._binaryPlaceholder.remove();
2757
- this._orphanedAtom = lastAtomNode;
2758
2757
  if (lastBinaryNode == null) {
2759
2758
  const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
2760
2759
  this._binaryNode = node;
2760
+ this._revertBinary = () => {
2761
+ lastAtomNode.remove();
2762
+ this._binaryNode = lastAtomNode;
2763
+ };
2761
2764
  return;
2762
2765
  }
2763
2766
  if (precedence === lastPrecendece && association === Association.right) {
2764
2767
  const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
2765
2768
  lastBinaryNode.appendChild(node);
2769
+ this._revertBinary = () => {
2770
+ node.replaceWith(lastAtomNode);
2771
+ this._binaryNode = lastBinaryNode;
2772
+ };
2766
2773
  this._binaryNode = node;
2767
2774
  }
2768
2775
  else if (precedence === lastPrecendece) {
@@ -2770,6 +2777,11 @@
2770
2777
  lastBinaryNode.replaceWith(node);
2771
2778
  lastBinaryNode.appendChild(lastAtomNode);
2772
2779
  node.append(lastBinaryNode, ...delimiterNode, this._binaryPlaceholder);
2780
+ this._revertBinary = () => {
2781
+ lastBinaryNode.remove();
2782
+ node.replaceWith(lastBinaryNode);
2783
+ this._binaryNode = lastBinaryNode;
2784
+ };
2773
2785
  this._binaryNode = node;
2774
2786
  }
2775
2787
  else if (precedence > lastPrecendece) {
@@ -2787,11 +2799,21 @@
2787
2799
  const node = Node.createNode("expression", name, []);
2788
2800
  root.replaceWith(node);
2789
2801
  node.append(root, ...delimiterNode, this._binaryPlaceholder);
2802
+ this._revertBinary = () => {
2803
+ root.remove();
2804
+ node.replaceWith(root);
2805
+ this._binaryNode = root;
2806
+ };
2790
2807
  this._binaryNode = node;
2791
2808
  }
2792
2809
  else {
2793
2810
  const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
2794
2811
  lastBinaryNode.appendChild(node);
2812
+ this._revertBinary = () => {
2813
+ lastAtomNode.remove();
2814
+ node.replaceWith(lastAtomNode);
2815
+ this._binaryNode = lastBinaryNode;
2816
+ };
2795
2817
  this._binaryNode = node;
2796
2818
  }
2797
2819
  }
@@ -2832,14 +2854,13 @@
2832
2854
  return this._atomNode != null;
2833
2855
  }
2834
2856
  commit() {
2835
- var _a;
2836
2857
  if (this._binaryNode == null) {
2837
2858
  return this._compileAtomNode();
2838
2859
  }
2839
2860
  const atomNode = this._compileAtomNode();
2840
2861
  if (atomNode == null) {
2841
- let root = this._binaryPlaceholder.findRoot();
2842
- (_a = this._binaryPlaceholder.parent) === null || _a === void 0 ? void 0 : _a.replaceWith(this._orphanedAtom);
2862
+ this._revertBinary();
2863
+ let root = this._binaryNode.findRoot();
2843
2864
  this.reset();
2844
2865
  return root;
2845
2866
  }
@@ -2853,7 +2874,6 @@
2853
2874
  reset() {
2854
2875
  this._prefixNode = null;
2855
2876
  this._atomNode = null;
2856
- this._orphanedAtom = null;
2857
2877
  this._postfixNode = null;
2858
2878
  this._binaryNode = null;
2859
2879
  }