Browse Source

fix: fixed-layout private scope covers (#496)

Yiwei Mao 6 months ago
parent
commit
3bfd4172ed

+ 9 - 0
packages/variable-engine/variable-core/src/scope/scope.ts

@@ -131,6 +131,15 @@ export class Scope<ScopeMeta extends Record<string, any> = Record<string, any>>
    */
   public setVar(json: ASTNodeJSON): ASTNode;
 
+  /**
+   * Sets a variable in the Scope by key.
+   *
+   * @param key - The key of the variable to set.
+   * @param json - The JSON value to store.
+   * @returns The updated AST node.
+   */
+  public setVar(key: string, json: ASTNodeJSON): ASTNode;
+
   public setVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {
     if (typeof arg1 === 'string' && arg2 !== undefined) {
       return this.ast.set(arg1, arg2);

+ 0 - 7
packages/variable-engine/variable-layout/__tests__/__snapshots__/variable-fix-enable-global-scope.test.ts.snap

@@ -491,7 +491,6 @@ Map {
   ],
   "forEach_260a8f85ff2_private" => [
     "forEach_260a8f85ff2",
-    "forEach_260a8f85ff2_private",
     "createRecord_8f85ff2c11d",
     "createRecord_8f85ff2c11d_private",
     "exclusiveSplit_ff2c11d0fb4",
@@ -506,7 +505,6 @@ Map {
   ],
   "exclusiveSplit_ff2c11d0fb4_private" => [
     "exclusiveSplit_ff2c11d0fb4",
-    "exclusiveSplit_ff2c11d0fb4_private",
     "branch_f2c11d0fb42",
     "branch_f2c11d0fb42_private",
     "branch_2c11d0fb42c",
@@ -520,7 +518,6 @@ Map {
   ],
   "exclusiveSplit_88dbf2c60ae_private" => [
     "exclusiveSplit_88dbf2c60ae",
-    "exclusiveSplit_88dbf2c60ae_private",
     "branch_8dbf2c60aee",
     "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
@@ -538,7 +535,6 @@ Map {
   ],
   "branch_8dbf2c60aee_private" => [
     "branch_8dbf2c60aee",
-    "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
     "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
@@ -550,7 +546,6 @@ Map {
   ],
   "exclusiveSplit_a59afaadc9a_private" => [
     "exclusiveSplit_a59afaadc9a",
-    "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
     "branch_59afaadc9ac_private",
     "branch_9afaadc9acd",
@@ -563,7 +558,6 @@ Map {
   ],
   "branch_9afaadc9acd_private" => [
     "branch_9afaadc9acd",
-    "branch_9afaadc9acd_private",
     "deleteRecords_c32807e97c5",
     "deleteRecords_c32807e97c5_private",
   ],
@@ -572,7 +566,6 @@ Map {
   ],
   "branch_dbf2c60aee4_private" => [
     "branch_dbf2c60aee4",
-    "branch_dbf2c60aee4_private",
     "updateRecords_7ed2a172c32",
     "updateRecords_7ed2a172c32_private",
   ],

+ 15 - 7
packages/variable-engine/variable-layout/__tests__/__snapshots__/variable-fix-layout-filter-start-end.test.ts.snap

@@ -75,19 +75,33 @@ exports[`Variable Fix Layout Filter Start End > test get Covers After Init Priva
 Map {
   "start" => [
     "getRecords_07e97c55832",
+    "getRecords_07e97c55832_private",
     "forEach_260a8f85ff2",
+    "forEach_260a8f85ff2_private",
     "createRecord_8f85ff2c11d",
+    "createRecord_8f85ff2c11d_private",
     "exclusiveSplit_ff2c11d0fb4",
+    "exclusiveSplit_ff2c11d0fb4_private",
     "branch_f2c11d0fb42",
+    "branch_f2c11d0fb42_private",
     "branch_2c11d0fb42c",
+    "branch_2c11d0fb42c_private",
     "exclusiveSplit_88dbf2c60ae",
+    "exclusiveSplit_88dbf2c60ae_private",
     "branch_8dbf2c60aee",
+    "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
+    "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
+    "branch_59afaadc9ac_private",
     "branch_9afaadc9acd",
+    "branch_9afaadc9acd_private",
     "deleteRecords_c32807e97c5",
+    "deleteRecords_c32807e97c5_private",
     "branch_dbf2c60aee4",
+    "branch_dbf2c60aee4_private",
     "updateRecords_7ed2a172c32",
+    "updateRecords_7ed2a172c32_private",
   ],
   "getRecords_07e97c55832" => [
     "forEach_260a8f85ff2",
@@ -382,6 +396,7 @@ Map {
     "getRecords_07e97c55832",
     "forEach_260a8f85ff2",
     "exclusiveSplit_88dbf2c60ae",
+    "end_private",
   ],
 }
 `;
@@ -396,7 +411,6 @@ Map {
   ],
   "forEach_260a8f85ff2_private" => [
     "forEach_260a8f85ff2",
-    "forEach_260a8f85ff2_private",
     "createRecord_8f85ff2c11d",
     "createRecord_8f85ff2c11d_private",
     "exclusiveSplit_ff2c11d0fb4",
@@ -411,7 +425,6 @@ Map {
   ],
   "exclusiveSplit_ff2c11d0fb4_private" => [
     "exclusiveSplit_ff2c11d0fb4",
-    "exclusiveSplit_ff2c11d0fb4_private",
     "branch_f2c11d0fb42",
     "branch_f2c11d0fb42_private",
     "branch_2c11d0fb42c",
@@ -425,7 +438,6 @@ Map {
   ],
   "exclusiveSplit_88dbf2c60ae_private" => [
     "exclusiveSplit_88dbf2c60ae",
-    "exclusiveSplit_88dbf2c60ae_private",
     "branch_8dbf2c60aee",
     "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
@@ -443,7 +455,6 @@ Map {
   ],
   "branch_8dbf2c60aee_private" => [
     "branch_8dbf2c60aee",
-    "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
     "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
@@ -455,7 +466,6 @@ Map {
   ],
   "exclusiveSplit_a59afaadc9a_private" => [
     "exclusiveSplit_a59afaadc9a",
-    "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
     "branch_59afaadc9ac_private",
     "branch_9afaadc9acd",
@@ -468,7 +478,6 @@ Map {
   ],
   "branch_9afaadc9acd_private" => [
     "branch_9afaadc9acd",
-    "branch_9afaadc9acd_private",
     "deleteRecords_c32807e97c5",
     "deleteRecords_c32807e97c5_private",
   ],
@@ -477,7 +486,6 @@ Map {
   ],
   "branch_dbf2c60aee4_private" => [
     "branch_dbf2c60aee4",
-    "branch_dbf2c60aee4_private",
     "updateRecords_7ed2a172c32",
     "updateRecords_7ed2a172c32_private",
   ],

+ 0 - 7
packages/variable-engine/variable-layout/__tests__/__snapshots__/variable-fix-layout-no-config.test.ts.snap

@@ -458,7 +458,6 @@ Map {
   ],
   "forEach_260a8f85ff2_private" => [
     "forEach_260a8f85ff2",
-    "forEach_260a8f85ff2_private",
     "createRecord_8f85ff2c11d",
     "createRecord_8f85ff2c11d_private",
     "exclusiveSplit_ff2c11d0fb4",
@@ -473,7 +472,6 @@ Map {
   ],
   "exclusiveSplit_ff2c11d0fb4_private" => [
     "exclusiveSplit_ff2c11d0fb4",
-    "exclusiveSplit_ff2c11d0fb4_private",
     "branch_f2c11d0fb42",
     "branch_f2c11d0fb42_private",
     "branch_2c11d0fb42c",
@@ -487,7 +485,6 @@ Map {
   ],
   "exclusiveSplit_88dbf2c60ae_private" => [
     "exclusiveSplit_88dbf2c60ae",
-    "exclusiveSplit_88dbf2c60ae_private",
     "branch_8dbf2c60aee",
     "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
@@ -505,7 +502,6 @@ Map {
   ],
   "branch_8dbf2c60aee_private" => [
     "branch_8dbf2c60aee",
-    "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
     "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
@@ -517,7 +513,6 @@ Map {
   ],
   "exclusiveSplit_a59afaadc9a_private" => [
     "exclusiveSplit_a59afaadc9a",
-    "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
     "branch_59afaadc9ac_private",
     "branch_9afaadc9acd",
@@ -530,7 +525,6 @@ Map {
   ],
   "branch_9afaadc9acd_private" => [
     "branch_9afaadc9acd",
-    "branch_9afaadc9acd_private",
     "deleteRecords_c32807e97c5",
     "deleteRecords_c32807e97c5_private",
   ],
@@ -539,7 +533,6 @@ Map {
   ],
   "branch_dbf2c60aee4_private" => [
     "branch_dbf2c60aee4",
-    "branch_dbf2c60aee4_private",
     "updateRecords_7ed2a172c32",
     "updateRecords_7ed2a172c32_private",
   ],

+ 0 - 7
packages/variable-engine/variable-layout/__tests__/__snapshots__/variable-fix-layout.test.ts.snap

@@ -555,7 +555,6 @@ Map {
   ],
   "forEach_260a8f85ff2_private" => [
     "forEach_260a8f85ff2",
-    "forEach_260a8f85ff2_private",
     "createRecord_8f85ff2c11d",
     "createRecord_8f85ff2c11d_private",
     "exclusiveSplit_ff2c11d0fb4",
@@ -570,7 +569,6 @@ Map {
   ],
   "exclusiveSplit_ff2c11d0fb4_private" => [
     "exclusiveSplit_ff2c11d0fb4",
-    "exclusiveSplit_ff2c11d0fb4_private",
     "branch_f2c11d0fb42",
     "branch_f2c11d0fb42_private",
     "branch_2c11d0fb42c",
@@ -584,7 +582,6 @@ Map {
   ],
   "exclusiveSplit_88dbf2c60ae_private" => [
     "exclusiveSplit_88dbf2c60ae",
-    "exclusiveSplit_88dbf2c60ae_private",
     "branch_8dbf2c60aee",
     "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
@@ -602,7 +599,6 @@ Map {
   ],
   "branch_8dbf2c60aee_private" => [
     "branch_8dbf2c60aee",
-    "branch_8dbf2c60aee_private",
     "exclusiveSplit_a59afaadc9a",
     "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
@@ -614,7 +610,6 @@ Map {
   ],
   "exclusiveSplit_a59afaadc9a_private" => [
     "exclusiveSplit_a59afaadc9a",
-    "exclusiveSplit_a59afaadc9a_private",
     "branch_59afaadc9ac",
     "branch_59afaadc9ac_private",
     "branch_9afaadc9acd",
@@ -627,7 +622,6 @@ Map {
   ],
   "branch_9afaadc9acd_private" => [
     "branch_9afaadc9acd",
-    "branch_9afaadc9acd_private",
     "deleteRecords_c32807e97c5",
     "deleteRecords_c32807e97c5_private",
   ],
@@ -636,7 +630,6 @@ Map {
   ],
   "branch_dbf2c60aee4_private" => [
     "branch_dbf2c60aee4",
-    "branch_dbf2c60aee4_private",
     "updateRecords_7ed2a172c32",
     "updateRecords_7ed2a172c32_private",
   ],

+ 1 - 1
packages/variable-engine/variable-layout/src/chains/fixed-layout-scope-chain.ts

@@ -160,7 +160,7 @@ export class FixedLayoutScopeChain extends ScopeChain {
       covers.push(
         ...this.getAllSortedChildScope(node, {
           addNodePrivateScope: true,
-        })
+        }).filter((_scope) => _scope !== scope)
       );
       return this.transformService.transformCovers(covers, { scope });
     }

+ 2 - 10
packages/variable-engine/variable-layout/src/flow-node-variable-data.ts

@@ -169,16 +169,8 @@ export class FlowNodeVariableData extends EntityData {
         node: this.entity,
         type: FlowNodeScopeTypeEnum.private,
       } as FlowNodeScopeMeta);
-      // 1. Notify the covering scopes of private to update dependencies
-      this._private.coverScopes.forEach((_scope) => {
-        _scope.refreshDeps();
-      });
-      // 2. Notify the dependent scopes of private to update their covers
-      this._private.depScopes.forEach((_scope) => {
-        _scope.refreshCovers();
-      });
-      // 3. The private scope itself needs to refresh its dependencies
-      this._private.available.refresh();
+
+      this.variableEngine.chain.refreshAllChange();
 
       this.toDispose.push(this._private);
     }