@fairfox/polly 0.13.2 → 0.14.0

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.
@@ -92,13 +92,24 @@ export declare class HandlerExtractor {
92
92
  */
93
93
  private extractSimpleOrElementAccessAssignment;
94
94
  /**
95
- * Extract property access assignment (state.field = value)
95
+ * Extract property access assignment (state.field = value or someState.value.field = value)
96
96
  */
97
97
  private extractPropertyAccessAssignment;
98
+ /**
99
+ * Extract assignments from object literal properties
100
+ * Used for: someState.value = { field1: value1, field2: value2 }
101
+ */
102
+ private extractObjectLiteralAssignments;
98
103
  /**
99
104
  * Extract element access assignment (state.items[index] = value)
100
105
  */
101
106
  private extractElementAccessAssignment;
107
+ /**
108
+ * Check if field path is a state mutation pattern and extract field name
109
+ * Supports: state.field, someState.value.field
110
+ * Returns: field name or null if not a state pattern
111
+ */
112
+ private extractFieldFromStatePath;
102
113
  /**
103
114
  * Extract compound assignments (+=, -=, *=, /=, %=)
104
115
  */
@@ -5747,6 +5747,39 @@ class HandlerExtractor {
5747
5747
  if (value !== undefined) {
5748
5748
  assignments.push({ field, value });
5749
5749
  }
5750
+ return;
5751
+ }
5752
+ const valueMatch = fieldPath.match(/\.value\.(.+)$/);
5753
+ if (valueMatch && valueMatch[1]) {
5754
+ const field = valueMatch[1];
5755
+ const value = this.extractValue(right);
5756
+ if (value !== undefined) {
5757
+ assignments.push({ field, value });
5758
+ }
5759
+ return;
5760
+ }
5761
+ if (fieldPath.endsWith(".value") && Node4.isObjectLiteralExpression(right)) {
5762
+ this.extractObjectLiteralAssignments(right, assignments);
5763
+ }
5764
+ }
5765
+ extractObjectLiteralAssignments(objectLiteral, assignments) {
5766
+ if (!Node4.isObjectLiteralExpression(objectLiteral))
5767
+ return;
5768
+ for (const prop of objectLiteral.getProperties()) {
5769
+ if (Node4.isPropertyAssignment(prop)) {
5770
+ const name = prop.getName();
5771
+ const initializer = prop.getInitializer();
5772
+ if (!name || !initializer)
5773
+ continue;
5774
+ const value = this.extractValue(initializer);
5775
+ if (value !== undefined) {
5776
+ assignments.push({ field: name, value });
5777
+ }
5778
+ }
5779
+ if (Node4.isShorthandPropertyAssignment(prop)) {
5780
+ const name = prop.getName();
5781
+ assignments.push({ field: name, value: "@" });
5782
+ }
5750
5783
  }
5751
5784
  }
5752
5785
  extractElementAccessAssignment(left, right, assignments) {
@@ -5756,9 +5789,9 @@ class HandlerExtractor {
5756
5789
  if (!Node4.isPropertyAccessExpression(expr))
5757
5790
  return;
5758
5791
  const fieldPath = this.getPropertyPath(expr);
5759
- if (!fieldPath.startsWith("state."))
5792
+ const field = this.extractFieldFromStatePath(fieldPath);
5793
+ if (!field)
5760
5794
  return;
5761
- const field = fieldPath.substring(6);
5762
5795
  const indexExpr = left.getArgumentExpression();
5763
5796
  const index = indexExpr ? indexExpr.getText() : "0";
5764
5797
  const value = this.extractValue(right);
@@ -5770,6 +5803,16 @@ class HandlerExtractor {
5770
5803
  });
5771
5804
  }
5772
5805
  }
5806
+ extractFieldFromStatePath(fieldPath) {
5807
+ if (fieldPath.startsWith("state.")) {
5808
+ return fieldPath.substring(6);
5809
+ }
5810
+ const valueMatch = fieldPath.match(/\.value\.(.+)$/);
5811
+ if (valueMatch && valueMatch[1]) {
5812
+ return valueMatch[1];
5813
+ }
5814
+ return null;
5815
+ }
5773
5816
  extractCompoundAssignment(node, assignments) {
5774
5817
  if (!Node4.isBinaryExpression(node))
5775
5818
  return;
@@ -5778,8 +5821,8 @@ class HandlerExtractor {
5778
5821
  const right = node.getRight();
5779
5822
  if (Node4.isPropertyAccessExpression(left)) {
5780
5823
  const fieldPath = this.getPropertyPath(left);
5781
- if (fieldPath.startsWith("state.")) {
5782
- const field = fieldPath.substring(6);
5824
+ const field = this.extractFieldFromStatePath(fieldPath);
5825
+ if (field) {
5783
5826
  const rightValue = right.getText();
5784
5827
  const tlaOp = operator.slice(0, -1);
5785
5828
  assignments.push({
@@ -5813,8 +5856,8 @@ class HandlerExtractor {
5813
5856
  if (!Node4.isPropertyAccessExpression(operand))
5814
5857
  return;
5815
5858
  const fieldPath = this.getPropertyPath(operand);
5816
- if (fieldPath.startsWith("state.")) {
5817
- const field = fieldPath.substring(6);
5859
+ const field = this.extractFieldFromStatePath(fieldPath);
5860
+ if (field) {
5818
5861
  const value = operatorText === "++" ? "@ + 1" : "@ - 1";
5819
5862
  assignments.push({ field, value });
5820
5863
  }
@@ -5829,8 +5872,8 @@ class HandlerExtractor {
5829
5872
  const object = expr.getExpression();
5830
5873
  if (Node4.isPropertyAccessExpression(object)) {
5831
5874
  const fieldPath = this.getPropertyPath(object);
5832
- if (fieldPath.startsWith("state.")) {
5833
- const field = fieldPath.substring(6);
5875
+ const field = this.extractFieldFromStatePath(fieldPath);
5876
+ if (field) {
5834
5877
  const args = node.getArguments().map((arg) => arg.getText());
5835
5878
  const tlaValue = this.translateArrayMethod(methodName, args, fieldPath);
5836
5879
  if (tlaValue) {
@@ -6470,8 +6513,8 @@ class HandlerExtractor {
6470
6513
  if (!Node4.isPropertyAccessExpression(left) && !Node4.isElementAccessExpression(left))
6471
6514
  return;
6472
6515
  const fieldPath = Node4.isPropertyAccessExpression(left) ? this.getPropertyPath(left) : this.getPropertyPath(left.getExpression());
6473
- if (fieldPath.startsWith("state.")) {
6474
- const field = fieldPath.substring(6);
6516
+ const field = this.extractFieldFromStatePath(fieldPath);
6517
+ if (field) {
6475
6518
  const line = node.getStartLineNumber();
6476
6519
  const afterAwait = node.getStart() > firstAwaitPos;
6477
6520
  mutations.push({ field, line, afterAwait });
@@ -6488,10 +6531,8 @@ class HandlerExtractor {
6488
6531
  if (!Node4.isPropertyAccessExpression(object))
6489
6532
  return;
6490
6533
  const fieldPath = this.getPropertyPath(object);
6491
- if (!fieldPath.startsWith("state."))
6492
- return;
6493
- if (["push", "pop", "shift", "unshift", "splice"].includes(methodName)) {
6494
- const field = fieldPath.substring(6);
6534
+ const field = this.extractFieldFromStatePath(fieldPath);
6535
+ if (field && ["push", "pop", "shift", "unshift", "splice"].includes(methodName)) {
6495
6536
  const line = node.getStartLineNumber();
6496
6537
  const afterAwait = node.getStart() > firstAwaitPos;
6497
6538
  mutations.push({ field, line, afterAwait });
@@ -9806,4 +9847,4 @@ Goodbye!`);
9806
9847
  }
9807
9848
  main();
9808
9849
 
9809
- //# debugId=53EFCFE442D6558B64756E2164756E21
9850
+ //# debugId=20A98BE870D3CEDD64756E2164756E21