@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.js CHANGED
@@ -15,6 +15,7 @@ var REF_BEAM = "range_beam";
15
15
  var REF_TERNARY = "range_ternary";
16
16
  var REF_NAMED = "range_named";
17
17
  var REF_STRUCT = "structured";
18
+ var REF_CELL = "cell";
18
19
  var FX_PREFIX = "fx_prefix";
19
20
  var UNKNOWN = "unknown";
20
21
  var UNARY = "UnaryExpression";
@@ -34,24 +35,26 @@ var MAX_ROWS = 2 ** 20 - 1;
34
35
  // lib/mergeRefTokens.ts
35
36
  var END = "$";
36
37
  var validRunsMerge = [
37
- [REF_RANGE, ":", REF_RANGE],
38
- [REF_RANGE, ".:", REF_RANGE],
39
- [REF_RANGE, ":.", REF_RANGE],
40
- [REF_RANGE, ".:.", REF_RANGE],
38
+ [REF_CELL, ":", REF_CELL],
39
+ [REF_CELL, ".:", REF_CELL],
40
+ [REF_CELL, ":.", REF_CELL],
41
+ [REF_CELL, ".:.", REF_CELL],
41
42
  [REF_RANGE],
42
43
  [REF_BEAM],
43
44
  [REF_TERNARY],
44
- [CONTEXT, "!", REF_RANGE, ":", REF_RANGE],
45
- [CONTEXT, "!", REF_RANGE, ".:", REF_RANGE],
46
- [CONTEXT, "!", REF_RANGE, ":.", REF_RANGE],
47
- [CONTEXT, "!", REF_RANGE, ".:.", REF_RANGE],
45
+ [CONTEXT, "!", REF_CELL, ":", REF_CELL],
46
+ [CONTEXT, "!", REF_CELL, ".:", REF_CELL],
47
+ [CONTEXT, "!", REF_CELL, ":.", REF_CELL],
48
+ [CONTEXT, "!", REF_CELL, ".:.", REF_CELL],
49
+ [CONTEXT, "!", REF_CELL],
48
50
  [CONTEXT, "!", REF_RANGE],
49
51
  [CONTEXT, "!", REF_BEAM],
50
52
  [CONTEXT, "!", REF_TERNARY],
51
- [CONTEXT_QUOTE, "!", REF_RANGE, ":", REF_RANGE],
52
- [CONTEXT_QUOTE, "!", REF_RANGE, ".:", REF_RANGE],
53
- [CONTEXT_QUOTE, "!", REF_RANGE, ":.", REF_RANGE],
54
- [CONTEXT_QUOTE, "!", REF_RANGE, ".:.", REF_RANGE],
53
+ [CONTEXT_QUOTE, "!", REF_CELL, ":", REF_CELL],
54
+ [CONTEXT_QUOTE, "!", REF_CELL, ".:", REF_CELL],
55
+ [CONTEXT_QUOTE, "!", REF_CELL, ":.", REF_CELL],
56
+ [CONTEXT_QUOTE, "!", REF_CELL, ".:.", REF_CELL],
57
+ [CONTEXT_QUOTE, "!", REF_CELL],
55
58
  [CONTEXT_QUOTE, "!", REF_RANGE],
56
59
  [CONTEXT_QUOTE, "!", REF_BEAM],
57
60
  [CONTEXT_QUOTE, "!", REF_TERNARY],
@@ -83,7 +86,11 @@ var matcher = (tokens2, currNode, anchorIndex, index = 0) => {
83
86
  while (i <= max) {
84
87
  const token = tokens2[anchorIndex - i];
85
88
  if (token) {
86
- const key = token.type === OPERATOR ? token.value : token.type;
89
+ const value = token.value;
90
+ let key = token.type === OPERATOR ? value : token.type;
91
+ if (key === REF_RANGE && !value.includes(":")) {
92
+ key = REF_CELL;
93
+ }
87
94
  if (key in node) {
88
95
  node = node[key];
89
96
  i += 1;
@@ -473,7 +480,7 @@ function lexRangeA1(str, pos, options) {
473
480
  }
474
481
  }
475
482
  }
476
- if (top && canEndRange(str, preOp)) {
483
+ if (top && canEndRange(str, preOp) && str.charCodeAt(preOp) !== 33) {
477
484
  return { type: REF_RANGE, value: str.slice(pos, preOp) };
478
485
  }
479
486
  } else {
@@ -513,6 +520,7 @@ var UC_C = 67;
513
520
  var LC_C = 99;
514
521
  var PLUS = 43;
515
522
  var MINUS = 45;
523
+ var EXCL2 = 33;
516
524
  function lexR1C1Part(str, pos, isRow = false) {
517
525
  const start = pos;
518
526
  const c0 = str.charCodeAt(pos);
@@ -567,7 +575,7 @@ function lexRangeR1C1(str, pos, options) {
567
575
  p += r1;
568
576
  const c1 = lexR1C1Part(str, p);
569
577
  p += c1;
570
- if (c1 || r1) {
578
+ if ((c1 || r1) && str.charCodeAt(p) !== EXCL2) {
571
579
  const op = advRangeOp(str, p);
572
580
  const preOp = p;
573
581
  if (op) {
@@ -784,7 +792,7 @@ function parseSRange(str, pos = 0) {
784
792
  }
785
793
 
786
794
  // lib/lexers/lexStructured.ts
787
- var EXCL2 = 33;
795
+ var EXCL3 = 33;
788
796
  function lexStructured(str, pos) {
789
797
  const structData = parseSRange(str, pos);
790
798
  if (structData && structData.length) {
@@ -792,7 +800,7 @@ function lexStructured(str, pos) {
792
800
  while (isWS(str.charCodeAt(pos + i))) {
793
801
  i++;
794
802
  }
795
- if (str.charCodeAt(pos + i) !== EXCL2) {
803
+ if (str.charCodeAt(pos + i) !== EXCL3) {
796
804
  return {
797
805
  type: REF_STRUCT,
798
806
  value: structData.token
@@ -887,9 +895,9 @@ function lexNamed(str, pos) {
887
895
  }
888
896
 
889
897
  // lib/lexers/lexRefOp.ts
890
- var EXCL3 = 33;
898
+ var EXCL4 = 33;
891
899
  function lexRefOp(str, pos, opts) {
892
- if (str.charCodeAt(pos) === EXCL3) {
900
+ if (str.charCodeAt(pos) === EXCL4) {
893
901
  return { type: OPERATOR, value: str[pos] };
894
902
  }
895
903
  if (!opts.r1c1) {
@@ -903,7 +911,7 @@ function lexRefOp(str, pos, opts) {
903
911
  // lib/lexers/lexNameFuncCntx.ts
904
912
  var BR_OPEN4 = 91;
905
913
  var PAREN_OPEN = 40;
906
- var EXCL4 = 33;
914
+ var EXCL5 = 33;
907
915
  var OFFS = 32;
908
916
  var ALLOWED = new Uint8Array(180 - OFFS);
909
917
  var OK_NAME_0 = 1;
@@ -968,7 +976,7 @@ function lexNameFuncCntx(str, pos, opts) {
968
976
  } else {
969
977
  if (c === PAREN_OPEN && func) {
970
978
  return { type: FUNCTION, value: str.slice(start, pos) };
971
- } else if (c === EXCL4 && cntx) {
979
+ } else if (c === EXCL5 && cntx) {
972
980
  return { type: CONTEXT, value: str.slice(start, pos) };
973
981
  }
974
982
  return nameOrUnknown(str, s, start, pos, name);
@@ -1751,6 +1759,24 @@ function parse(tokenlist, options = {}) {
1751
1759
 
1752
1760
  // lib/stringifyPrefix.ts
1753
1761
  var reBannedChars = /[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;
1762
+ var reIsRangelike = /^(R|C|RC|[A-Z]{1,3}\d{1,7})$/i;
1763
+ function needQuotes(scope, yesItDoes = 0) {
1764
+ if (yesItDoes) {
1765
+ return 1;
1766
+ }
1767
+ if (scope) {
1768
+ if (reBannedChars.test(scope)) {
1769
+ return 1;
1770
+ }
1771
+ if (reIsRangelike.test(scope)) {
1772
+ return 1;
1773
+ }
1774
+ }
1775
+ return 0;
1776
+ }
1777
+ function quotePrefix(prefix2) {
1778
+ return "'" + prefix2.replace(/'/g, "''") + "'";
1779
+ }
1754
1780
  function stringifyPrefix(ref) {
1755
1781
  let pre = "";
1756
1782
  let quote = 0;
@@ -1761,12 +1787,12 @@ function stringifyPrefix(ref) {
1761
1787
  if (scope) {
1762
1788
  const part = nth % 2 ? "[" + scope + "]" : scope;
1763
1789
  pre = part + pre;
1764
- quote += +reBannedChars.test(scope);
1790
+ quote += needQuotes(scope, quote);
1765
1791
  nth++;
1766
1792
  }
1767
1793
  }
1768
1794
  if (quote) {
1769
- pre = "'" + pre.replace(/'/g, "''") + "'";
1795
+ pre = quotePrefix(pre);
1770
1796
  }
1771
1797
  return pre ? pre + "!" : pre;
1772
1798
  }
@@ -1776,14 +1802,14 @@ function stringifyPrefixXlsx(ref) {
1776
1802
  const { workbookName, sheetName } = ref;
1777
1803
  if (workbookName) {
1778
1804
  pre += "[" + workbookName + "]";
1779
- quote += +reBannedChars.test(workbookName);
1805
+ quote += needQuotes(workbookName);
1780
1806
  }
1781
1807
  if (sheetName) {
1782
1808
  pre += sheetName;
1783
- quote += +reBannedChars.test(sheetName);
1809
+ quote += needQuotes(sheetName);
1784
1810
  }
1785
1811
  if (quote) {
1786
- pre = "'" + pre.replace(/'/g, "''") + "'";
1812
+ pre = quotePrefix(pre);
1787
1813
  }
1788
1814
  return pre ? pre + "!" : pre;
1789
1815
  }