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.
package/dist/index.js CHANGED
@@ -2715,9 +2715,9 @@ class PrecedenceTree {
2715
2715
  this._binaryPlaceholder = Node.createNode("placeholder", "binary-placeholder");
2716
2716
  this._atomNode = null;
2717
2717
  this._binaryNode = null;
2718
- this._orphanedAtom = null;
2719
2718
  this._precedenceMap = precedenceMap;
2720
2719
  this._associationMap = associationMap;
2720
+ this._revertBinary = () => { };
2721
2721
  }
2722
2722
  addPrefix(name, ...prefix) {
2723
2723
  const lastPrefixNode = this._prefixNode;
@@ -2752,15 +2752,22 @@ class PrecedenceTree {
2752
2752
  throw new Error("Cannot add a binary without an atom node.");
2753
2753
  }
2754
2754
  this._binaryPlaceholder.remove();
2755
- this._orphanedAtom = lastAtomNode;
2756
2755
  if (lastBinaryNode == null) {
2757
2756
  const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
2758
2757
  this._binaryNode = node;
2758
+ this._revertBinary = () => {
2759
+ lastAtomNode.remove();
2760
+ this._binaryNode = lastAtomNode;
2761
+ };
2759
2762
  return;
2760
2763
  }
2761
2764
  if (precedence === lastPrecendece && association === Association.right) {
2762
2765
  const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
2763
2766
  lastBinaryNode.appendChild(node);
2767
+ this._revertBinary = () => {
2768
+ node.replaceWith(lastAtomNode);
2769
+ this._binaryNode = lastBinaryNode;
2770
+ };
2764
2771
  this._binaryNode = node;
2765
2772
  }
2766
2773
  else if (precedence === lastPrecendece) {
@@ -2768,6 +2775,11 @@ class PrecedenceTree {
2768
2775
  lastBinaryNode.replaceWith(node);
2769
2776
  lastBinaryNode.appendChild(lastAtomNode);
2770
2777
  node.append(lastBinaryNode, ...delimiterNode, this._binaryPlaceholder);
2778
+ this._revertBinary = () => {
2779
+ lastBinaryNode.remove();
2780
+ node.replaceWith(lastBinaryNode);
2781
+ this._binaryNode = lastBinaryNode;
2782
+ };
2771
2783
  this._binaryNode = node;
2772
2784
  }
2773
2785
  else if (precedence > lastPrecendece) {
@@ -2785,11 +2797,21 @@ class PrecedenceTree {
2785
2797
  const node = Node.createNode("expression", name, []);
2786
2798
  root.replaceWith(node);
2787
2799
  node.append(root, ...delimiterNode, this._binaryPlaceholder);
2800
+ this._revertBinary = () => {
2801
+ root.remove();
2802
+ node.replaceWith(root);
2803
+ this._binaryNode = root;
2804
+ };
2788
2805
  this._binaryNode = node;
2789
2806
  }
2790
2807
  else {
2791
2808
  const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
2792
2809
  lastBinaryNode.appendChild(node);
2810
+ this._revertBinary = () => {
2811
+ lastAtomNode.remove();
2812
+ node.replaceWith(lastAtomNode);
2813
+ this._binaryNode = lastBinaryNode;
2814
+ };
2793
2815
  this._binaryNode = node;
2794
2816
  }
2795
2817
  }
@@ -2830,14 +2852,13 @@ class PrecedenceTree {
2830
2852
  return this._atomNode != null;
2831
2853
  }
2832
2854
  commit() {
2833
- var _a;
2834
2855
  if (this._binaryNode == null) {
2835
2856
  return this._compileAtomNode();
2836
2857
  }
2837
2858
  const atomNode = this._compileAtomNode();
2838
2859
  if (atomNode == null) {
2839
- let root = this._binaryPlaceholder.findRoot();
2840
- (_a = this._binaryPlaceholder.parent) === null || _a === void 0 ? void 0 : _a.replaceWith(this._orphanedAtom);
2860
+ this._revertBinary();
2861
+ let root = this._binaryNode.findRoot();
2841
2862
  this.reset();
2842
2863
  return root;
2843
2864
  }
@@ -2851,7 +2872,6 @@ class PrecedenceTree {
2851
2872
  reset() {
2852
2873
  this._prefixNode = null;
2853
2874
  this._atomNode = null;
2854
- this._orphanedAtom = null;
2855
2875
  this._postfixNode = null;
2856
2876
  this._binaryNode = null;
2857
2877
  }