@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 +75 -114
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +75 -114
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
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
|
-
|
|
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
|
|
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) =>
|
|
267
|
-
ASTMatch2.isNumber = (node) =>
|
|
268
|
-
ASTMatch2.isBoolean = (node) =>
|
|
269
|
-
ASTMatch2.isInteger = (node) =>
|
|
270
|
-
ASTMatch2.isObject = (node) =>
|
|
271
|
-
ASTMatch2.isArray = (node) =>
|
|
272
|
-
ASTMatch2.isMap = (node) =>
|
|
273
|
-
ASTMatch2.isCustomType = (node) =>
|
|
274
|
-
ASTMatch2.isVariableDeclaration = (node) =>
|
|
275
|
-
ASTMatch2.isProperty = (node) =>
|
|
276
|
-
ASTMatch2.isVariableDeclarationList = (node) =>
|
|
277
|
-
ASTMatch2.isEnumerateExpression = (node) =>
|
|
278
|
-
ASTMatch2.isKeyPathExpression = (node) =>
|
|
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
|
|
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 =
|
|
294
|
-
const isNewKey =
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
575
|
-
return (
|
|
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 ===
|
|
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
|
-
|
|
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 (
|
|
615
|
+
if (targetTypeJSON?.weak || targetTypeJSON?.kind === "Union" /* Union */) {
|
|
624
616
|
return isSuperEqual;
|
|
625
617
|
}
|
|
626
618
|
return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
|
|
627
|
-
(
|
|
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 !
|
|
628
|
+
return !targetTypeJSON?.items;
|
|
638
629
|
}
|
|
639
|
-
return
|
|
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:
|
|
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 (
|
|
697
|
+
if (targetTypeJSON?.weak || targetTypeJSON?.kind === "Union" /* Union */) {
|
|
708
698
|
return isSuperEqual;
|
|
709
699
|
}
|
|
710
700
|
return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
|
|
711
|
-
(
|
|
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 ||
|
|
722
|
-
return isValueTypeEqual &&
|
|
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:
|
|
729
|
-
valueType:
|
|
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
|
|
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 (
|
|
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 (
|
|
790
|
+
if (targetTypeJSON?.weak || targetTypeJSON?.kind === "Union" /* Union */) {
|
|
804
791
|
return isSuperEqual;
|
|
805
792
|
}
|
|
806
793
|
return targetTypeJSON && isSuperEqual && // 弱比较,只需要比较 Kind 即可
|
|
807
|
-
(
|
|
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 &&
|
|
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 (
|
|
843
|
-
return (
|
|
827
|
+
if (targetTypeJSON?.kind === "Union" /* Union */) {
|
|
828
|
+
return (targetTypeJSON?.types || [])?.some(
|
|
844
829
|
(_subType) => this.isTypeEqual(_subType)
|
|
845
830
|
);
|
|
846
831
|
}
|
|
847
|
-
return
|
|
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) => !
|
|
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
|
-
|
|
1000
|
-
|
|
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:
|
|
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
|
|
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 !==
|
|
1067
|
-
this.prevRefTypeHash =
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
1240
|
-
initializer:
|
|
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 ||
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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) && !
|
|
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) && !
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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";
|