@univerjs/engine-formula 0.10.14-nightly.202511070628 → 0.10.14-nightly.202511070939

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/lib/es/index.js CHANGED
@@ -971,31 +971,98 @@ class ga extends Ne {
971
971
  nodeMakerTest(e) {
972
972
  return this._nodeMaker(e);
973
973
  }
974
- treeBuilder(e, t = !0, r, n) {
974
+ treeBuilder(e, t = !0, r) {
975
+ var f;
975
976
  if (t === !0) {
976
- const h = hs.get(e), d = n == null ? void 0 : n(e);
977
+ const h = hs.get(e), d = r && ((f = this._simpleCheckDefinedName) == null ? void 0 : f.call(this, e, r));
977
978
  if (h && !d)
978
979
  return h;
979
980
  }
980
981
  this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Tt);
981
- const s = [];
982
- let o = this._nodeMaker(e, s);
983
- if (o === m.VALUE || s.length === 0)
984
- return o;
985
- let u = !1, c = "", l = [];
982
+ const n = [];
983
+ let s = this._nodeMaker(e, n);
984
+ if (s === m.VALUE || n.length === 0)
985
+ return s;
986
+ let o = !1, u = "", c = [];
986
987
  if (r) {
987
- const { hasDefinedName: h, sequenceString: d, definedNames: _ } = r(s);
988
- u = h, c = d, l = _;
988
+ const { hasDefinedName: h, sequenceString: d, definedNames: _ } = this._handleDefinedName(n, r);
989
+ o = h, u = d, c = _;
989
990
  }
990
- if (u && (this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Tt), o = this._nodeMaker(`=${c}`), o === m.VALUE))
991
- return o;
992
- const f = this._getTopNode(this._currentLexerNode);
993
- if (f && (this._currentLexerNode = f), t) {
991
+ if (o && (this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Tt), s = this._nodeMaker(`=${u}`), s === m.VALUE))
992
+ return s;
993
+ const l = this._getTopNode(this._currentLexerNode);
994
+ if (l && (this._currentLexerNode = l), t) {
994
995
  if (!this._suffixExpressionHandler(this._currentLexerNode))
995
996
  return m.VALUE;
996
997
  hs.set(e, this._currentLexerNode);
997
998
  }
998
- return u && this._currentLexerNode.setDefinedNames(l), this._currentLexerNode;
999
+ return o && this._currentLexerNode.setDefinedNames(c), this._currentLexerNode;
1000
+ }
1001
+ _handleDefinedName(e, t) {
1002
+ const { unitId: r, getValueByName: n } = t;
1003
+ if (r == null)
1004
+ return {
1005
+ sequenceString: "",
1006
+ hasDefinedName: !1,
1007
+ definedNames: []
1008
+ };
1009
+ const s = this.getSequenceNode(e);
1010
+ let o = "", u = !1;
1011
+ const c = [];
1012
+ for (let l = 0, f = s.length; l < f; l++) {
1013
+ const h = s[l];
1014
+ if (typeof h == "string") {
1015
+ o += h;
1016
+ continue;
1017
+ }
1018
+ const { nodeType: d, token: _ } = h;
1019
+ if (d === $e.REFERENCE || d === $e.FUNCTION) {
1020
+ const C = n(r, _);
1021
+ if (C) {
1022
+ const E = C.formulaOrRefString, b = this._handleNestedDefinedName(E, t);
1023
+ if (b == null || typeof b != "object")
1024
+ o += b || m.NAME, u = !0, c.push(_);
1025
+ else if (typeof b == "object") {
1026
+ const { sequenceString: R, definedNames: p } = b;
1027
+ o += R, p.forEach((N) => {
1028
+ c.push(N);
1029
+ }), u = !0;
1030
+ }
1031
+ } else this._checkDefinedNameDirty(_, t) ? (o += m.NAME, u = !0, c.push(_)) : o += _;
1032
+ } else
1033
+ o += _;
1034
+ }
1035
+ return {
1036
+ sequenceString: o,
1037
+ hasDefinedName: u,
1038
+ definedNames: c
1039
+ };
1040
+ }
1041
+ _handleNestedDefinedName(e, t) {
1042
+ const r = [], n = this._nodeMaker(e, r);
1043
+ return n === m.VALUE || r.length === 0 ? n : this._handleDefinedName(r, t);
1044
+ }
1045
+ _simpleCheckDefinedName(e, t) {
1046
+ const { getDirtyDefinedNameMap: r, unitId: n } = t, s = r(), o = n;
1047
+ if (o != null && s[o] != null) {
1048
+ const u = Object.keys(s[o]);
1049
+ for (let c = 0, l = u.length; c < l; c++) {
1050
+ const f = u[c];
1051
+ if (e.indexOf(f) > -1)
1052
+ return !0;
1053
+ }
1054
+ }
1055
+ return !1;
1056
+ }
1057
+ _checkDefinedNameDirty(e, t) {
1058
+ const { getDirtyDefinedNameMap: r, unitId: n } = t, s = r(), o = n;
1059
+ if (o != null && s[o] != null) {
1060
+ const u = Object.keys(s[o]);
1061
+ for (let c = 0, l = u.length; c < l; c++)
1062
+ if (u[c] === e)
1063
+ return !0;
1064
+ }
1065
+ return !1;
999
1066
  }
1000
1067
  // eslint-disable-next-line complexity
1001
1068
  _suffixExpressionHandler(e) {
@@ -2664,62 +2731,11 @@ let Ar = class extends Ne {
2664
2731
  super(), this._definedNamesService = i, this._lexerTreeBuilder = a, this._formulaCurrentConfigService = e;
2665
2732
  }
2666
2733
  treeBuilder(i, a = !0) {
2667
- return this._lexerTreeBuilder.treeBuilder(i, a, this._injectDefinedName.bind(this), this._simpleCheckDefinedName.bind(this));
2668
- }
2669
- _simpleCheckDefinedName(i) {
2670
- const a = this._formulaCurrentConfigService.getDirtyDefinedNameMap(), e = this._formulaCurrentConfigService.getExecuteUnitId();
2671
- if (e != null && a[e] != null) {
2672
- const t = Object.keys(a[e]);
2673
- for (let r = 0, n = t.length; r < n; r++) {
2674
- const s = t[r];
2675
- if (i.indexOf(s) > -1)
2676
- return !0;
2677
- }
2678
- }
2679
- return !1;
2680
- }
2681
- _checkDefinedNameDirty(i) {
2682
- const a = this._formulaCurrentConfigService.getDirtyDefinedNameMap(), e = this._formulaCurrentConfigService.getExecuteUnitId();
2683
- if (e != null && a[e] != null) {
2684
- const t = Object.keys(a[e]);
2685
- for (let r = 0, n = t.length; r < n; r++)
2686
- if (t[r] === i)
2687
- return !0;
2688
- }
2689
- return !1;
2690
- }
2691
- _injectDefinedName(i) {
2692
- const a = this._formulaCurrentConfigService.getExecuteUnitId();
2693
- if (a == null)
2694
- return {
2695
- sequenceString: "",
2696
- hasDefinedName: !1,
2697
- definedNames: []
2698
- };
2699
- const e = this._lexerTreeBuilder.getSequenceNode(i);
2700
- let t = "", r = !1;
2701
- const n = [];
2702
- for (let s = 0, o = e.length; s < o; s++) {
2703
- const u = e[s];
2704
- if (typeof u == "string") {
2705
- t += u;
2706
- continue;
2707
- }
2708
- const { nodeType: c, token: l } = u;
2709
- if (c === $e.REFERENCE || c === $e.FUNCTION) {
2710
- const f = this._definedNamesService.getValueByName(a, l);
2711
- if (f) {
2712
- let h = f.formulaOrRefString;
2713
- h.substring(0, 1) === X.EQUALS && (h = h.substring(1)), t += h, n.push(f.name), r = !0;
2714
- } else this._checkDefinedNameDirty(l) ? (t += m.NAME, r = !0, n.push(l)) : t += l;
2715
- } else
2716
- t += l;
2717
- }
2718
- return {
2719
- sequenceString: t,
2720
- hasDefinedName: r,
2721
- definedNames: n
2722
- };
2734
+ return this._lexerTreeBuilder.treeBuilder(i, a, {
2735
+ unitId: this._formulaCurrentConfigService.getExecuteUnitId(),
2736
+ getValueByName: this._definedNamesService.getValueByName.bind(this._definedNamesService),
2737
+ getDirtyDefinedNameMap: this._formulaCurrentConfigService.getDirtyDefinedNameMap.bind(this._formulaCurrentConfigService)
2738
+ });
2723
2739
  }
2724
2740
  };
2725
2741
  Ar = Cl([
@@ -30313,12 +30329,7 @@ class lb extends V {
30313
30329
  if (c.isBoolean())
30314
30330
  return c;
30315
30331
  let d = c.getValue();
30316
- if (c.isNull() && (d = 0), c.isString()) {
30317
- if (!W(d))
30318
- return c;
30319
- d = Number(d);
30320
- }
30321
- h.isNull() && (h = j.create(" "));
30332
+ c.isNull() && (d = 0), c.isString() && W(d) && (d = Number(d)), h.isNull() && (h = j.create(" "));
30322
30333
  const _ = `${h.getValue()}`, C = qa(_, d);
30323
30334
  return j.create(_ === " " ? C.trimEnd() : C);
30324
30335
  });
package/lib/index.js CHANGED
@@ -971,31 +971,98 @@ class ga extends Ne {
971
971
  nodeMakerTest(e) {
972
972
  return this._nodeMaker(e);
973
973
  }
974
- treeBuilder(e, t = !0, r, n) {
974
+ treeBuilder(e, t = !0, r) {
975
+ var f;
975
976
  if (t === !0) {
976
- const h = hs.get(e), d = n == null ? void 0 : n(e);
977
+ const h = hs.get(e), d = r && ((f = this._simpleCheckDefinedName) == null ? void 0 : f.call(this, e, r));
977
978
  if (h && !d)
978
979
  return h;
979
980
  }
980
981
  this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Tt);
981
- const s = [];
982
- let o = this._nodeMaker(e, s);
983
- if (o === m.VALUE || s.length === 0)
984
- return o;
985
- let u = !1, c = "", l = [];
982
+ const n = [];
983
+ let s = this._nodeMaker(e, n);
984
+ if (s === m.VALUE || n.length === 0)
985
+ return s;
986
+ let o = !1, u = "", c = [];
986
987
  if (r) {
987
- const { hasDefinedName: h, sequenceString: d, definedNames: _ } = r(s);
988
- u = h, c = d, l = _;
988
+ const { hasDefinedName: h, sequenceString: d, definedNames: _ } = this._handleDefinedName(n, r);
989
+ o = h, u = d, c = _;
989
990
  }
990
- if (u && (this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Tt), o = this._nodeMaker(`=${c}`), o === m.VALUE))
991
- return o;
992
- const f = this._getTopNode(this._currentLexerNode);
993
- if (f && (this._currentLexerNode = f), t) {
991
+ if (o && (this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Tt), s = this._nodeMaker(`=${u}`), s === m.VALUE))
992
+ return s;
993
+ const l = this._getTopNode(this._currentLexerNode);
994
+ if (l && (this._currentLexerNode = l), t) {
994
995
  if (!this._suffixExpressionHandler(this._currentLexerNode))
995
996
  return m.VALUE;
996
997
  hs.set(e, this._currentLexerNode);
997
998
  }
998
- return u && this._currentLexerNode.setDefinedNames(l), this._currentLexerNode;
999
+ return o && this._currentLexerNode.setDefinedNames(c), this._currentLexerNode;
1000
+ }
1001
+ _handleDefinedName(e, t) {
1002
+ const { unitId: r, getValueByName: n } = t;
1003
+ if (r == null)
1004
+ return {
1005
+ sequenceString: "",
1006
+ hasDefinedName: !1,
1007
+ definedNames: []
1008
+ };
1009
+ const s = this.getSequenceNode(e);
1010
+ let o = "", u = !1;
1011
+ const c = [];
1012
+ for (let l = 0, f = s.length; l < f; l++) {
1013
+ const h = s[l];
1014
+ if (typeof h == "string") {
1015
+ o += h;
1016
+ continue;
1017
+ }
1018
+ const { nodeType: d, token: _ } = h;
1019
+ if (d === $e.REFERENCE || d === $e.FUNCTION) {
1020
+ const C = n(r, _);
1021
+ if (C) {
1022
+ const E = C.formulaOrRefString, b = this._handleNestedDefinedName(E, t);
1023
+ if (b == null || typeof b != "object")
1024
+ o += b || m.NAME, u = !0, c.push(_);
1025
+ else if (typeof b == "object") {
1026
+ const { sequenceString: R, definedNames: p } = b;
1027
+ o += R, p.forEach((N) => {
1028
+ c.push(N);
1029
+ }), u = !0;
1030
+ }
1031
+ } else this._checkDefinedNameDirty(_, t) ? (o += m.NAME, u = !0, c.push(_)) : o += _;
1032
+ } else
1033
+ o += _;
1034
+ }
1035
+ return {
1036
+ sequenceString: o,
1037
+ hasDefinedName: u,
1038
+ definedNames: c
1039
+ };
1040
+ }
1041
+ _handleNestedDefinedName(e, t) {
1042
+ const r = [], n = this._nodeMaker(e, r);
1043
+ return n === m.VALUE || r.length === 0 ? n : this._handleDefinedName(r, t);
1044
+ }
1045
+ _simpleCheckDefinedName(e, t) {
1046
+ const { getDirtyDefinedNameMap: r, unitId: n } = t, s = r(), o = n;
1047
+ if (o != null && s[o] != null) {
1048
+ const u = Object.keys(s[o]);
1049
+ for (let c = 0, l = u.length; c < l; c++) {
1050
+ const f = u[c];
1051
+ if (e.indexOf(f) > -1)
1052
+ return !0;
1053
+ }
1054
+ }
1055
+ return !1;
1056
+ }
1057
+ _checkDefinedNameDirty(e, t) {
1058
+ const { getDirtyDefinedNameMap: r, unitId: n } = t, s = r(), o = n;
1059
+ if (o != null && s[o] != null) {
1060
+ const u = Object.keys(s[o]);
1061
+ for (let c = 0, l = u.length; c < l; c++)
1062
+ if (u[c] === e)
1063
+ return !0;
1064
+ }
1065
+ return !1;
999
1066
  }
1000
1067
  // eslint-disable-next-line complexity
1001
1068
  _suffixExpressionHandler(e) {
@@ -2664,62 +2731,11 @@ let Ar = class extends Ne {
2664
2731
  super(), this._definedNamesService = i, this._lexerTreeBuilder = a, this._formulaCurrentConfigService = e;
2665
2732
  }
2666
2733
  treeBuilder(i, a = !0) {
2667
- return this._lexerTreeBuilder.treeBuilder(i, a, this._injectDefinedName.bind(this), this._simpleCheckDefinedName.bind(this));
2668
- }
2669
- _simpleCheckDefinedName(i) {
2670
- const a = this._formulaCurrentConfigService.getDirtyDefinedNameMap(), e = this._formulaCurrentConfigService.getExecuteUnitId();
2671
- if (e != null && a[e] != null) {
2672
- const t = Object.keys(a[e]);
2673
- for (let r = 0, n = t.length; r < n; r++) {
2674
- const s = t[r];
2675
- if (i.indexOf(s) > -1)
2676
- return !0;
2677
- }
2678
- }
2679
- return !1;
2680
- }
2681
- _checkDefinedNameDirty(i) {
2682
- const a = this._formulaCurrentConfigService.getDirtyDefinedNameMap(), e = this._formulaCurrentConfigService.getExecuteUnitId();
2683
- if (e != null && a[e] != null) {
2684
- const t = Object.keys(a[e]);
2685
- for (let r = 0, n = t.length; r < n; r++)
2686
- if (t[r] === i)
2687
- return !0;
2688
- }
2689
- return !1;
2690
- }
2691
- _injectDefinedName(i) {
2692
- const a = this._formulaCurrentConfigService.getExecuteUnitId();
2693
- if (a == null)
2694
- return {
2695
- sequenceString: "",
2696
- hasDefinedName: !1,
2697
- definedNames: []
2698
- };
2699
- const e = this._lexerTreeBuilder.getSequenceNode(i);
2700
- let t = "", r = !1;
2701
- const n = [];
2702
- for (let s = 0, o = e.length; s < o; s++) {
2703
- const u = e[s];
2704
- if (typeof u == "string") {
2705
- t += u;
2706
- continue;
2707
- }
2708
- const { nodeType: c, token: l } = u;
2709
- if (c === $e.REFERENCE || c === $e.FUNCTION) {
2710
- const f = this._definedNamesService.getValueByName(a, l);
2711
- if (f) {
2712
- let h = f.formulaOrRefString;
2713
- h.substring(0, 1) === X.EQUALS && (h = h.substring(1)), t += h, n.push(f.name), r = !0;
2714
- } else this._checkDefinedNameDirty(l) ? (t += m.NAME, r = !0, n.push(l)) : t += l;
2715
- } else
2716
- t += l;
2717
- }
2718
- return {
2719
- sequenceString: t,
2720
- hasDefinedName: r,
2721
- definedNames: n
2722
- };
2734
+ return this._lexerTreeBuilder.treeBuilder(i, a, {
2735
+ unitId: this._formulaCurrentConfigService.getExecuteUnitId(),
2736
+ getValueByName: this._definedNamesService.getValueByName.bind(this._definedNamesService),
2737
+ getDirtyDefinedNameMap: this._formulaCurrentConfigService.getDirtyDefinedNameMap.bind(this._formulaCurrentConfigService)
2738
+ });
2723
2739
  }
2724
2740
  };
2725
2741
  Ar = Cl([
@@ -30313,12 +30329,7 @@ class lb extends V {
30313
30329
  if (c.isBoolean())
30314
30330
  return c;
30315
30331
  let d = c.getValue();
30316
- if (c.isNull() && (d = 0), c.isString()) {
30317
- if (!W(d))
30318
- return c;
30319
- d = Number(d);
30320
- }
30321
- h.isNull() && (h = j.create(" "));
30332
+ c.isNull() && (d = 0), c.isString() && W(d) && (d = Number(d)), h.isNull() && (h = j.create(" "));
30322
30333
  const _ = `${h.getValue()}`, C = qa(_, d);
30323
30334
  return j.create(_ === " " ? C.trimEnd() : C);
30324
30335
  });
@@ -1,10 +1,17 @@
1
+ import { Nullable, AbsoluteRefType, Disposable } from '@univerjs/core';
2
+ import { IDirtyUnitSheetDefinedNameMap } from '../../basics/common';
3
+ import { IDefinedNamesServiceParam } from '../../services/defined-names.service';
1
4
  import { ISequenceArray, ISequenceNode } from '../utils/sequence';
2
- import { AbsoluteRefType, Disposable } from '@univerjs/core';
3
5
  import { FormulaAstLRU } from '../../basics/cache-lru';
4
6
  import { ErrorType } from '../../basics/error-type';
5
7
  import { LexerNode } from './lexer-node';
6
8
  export declare const FormulaLexerNodeCache: FormulaAstLRU<LexerNode>;
7
9
  export declare const FormulaSequenceNodeCache: FormulaAstLRU<(string | ISequenceNode)[]>;
10
+ interface IInjectDefinedNameParam {
11
+ unitId: Nullable<string>;
12
+ getValueByName(unitId: string, name: string): Nullable<IDefinedNamesServiceParam>;
13
+ getDirtyDefinedNameMap(): IDirtyUnitSheetDefinedNameMap;
14
+ }
8
15
  export declare class LexerTreeBuilder extends Disposable {
9
16
  private _currentLexerNode;
10
17
  private _upLevel;
@@ -62,11 +69,11 @@ export declare class LexerTreeBuilder extends Disposable {
62
69
  private _minusSplitSequenceNode;
63
70
  private _pushSequenceNode;
64
71
  nodeMakerTest(formulaString: string): ErrorType.VALUE | (string | LexerNode)[] | undefined;
65
- treeBuilder(formulaString: string, transformSuffix?: boolean, injectDefinedName?: (sequenceArray: ISequenceArray[]) => {
66
- sequenceString: string;
67
- hasDefinedName: boolean;
68
- definedNames: string[];
69
- }, simpleCheckDefinedName?: (formulaString: string) => boolean): ErrorType.VALUE | LexerNode | (string | LexerNode)[] | undefined;
72
+ treeBuilder(formulaString: string, transformSuffix?: boolean, injectDefinedNameParam?: IInjectDefinedNameParam): ErrorType.VALUE | LexerNode | (string | LexerNode)[] | undefined;
73
+ private _handleDefinedName;
74
+ private _handleNestedDefinedName;
75
+ private _simpleCheckDefinedName;
76
+ private _checkDefinedNameDirty;
70
77
  private _suffixExpressionHandler;
71
78
  private _processSuffixExpressionRemain;
72
79
  private _processSuffixExpressionCloseBracket;
@@ -131,3 +138,4 @@ export declare class LexerTreeBuilder extends Disposable {
131
138
  private _isScientificNotation;
132
139
  private _addSequenceArray;
133
140
  }
141
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { Disposable } from '@univerjs/core';
2
- import { ErrorType } from '../../basics/error-type';
3
2
  import { IFormulaCurrentConfigService } from '../../services/current-data.service';
4
3
  import { IDefinedNamesService } from '../../services/defined-names.service';
5
4
  import { LexerTreeBuilder } from './lexer-tree-builder';
@@ -8,8 +7,5 @@ export declare class Lexer extends Disposable {
8
7
  private readonly _lexerTreeBuilder;
9
8
  private readonly _formulaCurrentConfigService;
10
9
  constructor(_definedNamesService: IDefinedNamesService, _lexerTreeBuilder: LexerTreeBuilder, _formulaCurrentConfigService: IFormulaCurrentConfigService);
11
- treeBuilder(formulaString: string, transformSuffix?: boolean): ErrorType.VALUE | import('./lexer-node').LexerNode | (string | import('./lexer-node').LexerNode)[] | undefined;
12
- private _simpleCheckDefinedName;
13
- private _checkDefinedNameDirty;
14
- private _injectDefinedName;
10
+ treeBuilder(formulaString: string, transformSuffix?: boolean): import("../..").ErrorType.VALUE | import('./lexer-node').LexerNode | (string | import('./lexer-node').LexerNode)[] | undefined;
15
11
  }