@flowgram.ai/variable-core 0.1.0-alpha.8 → 0.1.0-alpha.9

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/esm/index.js CHANGED
@@ -91,10 +91,9 @@ var VariableTable = class {
91
91
  return disposables;
92
92
  }
93
93
  fireChange() {
94
- var _a;
95
94
  this._version++;
96
95
  this.onDataChangeEmitter.fire();
97
- (_a = this.parentTable) == null ? void 0 : _a.fireChange();
96
+ this.parentTable?.fireChange();
98
97
  }
99
98
  get version() {
100
99
  return this._version;
@@ -116,7 +115,7 @@ var VariableTable = class {
116
115
  return;
117
116
  }
118
117
  const variable = this.getVariableByKey(variableKey);
119
- return propertyKeys.length ? variable == null ? void 0 : variable.getByKeyPath(propertyKeys) : variable;
118
+ return propertyKeys.length ? variable?.getByKeyPath(propertyKeys) : variable;
120
119
  }
121
120
  /**
122
121
  * 根据 key 值找到相应的变量
@@ -150,10 +149,7 @@ var VariableTable = class {
150
149
  }
151
150
  dispose() {
152
151
  this.variableKeys.forEach(
153
- (_key) => {
154
- var _a;
155
- return (_a = this.parentTable) == null ? void 0 : _a.removeVariableFromTable(_key);
156
- }
152
+ (_key) => this.parentTable?.removeVariableFromTable(_key)
157
153
  );
158
154
  this.onDataChangeEmitter.dispose();
159
155
  }
@@ -263,21 +259,21 @@ var postConstructAST = () => (target, propertyKey) => {
263
259
  // src/ast/match.ts
264
260
  var ASTMatch;
265
261
  ((ASTMatch2) => {
266
- ASTMatch2.isString = (node) => (node == null ? void 0 : node.kind) === "String" /* String */;
267
- ASTMatch2.isNumber = (node) => (node == null ? void 0 : node.kind) === "Number" /* Number */;
268
- ASTMatch2.isBoolean = (node) => (node == null ? void 0 : node.kind) === "Boolean" /* Boolean */;
269
- ASTMatch2.isInteger = (node) => (node == null ? void 0 : node.kind) === "Integer" /* Integer */;
270
- ASTMatch2.isObject = (node) => (node == null ? void 0 : node.kind) === "Object" /* Object */;
271
- ASTMatch2.isArray = (node) => (node == null ? void 0 : node.kind) === "Array" /* Array */;
272
- ASTMatch2.isMap = (node) => (node == null ? void 0 : node.kind) === "Map" /* Map */;
273
- ASTMatch2.isCustomType = (node) => (node == null ? void 0 : node.kind) === "CustomType" /* CustomType */;
274
- ASTMatch2.isVariableDeclaration = (node) => (node == null ? void 0 : node.kind) === "VariableDeclaration" /* VariableDeclaration */;
275
- ASTMatch2.isProperty = (node) => (node == null ? void 0 : node.kind) === "Property" /* Property */;
276
- ASTMatch2.isVariableDeclarationList = (node) => (node == null ? void 0 : node.kind) === "VariableDeclarationList" /* VariableDeclarationList */;
277
- ASTMatch2.isEnumerateExpression = (node) => (node == null ? void 0 : node.kind) === "EnumerateExpression" /* EnumerateExpression */;
278
- ASTMatch2.isKeyPathExpression = (node) => (node == null ? void 0 : node.kind) === "KeyPathExpression" /* KeyPathExpression */;
262
+ ASTMatch2.isString = (node) => node?.kind === "String" /* String */;
263
+ ASTMatch2.isNumber = (node) => node?.kind === "Number" /* Number */;
264
+ ASTMatch2.isBoolean = (node) => node?.kind === "Boolean" /* Boolean */;
265
+ ASTMatch2.isInteger = (node) => node?.kind === "Integer" /* Integer */;
266
+ ASTMatch2.isObject = (node) => node?.kind === "Object" /* Object */;
267
+ ASTMatch2.isArray = (node) => node?.kind === "Array" /* Array */;
268
+ ASTMatch2.isMap = (node) => node?.kind === "Map" /* Map */;
269
+ ASTMatch2.isCustomType = (node) => node?.kind === "CustomType" /* CustomType */;
270
+ ASTMatch2.isVariableDeclaration = (node) => node?.kind === "VariableDeclaration" /* VariableDeclaration */;
271
+ ASTMatch2.isProperty = (node) => node?.kind === "Property" /* Property */;
272
+ ASTMatch2.isVariableDeclarationList = (node) => node?.kind === "VariableDeclarationList" /* VariableDeclarationList */;
273
+ ASTMatch2.isEnumerateExpression = (node) => node?.kind === "EnumerateExpression" /* EnumerateExpression */;
274
+ ASTMatch2.isKeyPathExpression = (node) => node?.kind === "KeyPathExpression" /* KeyPathExpression */;
279
275
  function is(node, targetType) {
280
- return (node == null ? void 0 : node.kind) === (targetType == null ? void 0 : targetType.kind);
276
+ return node?.kind === targetType?.kind;
281
277
  }
282
278
  ASTMatch2.is = is;
283
279
  })(ASTMatch || (ASTMatch = {}));
@@ -290,8 +286,8 @@ function updateChildNodeHelper({
290
286
  nextJSON
291
287
  }) {
292
288
  const currNode = getChildNode();
293
- const isNewKind = (currNode == null ? void 0 : currNode.kind) !== (nextJSON == null ? void 0 : nextJSON.kind);
294
- const isNewKey = (nextJSON == null ? void 0 : nextJSON.key) && (nextJSON == null ? void 0 : nextJSON.key) !== (currNode == null ? void 0 : currNode.key);
289
+ const isNewKind = currNode?.kind !== nextJSON?.kind;
290
+ const isNewKey = nextJSON?.key && nextJSON?.key !== currNode?.key;
295
291
  if (isNewKind || isNewKey) {
296
292
  if (currNode) {
297
293
  currNode.dispose();
@@ -306,7 +302,7 @@ function updateChildNodeHelper({
306
302
  this.fireChange();
307
303
  }
308
304
  } else if (nextJSON) {
309
- currNode == null ? void 0 : currNode.fromJSON(nextJSON);
305
+ currNode?.fromJSON(nextJSON);
310
306
  }
311
307
  return currNode;
312
308
  }
@@ -386,8 +382,7 @@ var ASTNode = class _ASTNode {
386
382
  */
387
383
  this.toDispose = new DisposableCollection3(
388
384
  Disposable2.create(() => {
389
- var _a;
390
- (_a = this.parent) == null ? void 0 : _a.fireChange();
385
+ this.parent?.fireChange();
391
386
  this.children.forEach((child) => child.dispose());
392
387
  })
393
388
  );
@@ -483,7 +478,6 @@ var ASTNode = class _ASTNode {
483
478
  * 触发当前节点更新
484
479
  */
485
480
  fireChange() {
486
- var _a;
487
481
  if (this.changeLocked || this.disposed) {
488
482
  return;
489
483
  }
@@ -494,7 +488,7 @@ var ASTNode = class _ASTNode {
494
488
  this._version++;
495
489
  this.value$.next(this);
496
490
  this.dispatchGlobalEvent({ type: "UpdateAST" });
497
- (_a = this.parent) == null ? void 0 : _a.fireChange();
491
+ this.parent?.fireChange();
498
492
  }
499
493
  /**
500
494
  * 节点的版本值
@@ -569,14 +563,13 @@ var BaseType = class extends ASTNode {
569
563
  * @param targetTypeJSON
570
564
  */
571
565
  isTypeEqual(targetTypeJSONOrKind) {
572
- var _a;
573
566
  const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
574
- if ((targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
575
- return (_a = (targetTypeJSON == null ? void 0 : targetTypeJSON.types) || []) == null ? void 0 : _a.some(
567
+ if (targetTypeJSON?.kind === "Union" /* Union */) {
568
+ return (targetTypeJSON?.types || [])?.some(
576
569
  (_subType) => this.isTypeEqual(_subType)
577
570
  );
578
571
  }
579
- return this.kind === (targetTypeJSON == null ? void 0 : targetTypeJSON.kind);
572
+ return this.kind === targetTypeJSON?.kind;
580
573
  }
581
574
  /**
582
575
  * 可下钻类型需实现
@@ -607,8 +600,7 @@ var ArrayType = class extends BaseType {
607
600
  }
608
601
  // items 类型是否可下钻
609
602
  get canDrilldownItems() {
610
- var _a;
611
- return !!(((_a = this.items) == null ? void 0 : _a.flags) & 16 /* DrilldownType */);
603
+ return !!(this.items?.flags & 16 /* DrilldownType */);
612
604
  }
613
605
  getByKeyPath(keyPath) {
614
606
  const [curr, ...rest] = keyPath || [];
@@ -620,11 +612,11 @@ var ArrayType = class extends BaseType {
620
612
  isTypeEqual(targetTypeJSONOrKind) {
621
613
  const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
622
614
  const isSuperEqual = super.isTypeEqual(targetTypeJSONOrKind);
623
- if ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
615
+ if (targetTypeJSON?.weak || targetTypeJSON?.kind === "Union" /* Union */) {
624
616
  return isSuperEqual;
625
617
  }
626
618
  return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
627
- ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || this.customStrongEqual(targetTypeJSON));
619
+ (targetTypeJSON?.weak || this.customStrongEqual(targetTypeJSON));
628
620
  }
629
621
  /**
630
622
  * Array 强比较
@@ -632,17 +624,15 @@ var ArrayType = class extends BaseType {
632
624
  * @returns
633
625
  */
634
626
  customStrongEqual(targetTypeJSON) {
635
- var _a;
636
627
  if (!this.items) {
637
- return !(targetTypeJSON == null ? void 0 : targetTypeJSON.items);
628
+ return !targetTypeJSON?.items;
638
629
  }
639
- return (_a = this.items) == null ? void 0 : _a.isTypeEqual(targetTypeJSON.items);
630
+ return this.items?.isTypeEqual(targetTypeJSON.items);
640
631
  }
641
632
  toJSON() {
642
- var _a;
643
633
  return {
644
634
  kind: "Array" /* Array */,
645
- items: (_a = this.items) == null ? void 0 : _a.toJSON()
635
+ items: this.items?.toJSON()
646
636
  };
647
637
  }
648
638
  };
@@ -704,11 +694,11 @@ var MapType = class extends BaseType {
704
694
  isTypeEqual(targetTypeJSONOrKind) {
705
695
  const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
706
696
  const isSuperEqual = super.isTypeEqual(targetTypeJSONOrKind);
707
- if ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
697
+ if (targetTypeJSON?.weak || targetTypeJSON?.kind === "Union" /* Union */) {
708
698
  return isSuperEqual;
709
699
  }
710
700
  return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
711
- ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || this.customStrongEqual(targetTypeJSON));
701
+ (targetTypeJSON?.weak || this.customStrongEqual(targetTypeJSON));
712
702
  }
713
703
  /**
714
704
  * Map 强比较
@@ -716,17 +706,15 @@ var MapType = class extends BaseType {
716
706
  * @returns
717
707
  */
718
708
  customStrongEqual(targetTypeJSON) {
719
- var _a, _b;
720
709
  const { keyType = "String" /* String */, valueType } = targetTypeJSON;
721
- const isValueTypeEqual = !valueType && !this.valueType || ((_a = this.valueType) == null ? void 0 : _a.isTypeEqual(valueType));
722
- return isValueTypeEqual && ((_b = this.keyType) == null ? void 0 : _b.isTypeEqual(keyType));
710
+ const isValueTypeEqual = !valueType && !this.valueType || this.valueType?.isTypeEqual(valueType);
711
+ return isValueTypeEqual && this.keyType?.isTypeEqual(keyType);
723
712
  }
724
713
  toJSON() {
725
- var _a, _b;
726
714
  return {
727
715
  kind: "Map" /* Map */,
728
- keyType: (_a = this.keyType) == null ? void 0 : _a.toJSON(),
729
- valueType: (_b = this.valueType) == null ? void 0 : _b.toJSON()
716
+ keyType: this.keyType?.toJSON(),
717
+ valueType: this.valueType?.toJSON()
730
718
  };
731
719
  }
732
720
  };
@@ -762,7 +750,7 @@ var ObjectType = class extends BaseType {
762
750
  });
763
751
  removedKeys.forEach((key) => {
764
752
  const property = this.propertyTable.get(key);
765
- property == null ? void 0 : property.dispose();
753
+ property?.dispose();
766
754
  this.propertyTable.delete(key);
767
755
  this.fireChange();
768
756
  });
@@ -786,13 +774,12 @@ var ObjectType = class extends BaseType {
786
774
  * @returns
787
775
  */
788
776
  getByKeyPath(keyPath) {
789
- var _a;
790
777
  const [curr, ...restKeyPath] = keyPath;
791
778
  const property = this.propertyTable.get(curr);
792
779
  if (!restKeyPath.length) {
793
780
  return property;
794
781
  }
795
- if ((property == null ? void 0 : property.type) && ((_a = property == null ? void 0 : property.type) == null ? void 0 : _a.flags) & 16 /* DrilldownType */) {
782
+ if (property?.type && property?.type?.flags & 16 /* DrilldownType */) {
796
783
  return property.type.getByKeyPath(restKeyPath);
797
784
  }
798
785
  return void 0;
@@ -800,11 +787,11 @@ var ObjectType = class extends BaseType {
800
787
  isTypeEqual(targetTypeJSONOrKind) {
801
788
  const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
802
789
  const isSuperEqual = super.isTypeEqual(targetTypeJSONOrKind);
803
- if ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
790
+ if (targetTypeJSON?.weak || targetTypeJSON?.kind === "Union" /* Union */) {
804
791
  return isSuperEqual;
805
792
  }
806
793
  return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
807
- ((targetTypeJSON == null ? void 0 : targetTypeJSON.weak) || this.customStrongEqual(targetTypeJSON));
794
+ (targetTypeJSON?.weak || this.customStrongEqual(targetTypeJSON));
808
795
  }
809
796
  /**
810
797
  * Object 类型强比较
@@ -817,9 +804,8 @@ var ObjectType = class extends BaseType {
817
804
  const targetPropertyKeys = targetProperties.map((_target) => _target.key);
818
805
  const isKeyStrongEqual = !xor(sourcePropertyKeys, targetPropertyKeys).length;
819
806
  return isKeyStrongEqual && targetProperties.every((targetProperty) => {
820
- var _a;
821
807
  const sourceProperty = this.propertyTable.get(targetProperty.key);
822
- return sourceProperty && sourceProperty.key === targetProperty.key && ((_a = sourceProperty.type) == null ? void 0 : _a.isTypeEqual(targetProperty == null ? void 0 : targetProperty.type));
808
+ return sourceProperty && sourceProperty.key === targetProperty.key && sourceProperty.type?.isTypeEqual(targetProperty?.type);
823
809
  });
824
810
  }
825
811
  };
@@ -837,14 +823,13 @@ var CustomType = class extends BaseType {
837
823
  }
838
824
  }
839
825
  isTypeEqual(targetTypeJSONOrKind) {
840
- var _a;
841
826
  const targetTypeJSON = parseTypeJsonOrKind(targetTypeJSONOrKind);
842
- if ((targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === "Union" /* Union */) {
843
- return (_a = (targetTypeJSON == null ? void 0 : targetTypeJSON.types) || []) == null ? void 0 : _a.some(
827
+ if (targetTypeJSON?.kind === "Union" /* Union */) {
828
+ return (targetTypeJSON?.types || [])?.some(
844
829
  (_subType) => this.isTypeEqual(_subType)
845
830
  );
846
831
  }
847
- return (targetTypeJSON == null ? void 0 : targetTypeJSON.kind) === this.kind && (targetTypeJSON == null ? void 0 : targetTypeJSON.typeName) === this.typeName;
832
+ return targetTypeJSON?.kind === this.kind && targetTypeJSON?.typeName === this.typeName;
848
833
  }
849
834
  };
850
835
  CustomType.kind = "CustomType" /* CustomType */;
@@ -892,7 +877,7 @@ var BaseExpression = class extends ASTNode {
892
877
  map2(() => this.getRefFields()),
893
878
  distinctUntilChanged2(shallowEqual2),
894
879
  switchMap2(
895
- (refs) => !(refs == null ? void 0 : refs.length) ? of([]) : combineLatest(
880
+ (refs) => !refs?.length ? of([]) : combineLatest(
896
881
  refs.map(
897
882
  (ref) => ref ? ref.value$ : of(void 0)
898
883
  )
@@ -996,9 +981,8 @@ var EnumerateExpression = class extends BaseExpression {
996
981
  return this._enumerateFor;
997
982
  }
998
983
  get returnType() {
999
- var _a;
1000
- const childReturnType = (_a = this.enumerateFor) == null ? void 0 : _a.returnType;
1001
- if ((childReturnType == null ? void 0 : childReturnType.kind) === "Array" /* Array */) {
984
+ const childReturnType = this.enumerateFor?.returnType;
985
+ if (childReturnType?.kind === "Array" /* Array */) {
1002
986
  return childReturnType.items;
1003
987
  }
1004
988
  return void 0;
@@ -1010,10 +994,9 @@ var EnumerateExpression = class extends BaseExpression {
1010
994
  this.updateChildNodeByKey("_enumerateFor", expression);
1011
995
  }
1012
996
  toJSON() {
1013
- var _a;
1014
997
  return {
1015
998
  kind: "EnumerateExpression" /* EnumerateExpression */,
1016
- enumerateFor: (_a = this.enumerateFor) == null ? void 0 : _a.toJSON()
999
+ enumerateFor: this.enumerateFor?.toJSON()
1017
1000
  };
1018
1001
  }
1019
1002
  };
@@ -1028,7 +1011,7 @@ function getAllRefs(ast) {
1028
1011
  return getAllChildren(ast).filter((_child) => _child.flags & 4 /* Expression */).map((_child) => _child.refs).flat().filter(Boolean);
1029
1012
  }
1030
1013
  function checkRefCycle(curr, refNodes) {
1031
- if (intersection(curr.scope.coverScopes, refNodes.map((_ref) => _ref == null ? void 0 : _ref.scope).filter(Boolean)).length === 0) {
1014
+ if (intersection(curr.scope.coverScopes, refNodes.map((_ref) => _ref?.scope).filter(Boolean)).length === 0) {
1032
1015
  return false;
1033
1016
  }
1034
1017
  const visited = /* @__PURE__ */ new Set();
@@ -1061,10 +1044,9 @@ var KeyPathExpressionV2 = class extends BaseExpression {
1061
1044
  }),
1062
1045
  subsToDisposable(
1063
1046
  this.refs$.subscribe((_type) => {
1064
- var _a, _b;
1065
1047
  const [ref] = this._refs;
1066
- if (this.prevRefTypeHash !== ((_a = ref == null ? void 0 : ref.type) == null ? void 0 : _a.hash)) {
1067
- this.prevRefTypeHash = (_b = ref == null ? void 0 : ref.type) == null ? void 0 : _b.hash;
1048
+ if (this.prevRefTypeHash !== ref?.type?.hash) {
1049
+ this.prevRefTypeHash = ref?.type?.hash;
1068
1050
  this.updateChildNodeByKey("_returnType", this.getReturnTypeJSONByRef(ref));
1069
1051
  }
1070
1052
  })
@@ -1105,8 +1087,7 @@ var KeyPathExpressionV2 = class extends BaseExpression {
1105
1087
  }
1106
1088
  }
1107
1089
  getReturnTypeJSONByRef(_ref) {
1108
- var _a;
1109
- return (_a = _ref == null ? void 0 : _ref.type) == null ? void 0 : _a.toJSON();
1090
+ return _ref?.type?.toJSON();
1110
1091
  }
1111
1092
  toJSON() {
1112
1093
  return {
@@ -1126,8 +1107,7 @@ var WrapArrayExpression = class extends BaseExpression {
1126
1107
  return this._returnType;
1127
1108
  }
1128
1109
  refreshReturnType() {
1129
- var _a, _b;
1130
- const childReturnTypeJSON = (_b = (_a = this.wrapFor) == null ? void 0 : _a.returnType) == null ? void 0 : _b.toJSON();
1110
+ const childReturnTypeJSON = this.wrapFor?.returnType?.toJSON();
1131
1111
  this.updateChildNodeByKey("_returnType", {
1132
1112
  kind: "Array" /* Array */,
1133
1113
  items: childReturnTypeJSON
@@ -1140,19 +1120,15 @@ var WrapArrayExpression = class extends BaseExpression {
1140
1120
  this.updateChildNodeByKey("_wrapFor", expression);
1141
1121
  }
1142
1122
  toJSON() {
1143
- var _a;
1144
1123
  return {
1145
1124
  kind: "WrapArrayExpression" /* WrapArrayExpression */,
1146
- wrapFor: (_a = this.wrapFor) == null ? void 0 : _a.toJSON()
1125
+ wrapFor: this.wrapFor?.toJSON()
1147
1126
  };
1148
1127
  }
1149
1128
  init() {
1150
1129
  this.toDispose.push(
1151
1130
  this.subscribe(this.refreshReturnType, {
1152
- selector: (curr) => {
1153
- var _a;
1154
- return (_a = curr.wrapFor) == null ? void 0 : _a.returnType;
1155
- }
1131
+ selector: (curr) => curr.wrapFor?.returnType
1156
1132
  })
1157
1133
  );
1158
1134
  }
@@ -1180,8 +1156,7 @@ var BaseVariableField = class extends ASTNode {
1180
1156
  return this._meta;
1181
1157
  }
1182
1158
  get type() {
1183
- var _a;
1184
- return ((_a = this._initializer) == null ? void 0 : _a.returnType) || this._type;
1159
+ return this._initializer?.returnType || this._type;
1185
1160
  }
1186
1161
  get initializer() {
1187
1162
  return this._initializer;
@@ -1213,8 +1188,7 @@ var BaseVariableField = class extends ASTNode {
1213
1188
  * @returns
1214
1189
  */
1215
1190
  getByKeyPath(keyPath) {
1216
- var _a;
1217
- if (((_a = this.type) == null ? void 0 : _a.flags) & 16 /* DrilldownType */) {
1191
+ if (this.type?.flags & 16 /* DrilldownType */) {
1218
1192
  return this.type.getByKeyPath(keyPath);
1219
1193
  }
1220
1194
  return void 0;
@@ -1232,12 +1206,11 @@ var BaseVariableField = class extends ASTNode {
1232
1206
  * @returns
1233
1207
  */
1234
1208
  toJSON() {
1235
- var _a, _b;
1236
1209
  return {
1237
1210
  kind: this.kind,
1238
1211
  key: this.key,
1239
- type: (_a = this.type) == null ? void 0 : _a.toJSON(),
1240
- initializer: (_b = this.initializer) == null ? void 0 : _b.toJSON(),
1212
+ type: this.type?.toJSON(),
1213
+ initializer: this.initializer?.toJSON(),
1241
1214
  meta: this._meta
1242
1215
  };
1243
1216
  }
@@ -1286,9 +1259,8 @@ var VariableDeclarationList = class extends ASTNode {
1286
1259
  const prev = [...this.declarations || []];
1287
1260
  this.declarations = (declarations || []).map(
1288
1261
  (declaration, idx) => {
1289
- var _a, _b;
1290
1262
  const order = (startOrder || 0) + idx;
1291
- const declarationKey = declaration.key || ((_b = (_a = this.declarations) == null ? void 0 : _a[idx]) == null ? void 0 : _b.key);
1263
+ const declarationKey = declaration.key || this.declarations?.[idx]?.key;
1292
1264
  const existDeclaration = this.declarationTable.get(declarationKey);
1293
1265
  if (declarationKey) {
1294
1266
  removedKeys.delete(declarationKey);
@@ -1310,7 +1282,7 @@ var VariableDeclarationList = class extends ASTNode {
1310
1282
  );
1311
1283
  removedKeys.forEach((key) => {
1312
1284
  const declaration = this.declarationTable.get(key);
1313
- declaration == null ? void 0 : declaration.dispose();
1285
+ declaration?.dispose();
1314
1286
  this.declarationTable.delete(key);
1315
1287
  });
1316
1288
  this.dispatchGlobalEvent({
@@ -1436,8 +1408,7 @@ var MapNode = class extends ASTNode {
1436
1408
  * @param key
1437
1409
  */
1438
1410
  remove(key) {
1439
- var _a;
1440
- (_a = this.get(key)) == null ? void 0 : _a.dispose();
1411
+ this.get(key)?.dispose();
1441
1412
  this.map.delete(key);
1442
1413
  this.fireChange();
1443
1414
  }
@@ -1483,7 +1454,6 @@ var ASTRegisters = class {
1483
1454
  * @returns
1484
1455
  */
1485
1456
  createAST(json, { parent, scope }) {
1486
- var _a;
1487
1457
  const Registry = this.astMap.get(json.kind);
1488
1458
  if (!Registry) {
1489
1459
  throw Error(`ASTKind: ${String(json.kind)} can not find its ASTNode Registry`);
@@ -1495,14 +1465,14 @@ var ASTRegisters = class {
1495
1465
  scope,
1496
1466
  parent
1497
1467
  },
1498
- (injector == null ? void 0 : injector()) || {}
1468
+ injector?.() || {}
1499
1469
  );
1500
1470
  node.changeLocked = true;
1501
1471
  node.fromJSON(omit(json, ["key", "kind"]));
1502
1472
  node.changeLocked = false;
1503
1473
  if (Reflect.hasMetadata(POST_CONSTRUCT_AST_SYMBOL, node)) {
1504
1474
  const postConstructKey = Reflect.getMetadata(POST_CONSTRUCT_AST_SYMBOL, node);
1505
- (_a = node[postConstructKey]) == null ? void 0 : _a.call(node);
1475
+ node[postConstructKey]?.();
1506
1476
  }
1507
1477
  return node;
1508
1478
  }
@@ -1602,14 +1572,12 @@ var ScopeOutputData = class {
1602
1572
  }
1603
1573
  }),
1604
1574
  this.scope.event.on("DisposeAST", (_action) => {
1605
- var _a;
1606
- if (((_a = _action.ast) == null ? void 0 : _a.kind) === "VariableDeclaration" /* VariableDeclaration */) {
1575
+ if (_action.ast?.kind === "VariableDeclaration" /* VariableDeclaration */) {
1607
1576
  this.removeVariableFromTable(_action.ast.key);
1608
1577
  }
1609
1578
  }),
1610
1579
  this.scope.event.on("NewAST", (_action) => {
1611
- var _a;
1612
- if (((_a = _action.ast) == null ? void 0 : _a.kind) === "VariableDeclaration" /* VariableDeclaration */) {
1580
+ if (_action.ast?.kind === "VariableDeclaration" /* VariableDeclaration */) {
1613
1581
  this.addVariableToTable(_action.ast);
1614
1582
  }
1615
1583
  }),
@@ -1852,13 +1820,13 @@ var Scope = class {
1852
1820
  get depScopes() {
1853
1821
  return this.memo(
1854
1822
  "deps",
1855
- () => this.variableEngine.chain.getDeps(this).filter((_scope) => Boolean(_scope) && !(_scope == null ? void 0 : _scope.disposed))
1823
+ () => this.variableEngine.chain.getDeps(this).filter((_scope) => Boolean(_scope) && !_scope?.disposed)
1856
1824
  );
1857
1825
  }
1858
1826
  get coverScopes() {
1859
1827
  return this.memo(
1860
1828
  "covers",
1861
- () => this.variableEngine.chain.getCovers(this).filter((_scope) => Boolean(_scope) && !(_scope == null ? void 0 : _scope.disposed))
1829
+ () => this.variableEngine.chain.getCovers(this).filter((_scope) => Boolean(_scope) && !_scope?.disposed)
1862
1830
  );
1863
1831
  }
1864
1832
  dispose() {
@@ -1904,8 +1872,7 @@ var VariableEngine = class {
1904
1872
  }
1905
1873
  // 移除作用域
1906
1874
  removeScopeById(scopeId) {
1907
- var _a;
1908
- (_a = this.getScopeById(scopeId)) == null ? void 0 : _a.dispose();
1875
+ this.getScopeById(scopeId)?.dispose();
1909
1876
  }
1910
1877
  /**
1911
1878
  * Get Scope, if Scope exists and type is same, will use it directly
@@ -1989,8 +1956,7 @@ var VariableFieldKeyRenameService = class {
1989
1956
  this.onDisposeInList = this.disposeInListEmitter.event;
1990
1957
  }
1991
1958
  handleFieldListChange(ast, prev, next) {
1992
- var _a, _b;
1993
- if (!ast || !(prev == null ? void 0 : prev.length) || !(next == null ? void 0 : next.length)) {
1959
+ if (!ast || !prev?.length || !next?.length) {
1994
1960
  this.notifyFieldsDispose(prev, next);
1995
1961
  return;
1996
1962
  }
@@ -2008,7 +1974,7 @@ var VariableFieldKeyRenameService = class {
2008
1974
  return;
2009
1975
  }
2010
1976
  existFieldChanged = true;
2011
- if (((_a = prevField.type) == null ? void 0 : _a.kind) === ((_b = nextField.type) == null ? void 0 : _b.kind)) {
1977
+ if (prevField.type?.kind === nextField.type?.kind) {
2012
1978
  renameNodeInfo = { before: prevField, after: nextField };
2013
1979
  }
2014
1980
  }
@@ -2028,15 +1994,13 @@ var VariableFieldKeyRenameService = class {
2028
1994
  this.variableEngine.onGlobalEvent(
2029
1995
  "VariableListChange",
2030
1996
  (_action) => {
2031
- var _a, _b;
2032
- this.handleFieldListChange(_action.ast, (_a = _action.payload) == null ? void 0 : _a.prev, (_b = _action.payload) == null ? void 0 : _b.next);
1997
+ this.handleFieldListChange(_action.ast, _action.payload?.prev, _action.payload?.next);
2033
1998
  }
2034
1999
  ),
2035
2000
  this.variableEngine.onGlobalEvent(
2036
2001
  "ObjectPropertiesChange",
2037
2002
  (_action) => {
2038
- var _a, _b;
2039
- this.handleFieldListChange(_action.ast, (_a = _action.payload) == null ? void 0 : _a.prev, (_b = _action.payload) == null ? void 0 : _b.next);
2003
+ this.handleFieldListChange(_action.ast, _action.payload?.prev, _action.payload?.next);
2040
2004
  }
2041
2005
  )
2042
2006
  ]);
@@ -2072,10 +2036,7 @@ import { createContext, useContext } from "react";
2072
2036
  var ScopeContext = createContext(null);
2073
2037
  var ScopeProvider = ScopeContext.Provider;
2074
2038
  var useScopeContext = () => useContext(ScopeContext);
2075
- var useCurrentScope = () => {
2076
- var _a;
2077
- return (_a = useContext(ScopeContext)) == null ? void 0 : _a.scope;
2078
- };
2039
+ var useCurrentScope = () => useContext(ScopeContext)?.scope;
2079
2040
 
2080
2041
  // src/react/hooks/useScopeAvailable.ts
2081
2042
  import { useEffect } from "react";