@borgar/fx 5.0.1 → 5.0.2

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.cjs CHANGED
@@ -84,6 +84,7 @@ var REF_BEAM = "range_beam";
84
84
  var REF_TERNARY = "range_ternary";
85
85
  var REF_NAMED = "range_named";
86
86
  var REF_STRUCT = "structured";
87
+ var REF_CELL = "cell";
87
88
  var FX_PREFIX = "fx_prefix";
88
89
  var UNKNOWN = "unknown";
89
90
  var UNARY = "UnaryExpression";
@@ -103,24 +104,26 @@ var MAX_ROWS = 2 ** 20 - 1;
103
104
  // lib/mergeRefTokens.ts
104
105
  var END = "$";
105
106
  var validRunsMerge = [
106
- [REF_RANGE, ":", REF_RANGE],
107
- [REF_RANGE, ".:", REF_RANGE],
108
- [REF_RANGE, ":.", REF_RANGE],
109
- [REF_RANGE, ".:.", REF_RANGE],
107
+ [REF_CELL, ":", REF_CELL],
108
+ [REF_CELL, ".:", REF_CELL],
109
+ [REF_CELL, ":.", REF_CELL],
110
+ [REF_CELL, ".:.", REF_CELL],
110
111
  [REF_RANGE],
111
112
  [REF_BEAM],
112
113
  [REF_TERNARY],
113
- [CONTEXT, "!", REF_RANGE, ":", REF_RANGE],
114
- [CONTEXT, "!", REF_RANGE, ".:", REF_RANGE],
115
- [CONTEXT, "!", REF_RANGE, ":.", REF_RANGE],
116
- [CONTEXT, "!", REF_RANGE, ".:.", REF_RANGE],
114
+ [CONTEXT, "!", REF_CELL, ":", REF_CELL],
115
+ [CONTEXT, "!", REF_CELL, ".:", REF_CELL],
116
+ [CONTEXT, "!", REF_CELL, ":.", REF_CELL],
117
+ [CONTEXT, "!", REF_CELL, ".:.", REF_CELL],
118
+ [CONTEXT, "!", REF_CELL],
117
119
  [CONTEXT, "!", REF_RANGE],
118
120
  [CONTEXT, "!", REF_BEAM],
119
121
  [CONTEXT, "!", REF_TERNARY],
120
- [CONTEXT_QUOTE, "!", REF_RANGE, ":", REF_RANGE],
121
- [CONTEXT_QUOTE, "!", REF_RANGE, ".:", REF_RANGE],
122
- [CONTEXT_QUOTE, "!", REF_RANGE, ":.", REF_RANGE],
123
- [CONTEXT_QUOTE, "!", REF_RANGE, ".:.", REF_RANGE],
122
+ [CONTEXT_QUOTE, "!", REF_CELL, ":", REF_CELL],
123
+ [CONTEXT_QUOTE, "!", REF_CELL, ".:", REF_CELL],
124
+ [CONTEXT_QUOTE, "!", REF_CELL, ":.", REF_CELL],
125
+ [CONTEXT_QUOTE, "!", REF_CELL, ".:.", REF_CELL],
126
+ [CONTEXT_QUOTE, "!", REF_CELL],
124
127
  [CONTEXT_QUOTE, "!", REF_RANGE],
125
128
  [CONTEXT_QUOTE, "!", REF_BEAM],
126
129
  [CONTEXT_QUOTE, "!", REF_TERNARY],
@@ -152,7 +155,11 @@ var matcher = (tokens2, currNode, anchorIndex, index = 0) => {
152
155
  while (i <= max) {
153
156
  const token = tokens2[anchorIndex - i];
154
157
  if (token) {
155
- const key = token.type === OPERATOR ? token.value : token.type;
158
+ const value = token.value;
159
+ let key = token.type === OPERATOR ? value : token.type;
160
+ if (key === REF_RANGE && !value.includes(":")) {
161
+ key = REF_CELL;
162
+ }
156
163
  if (key in node) {
157
164
  node = node[key];
158
165
  i += 1;
@@ -542,7 +549,7 @@ function lexRangeA1(str, pos, options) {
542
549
  }
543
550
  }
544
551
  }
545
- if (top && canEndRange(str, preOp)) {
552
+ if (top && canEndRange(str, preOp) && str.charCodeAt(preOp) !== 33) {
546
553
  return { type: REF_RANGE, value: str.slice(pos, preOp) };
547
554
  }
548
555
  } else {
@@ -582,6 +589,7 @@ var UC_C = 67;
582
589
  var LC_C = 99;
583
590
  var PLUS = 43;
584
591
  var MINUS = 45;
592
+ var EXCL2 = 33;
585
593
  function lexR1C1Part(str, pos, isRow = false) {
586
594
  const start = pos;
587
595
  const c0 = str.charCodeAt(pos);
@@ -636,7 +644,7 @@ function lexRangeR1C1(str, pos, options) {
636
644
  p += r1;
637
645
  const c1 = lexR1C1Part(str, p);
638
646
  p += c1;
639
- if (c1 || r1) {
647
+ if ((c1 || r1) && str.charCodeAt(p) !== EXCL2) {
640
648
  const op = advRangeOp(str, p);
641
649
  const preOp = p;
642
650
  if (op) {
@@ -853,7 +861,7 @@ function parseSRange(str, pos = 0) {
853
861
  }
854
862
 
855
863
  // lib/lexers/lexStructured.ts
856
- var EXCL2 = 33;
864
+ var EXCL3 = 33;
857
865
  function lexStructured(str, pos) {
858
866
  const structData = parseSRange(str, pos);
859
867
  if (structData && structData.length) {
@@ -861,7 +869,7 @@ function lexStructured(str, pos) {
861
869
  while (isWS(str.charCodeAt(pos + i))) {
862
870
  i++;
863
871
  }
864
- if (str.charCodeAt(pos + i) !== EXCL2) {
872
+ if (str.charCodeAt(pos + i) !== EXCL3) {
865
873
  return {
866
874
  type: REF_STRUCT,
867
875
  value: structData.token
@@ -956,9 +964,9 @@ function lexNamed(str, pos) {
956
964
  }
957
965
 
958
966
  // lib/lexers/lexRefOp.ts
959
- var EXCL3 = 33;
967
+ var EXCL4 = 33;
960
968
  function lexRefOp(str, pos, opts) {
961
- if (str.charCodeAt(pos) === EXCL3) {
969
+ if (str.charCodeAt(pos) === EXCL4) {
962
970
  return { type: OPERATOR, value: str[pos] };
963
971
  }
964
972
  if (!opts.r1c1) {
@@ -972,7 +980,7 @@ function lexRefOp(str, pos, opts) {
972
980
  // lib/lexers/lexNameFuncCntx.ts
973
981
  var BR_OPEN4 = 91;
974
982
  var PAREN_OPEN = 40;
975
- var EXCL4 = 33;
983
+ var EXCL5 = 33;
976
984
  var OFFS = 32;
977
985
  var ALLOWED = new Uint8Array(180 - OFFS);
978
986
  var OK_NAME_0 = 1;
@@ -1037,7 +1045,7 @@ function lexNameFuncCntx(str, pos, opts) {
1037
1045
  } else {
1038
1046
  if (c === PAREN_OPEN && func) {
1039
1047
  return { type: FUNCTION, value: str.slice(start, pos) };
1040
- } else if (c === EXCL4 && cntx) {
1048
+ } else if (c === EXCL5 && cntx) {
1041
1049
  return { type: CONTEXT, value: str.slice(start, pos) };
1042
1050
  }
1043
1051
  return nameOrUnknown(str, s, start, pos, name);
@@ -1820,6 +1828,24 @@ function parse(tokenlist, options = {}) {
1820
1828
 
1821
1829
  // lib/stringifyPrefix.ts
1822
1830
  var reBannedChars = /[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;
1831
+ var reIsRangelike = /^(R|C|RC|[A-Z]{1,3}\d{1,7})$/i;
1832
+ function needQuotes(scope, yesItDoes = 0) {
1833
+ if (yesItDoes) {
1834
+ return 1;
1835
+ }
1836
+ if (scope) {
1837
+ if (reBannedChars.test(scope)) {
1838
+ return 1;
1839
+ }
1840
+ if (reIsRangelike.test(scope)) {
1841
+ return 1;
1842
+ }
1843
+ }
1844
+ return 0;
1845
+ }
1846
+ function quotePrefix(prefix2) {
1847
+ return "'" + prefix2.replace(/'/g, "''") + "'";
1848
+ }
1823
1849
  function stringifyPrefix(ref) {
1824
1850
  let pre = "";
1825
1851
  let quote = 0;
@@ -1830,12 +1856,12 @@ function stringifyPrefix(ref) {
1830
1856
  if (scope) {
1831
1857
  const part = nth % 2 ? "[" + scope + "]" : scope;
1832
1858
  pre = part + pre;
1833
- quote += +reBannedChars.test(scope);
1859
+ quote += needQuotes(scope, quote);
1834
1860
  nth++;
1835
1861
  }
1836
1862
  }
1837
1863
  if (quote) {
1838
- pre = "'" + pre.replace(/'/g, "''") + "'";
1864
+ pre = quotePrefix(pre);
1839
1865
  }
1840
1866
  return pre ? pre + "!" : pre;
1841
1867
  }
@@ -1845,14 +1871,14 @@ function stringifyPrefixXlsx(ref) {
1845
1871
  const { workbookName, sheetName } = ref;
1846
1872
  if (workbookName) {
1847
1873
  pre += "[" + workbookName + "]";
1848
- quote += +reBannedChars.test(workbookName);
1874
+ quote += needQuotes(workbookName);
1849
1875
  }
1850
1876
  if (sheetName) {
1851
1877
  pre += sheetName;
1852
- quote += +reBannedChars.test(sheetName);
1878
+ quote += needQuotes(sheetName);
1853
1879
  }
1854
1880
  if (quote) {
1855
- pre = "'" + pre.replace(/'/g, "''") + "'";
1881
+ pre = quotePrefix(pre);
1856
1882
  }
1857
1883
  return pre ? pre + "!" : pre;
1858
1884
  }