@@ -772,24 +772,41 @@ function isCoveredAnyNode(
772
772
return false
773
773
}
774
774
775
+ /* eslint-disable complexity -- X( */
775
776
/** Check whether the right nodes is covered by the left nodes. */
776
777
function isCoveredAltNodes (
778
+ /* eslint-enable complexity -- X( */
777
779
left : NormalizedNode [ ] ,
778
780
right : NormalizedNode [ ] ,
779
781
options : Options ,
780
782
) {
781
- // if (options.canOmitRight) {
782
- // return isCoveredAltNodesForCanOmitRight(left, right, options)
783
- // }
783
+ let rightLength = right . length
784
+ if ( options . canOmitRight ) {
785
+ while ( right [ rightLength - 1 ] ) {
786
+ const re = right [ rightLength - 1 ]
787
+ if ( re . type === "NormalizedOptional" ) {
788
+ rightLength --
789
+ } else {
790
+ break
791
+ }
792
+ }
793
+ }
784
794
let leftIndex = 0
785
795
let rightIndex = 0
786
- while ( leftIndex < left . length && rightIndex < right . length ) {
796
+ while ( leftIndex < left . length && rightIndex < rightLength ) {
787
797
const le = left [ leftIndex ]
788
798
const re = right [ rightIndex ]
789
799
790
800
if ( re . type === "NormalizedOptional" ) {
791
- rightIndex ++
792
- continue
801
+ let leftElement
802
+ if ( le . type === "NormalizedOptional" ) {
803
+ leftElement = le . element
804
+ } else {
805
+ leftElement = le
806
+ }
807
+ if ( ! isCoveredForNormalizedNode ( leftElement , re . element , options ) ) {
808
+ return false
809
+ }
793
810
} else if ( le . type === "NormalizedOptional" ) {
794
811
// Checks if skipped.
795
812
const skippedLeftItems = left . slice ( leftIndex + 1 )
@@ -838,62 +855,3 @@ function isCoveredAltNodes(
838
855
}
839
856
return leftIndex >= left . length
840
857
}
841
-
842
- /** Check whether the right nodes is covered by the left nodes. */
843
- // function isCoveredAltNodesForCanOmitRight(
844
- // left: NormalizedNode[],
845
- // right: NormalizedNode[],
846
- // options: Options,
847
- // ) {
848
- // let leftIndex = 0
849
- // let rightIndex = 0
850
- // while (leftIndex < left.length && rightIndex < right.length) {
851
- // const le = left[leftIndex]
852
- // const re = right[rightIndex]
853
-
854
- // if (re.type === "NormalizedOptional") {
855
- // rightIndex++
856
- // continue
857
- // } else if (le.type === "NormalizedOptional") {
858
- // // Checks if skipped.
859
- // const skippedLeftItems = left.slice(leftIndex + 1)
860
- // if (
861
- // isCoveredAltNodes(
862
- // skippedLeftItems,
863
- // right.slice(rightIndex),
864
- // options,
865
- // )
866
- // ) {
867
- // return true
868
- // }
869
- // if (!isCoveredForNormalizedNode(le.element, re, options)) {
870
- // // I know it won't match if I skip it.
871
- // return false
872
- // }
873
- // if (le.max >= 2) {
874
- // // Check for multiple iterations.
875
- // if (
876
- // isCoveredAltNodes(
877
- // [le.decrementMax(), ...skippedLeftItems],
878
- // right.slice(rightIndex + 1),
879
- // options,
880
- // )
881
- // ) {
882
- // return true
883
- // }
884
- // }
885
- // } else if (!isCoveredForNormalizedNode(le, re, options)) {
886
- // return false
887
- // }
888
- // leftIndex++
889
- // rightIndex++
890
- // }
891
- // while (leftIndex < left.length) {
892
- // const le = left[leftIndex]
893
- // if (le.type !== "NormalizedOptional") {
894
- // return false
895
- // }
896
- // leftIndex++
897
- // }
898
- // return leftIndex >= left.length
899
- // }
0 commit comments