@@ -10797,80 +10797,6 @@ function escapeStringRegexp(string) {
10797
10797
.replace(/-/g, '\\x2d');
10798
10798
}
10799
10799
10800
- function color$1(d) {
10801
- return '\u001B[33m' + d + '\u001B[39m'
10802
- }
10803
-
10804
- const CONTINUE = true;
10805
- const SKIP = 'skip';
10806
- const EXIT = false;
10807
- const visitParents =
10808
- (
10809
- function (tree, test, visitor, reverse) {
10810
- if (typeof test === 'function' && typeof visitor !== 'function') {
10811
- reverse = visitor;
10812
- visitor = test;
10813
- test = null;
10814
- }
10815
- var is = convert(test);
10816
- var step = reverse ? -1 : 1;
10817
- factory(tree, null, [])();
10818
- function factory(node, index, parents) {
10819
- var value = typeof node === 'object' && node !== null ? node : {};
10820
- var name;
10821
- if (typeof value.type === 'string') {
10822
- name =
10823
- typeof value.tagName === 'string'
10824
- ? value.tagName
10825
- : typeof value.name === 'string'
10826
- ? value.name
10827
- : undefined;
10828
- Object.defineProperty(visit, 'name', {
10829
- value:
10830
- 'node (' +
10831
- color$1(value.type + (name ? '<' + name + '>' : '')) +
10832
- ')'
10833
- });
10834
- }
10835
- return visit
10836
- function visit() {
10837
- var result = [];
10838
- var subresult;
10839
- var offset;
10840
- var grandparents;
10841
- if (!test || is(node, index, parents[parents.length - 1] || null)) {
10842
- result = toResult(visitor(node, parents));
10843
- if (result[0] === EXIT) {
10844
- return result
10845
- }
10846
- }
10847
- if (node.children && result[0] !== SKIP) {
10848
- offset = (reverse ? node.children.length : -1) + step;
10849
- grandparents = parents.concat(node);
10850
- while (offset > -1 && offset < node.children.length) {
10851
- subresult = factory(node.children[offset], offset, grandparents)();
10852
- if (subresult[0] === EXIT) {
10853
- return subresult
10854
- }
10855
- offset =
10856
- typeof subresult[1] === 'number' ? subresult[1] : offset + step;
10857
- }
10858
- }
10859
- return result
10860
- }
10861
- }
10862
- }
10863
- );
10864
- function toResult(value) {
10865
- if (Array.isArray(value)) {
10866
- return value
10867
- }
10868
- if (typeof value === 'number') {
10869
- return [CONTINUE, value]
10870
- }
10871
- return [value]
10872
- }
10873
-
10874
10800
const own$3 = {}.hasOwnProperty;
10875
10801
const findAndReplace =
10876
10802
(
@@ -10891,7 +10817,7 @@ const findAndReplace =
10891
10817
const pairs = toPairs(schema);
10892
10818
let pairIndex = -1;
10893
10819
while (++pairIndex < pairs.length) {
10894
- visitParents(tree, 'text', visitor);
10820
+ visitParents$1 (tree, 'text', visitor);
10895
10821
}
10896
10822
return tree
10897
10823
function visitor(node, parents) {
@@ -10911,28 +10837,33 @@ const findAndReplace =
10911
10837
grandparent = parent;
10912
10838
}
10913
10839
if (grandparent) {
10914
- return handler(node, grandparent )
10840
+ return handler(node, parents )
10915
10841
}
10916
10842
}
10917
- function handler(node, parent) {
10843
+ function handler(node, parents) {
10844
+ const parent = parents[parents.length - 1];
10918
10845
const find = pairs[pairIndex][0];
10919
10846
const replace = pairs[pairIndex][1];
10920
10847
let start = 0;
10921
- let index = parent.children.indexOf(node);
10848
+ const index = parent.children.indexOf(node);
10922
10849
let nodes = [];
10923
10850
let position;
10924
10851
find.lastIndex = 0;
10925
10852
let match = find.exec(node.value);
10926
10853
while (match) {
10927
10854
position = match.index;
10928
- let value = replace(...match, {
10855
+ const matchObject = {
10929
10856
index: match.index,
10930
- input: match.input
10931
- });
10857
+ input: match.input,
10858
+ stack: [...parents, node]
10859
+ };
10860
+ let value = replace(...match, matchObject);
10932
10861
if (typeof value === 'string') {
10933
10862
value = value.length > 0 ? {type: 'text', value} : undefined;
10934
10863
}
10935
- if (value !== false) {
10864
+ if (value === false) {
10865
+ position = undefined;
10866
+ } else {
10936
10867
if (start !== position) {
10937
10868
nodes.push({
10938
10869
type: 'text',
@@ -10953,14 +10884,13 @@ const findAndReplace =
10953
10884
}
10954
10885
if (position === undefined) {
10955
10886
nodes = [node];
10956
- index--;
10957
10887
} else {
10958
10888
if (start < node.value.length) {
10959
10889
nodes.push({type: 'text', value: node.value.slice(start)});
10960
10890
}
10961
10891
parent.children.splice(index, 1, ...nodes);
10962
10892
}
10963
- return index + nodes.length + 1
10893
+ return index + nodes.length
10964
10894
}
10965
10895
}
10966
10896
);
@@ -11747,6 +11677,80 @@ function location(file) {
11747
11677
}
11748
11678
}
11749
11679
11680
+ function color$1(d) {
11681
+ return '\u001B[33m' + d + '\u001B[39m'
11682
+ }
11683
+
11684
+ const CONTINUE = true;
11685
+ const SKIP = 'skip';
11686
+ const EXIT = false;
11687
+ const visitParents =
11688
+ (
11689
+ function (tree, test, visitor, reverse) {
11690
+ if (typeof test === 'function' && typeof visitor !== 'function') {
11691
+ reverse = visitor;
11692
+ visitor = test;
11693
+ test = null;
11694
+ }
11695
+ var is = convert(test);
11696
+ var step = reverse ? -1 : 1;
11697
+ factory(tree, null, [])();
11698
+ function factory(node, index, parents) {
11699
+ var value = typeof node === 'object' && node !== null ? node : {};
11700
+ var name;
11701
+ if (typeof value.type === 'string') {
11702
+ name =
11703
+ typeof value.tagName === 'string'
11704
+ ? value.tagName
11705
+ : typeof value.name === 'string'
11706
+ ? value.name
11707
+ : undefined;
11708
+ Object.defineProperty(visit, 'name', {
11709
+ value:
11710
+ 'node (' +
11711
+ color$1(value.type + (name ? '<' + name + '>' : '')) +
11712
+ ')'
11713
+ });
11714
+ }
11715
+ return visit
11716
+ function visit() {
11717
+ var result = [];
11718
+ var subresult;
11719
+ var offset;
11720
+ var grandparents;
11721
+ if (!test || is(node, index, parents[parents.length - 1] || null)) {
11722
+ result = toResult(visitor(node, parents));
11723
+ if (result[0] === EXIT) {
11724
+ return result
11725
+ }
11726
+ }
11727
+ if (node.children && result[0] !== SKIP) {
11728
+ offset = (reverse ? node.children.length : -1) + step;
11729
+ grandparents = parents.concat(node);
11730
+ while (offset > -1 && offset < node.children.length) {
11731
+ subresult = factory(node.children[offset], offset, grandparents)();
11732
+ if (subresult[0] === EXIT) {
11733
+ return subresult
11734
+ }
11735
+ offset =
11736
+ typeof subresult[1] === 'number' ? subresult[1] : offset + step;
11737
+ }
11738
+ }
11739
+ return result
11740
+ }
11741
+ }
11742
+ }
11743
+ );
11744
+ function toResult(value) {
11745
+ if (Array.isArray(value)) {
11746
+ return value
11747
+ }
11748
+ if (typeof value === 'number') {
11749
+ return [CONTINUE, value]
11750
+ }
11751
+ return [value]
11752
+ }
11753
+
11750
11754
const visit =
11751
11755
(
11752
11756
function (tree, test, visitor, reverse) {
0 commit comments